Merge branch 'main' of framagit.org:cen-colas/pycen into main
This commit is contained in:
Binary file not shown.
Binary file not shown.
+13
-9
@@ -13,8 +13,9 @@ from reportlab.lib.units import mm, inch
|
||||
|
||||
|
||||
# Ajout d'un style justifié
|
||||
styles = getSampleStyleSheet()
|
||||
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
|
||||
styles = getSampleStyleSheet()['Normal']
|
||||
styles.wordWrap = 'LTR'
|
||||
# styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
|
||||
|
||||
# page size
|
||||
page_size = A4
|
||||
@@ -51,10 +52,13 @@ class Rapport(object):
|
||||
self.story.append(im)
|
||||
self.spacer()
|
||||
|
||||
def paragraph(self, text, fontsize=12, style="Normal"):
|
||||
ptext = u'<font size={0:d}>{1:s}</font>'.format(fontsize, text)
|
||||
def paragraph(self, text, style="Normal",
|
||||
# fontsize=12,color="black"
|
||||
):
|
||||
# ptext = u'<font size={0:d} color={1:s}>{2:s}</font>'.format(fontsize, color, text)
|
||||
ptext = text
|
||||
self.story.append(Paragraph(ptext, styles[style]))
|
||||
self.spacer()
|
||||
# self.spacer()
|
||||
|
||||
def table(self, data):
|
||||
TableStyle()
|
||||
@@ -69,7 +73,7 @@ class Rapport(object):
|
||||
lista = [df.columns[:, ].values.astype(str).tolist()] + df.values.tolist()
|
||||
ts = [('LINEABOVE', (0, 0), (-1, 0), 1, colors.purple),
|
||||
('LINEBELOW', (0, 0), (-1, 0), 1, colors.purple),
|
||||
('FONT', (0, 0), (-1, 0), 'Times-Bold'),
|
||||
('FONT', (0, 0), (-1, 0), 'Times'),
|
||||
]
|
||||
self.story.append(Table(lista, style=ts))
|
||||
|
||||
@@ -87,15 +91,15 @@ class Rapport(object):
|
||||
|
||||
def myFirstPage(self, canvas, doc):
|
||||
canvas.saveState()
|
||||
canvas.setFont('Times-Bold', 22)
|
||||
canvas.setFont('Times', 22)
|
||||
canvas.drawCentredString(page_with / 2.0, page_height - 108, self.titre)
|
||||
canvas.setFont('Times-Roman', 9)
|
||||
canvas.setFont('Times', 9)
|
||||
canvas.drawString(0.5 * inch, 0.5 * inch, "%s" % self.pied_de_page)
|
||||
canvas.restoreState()
|
||||
|
||||
def myLaterPages(self, canvas, doc):
|
||||
canvas.saveState()
|
||||
canvas.setFont('Times-Roman', 9)
|
||||
canvas.setFont('Times', 9)
|
||||
canvas.drawString(0.5 * inch, 0.5 * inch, "%s" % self.pied_de_page)
|
||||
canvas.drawString(4 * inch, 0.5 * inch, "Page %d " % doc.page)
|
||||
canvas.restoreState()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -7,7 +7,7 @@
|
||||
#Version : 1.0
|
||||
|
||||
from ..tools import _get_table
|
||||
from ..pers.pers import _merge_author,_merge_relation
|
||||
from ..pers.pers import _merge_author2,_merge_relation
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ def _get_typ_site(ids=None, nom=None):
|
||||
df = _get_table(con, schema, table, ids=ids, nom=nom)
|
||||
return df
|
||||
|
||||
def _get_lots(ids=None, nom=None):
|
||||
table = 'lots'
|
||||
df = _get_table(con, schema, table, ids=ids, nom=nom)
|
||||
return df
|
||||
|
||||
|
||||
def get_sitesInfos(ids=None, nom=None, columns=None, with_nameOrga=False, details=False,
|
||||
params_col={}, milieu=None, statut='actif'):
|
||||
@@ -49,6 +54,7 @@ def get_sitesInfos(ids=None, nom=None, columns=None, with_nameOrga=False, detail
|
||||
typ_milieux = _get_typ_milieux()
|
||||
typo_sdage = _get_typo_sdage()
|
||||
typ_site = _get_typ_site()
|
||||
lots = _get_lots()
|
||||
|
||||
if milieu:
|
||||
m = _get_typ_milieux(nom=milieu)
|
||||
@@ -61,7 +67,7 @@ def get_sitesInfos(ids=None, nom=None, columns=None, with_nameOrga=False, detail
|
||||
if 'id_auteur' in df.columns:
|
||||
df.drop(columns='id_auteur', inplace=True)
|
||||
df = _merge_relation(df=df,table='r_sites_auteur',schema=schema, left_id='id',right_id='id_site')
|
||||
df = _merge_author(df=df, col_aut='id_auteur', orga=with_nameOrga)
|
||||
df = _merge_author2(df=df, col_aut='id_auteur')
|
||||
# merge type_site
|
||||
if 'id_type_site' in df.columns:
|
||||
df = merge(df, typ_site, how='left', left_on='id_type_site', right_on='id', suffixes=('','_y') ) \
|
||||
@@ -120,7 +126,7 @@ def get_sitesGeom(id_site=None, nom_site=None, columns=None, last_update=False,
|
||||
if 'id_auteur' in df.columns:
|
||||
df.drop(columns='id_auteur', inplace=True)
|
||||
df = _merge_relation(df=df,table='r_geomsites_auteur',schema=schema, left_id='id',right_id='id_geom_site')
|
||||
df = _merge_author(df=df, col_aut='id_auteur', orga=with_nameOrga)
|
||||
df = _merge_author2(df=df, col_aut='id_auteur')
|
||||
|
||||
if 'auteur' in df.columns:
|
||||
df.rename(columns={'auteur': 'auteur_geom'}, inplace=True)
|
||||
|
||||
+17
-4
@@ -6,7 +6,6 @@
|
||||
#Auteur : Colas Geier
|
||||
#Version : 1.0
|
||||
|
||||
from numpy.core.numeric import True_
|
||||
from pandas import Series, Index, read_sql, merge
|
||||
|
||||
|
||||
@@ -131,6 +130,7 @@ def _set_geom(df, hex=True):
|
||||
return df
|
||||
|
||||
|
||||
|
||||
def _get_param(schema, param_table, type_table=None, type_court=True):
|
||||
from .params import con
|
||||
|
||||
@@ -253,10 +253,23 @@ def _get_relation_autor2(df, relation_tab, schema, id_df, id_relation, id_rela_a
|
||||
right_id = id_relation)
|
||||
|
||||
aut = get_auteur2()[['nom_prenom']]
|
||||
df[id_rela_auth] = df[id_rela_auth].astype(float)
|
||||
df = df.merge(aut,how='left', left_on=id_rela_auth, right_index=True)
|
||||
aut_df = df[id_rela_auth].str.split(' & ',expand = True)
|
||||
aut_df.replace([*aut.index.astype(str)],[*aut.nom_prenom], inplace=True)
|
||||
lst_col = aut_df.columns.drop(0)
|
||||
aut_df[id_rela_auth] = aut_df[0]
|
||||
for col in lst_col:
|
||||
aut_df.loc[~aut_df[col].isna(),id_rela_auth] = aut_df.loc[~aut_df[col].isna(),id_rela_auth] + \
|
||||
' & ' + aut_df.loc[~aut_df[col].isna(),col]
|
||||
aut_df.drop(columns=[0,*lst_col], inplace=True)
|
||||
aut_df.columns = [id_rela_auth + '_tmp']
|
||||
df = df.merge(aut_df,how='left', left_index=True, right_index=True)
|
||||
df[id_rela_auth] = df[id_rela_auth+'_tmp']
|
||||
del df[id_rela_auth+'_tmp']
|
||||
|
||||
# df[id_rela_auth] = df[id_rela_auth].astype(float)
|
||||
# df = df.merge(aut,how='left', left_on=id_rela_auth, right_index=True)
|
||||
# df = _merge_author(df=df, col_aut=id_rela_auth, on_index=True)
|
||||
df.rename(columns={'auteur': 'auteur'+suffixe}, inplace=True)
|
||||
df.rename(columns={id_rela_auth: 'auteur'+suffixe}, inplace=True)
|
||||
return df
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+26
-11
@@ -14,9 +14,9 @@ import pandas as pd
|
||||
# from sqlalchemy.sql.expression import column
|
||||
# from sqlalchemy import create_engine
|
||||
from geoalchemy2 import Geometry
|
||||
from .pers.pers import _get_table
|
||||
# from .pers.pers import _get_table
|
||||
from .sites.sites import _get_typ_milieux
|
||||
from .tools import _get_relation_autor
|
||||
from .tools import _get_relation_autor2, _get_table
|
||||
|
||||
|
||||
#####################################
|
||||
@@ -277,7 +277,7 @@ class zh():
|
||||
dic = self._get_param(type_table='type_param_delim_fct', param_table='param_delim_fct', type_court=nom_type_court)
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsitedelim_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsitedelim_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_sitedelim', id_rela_auth='id_auteur' )
|
||||
|
||||
df = pd.merge(df,dic, how='left', left_on='id_crit_delim', right_on='id', suffixes=(None,'_y')) \
|
||||
@@ -304,7 +304,7 @@ class zh():
|
||||
dic = self._get_param(type_table='type_param_fct', param_table='param_fct_eco_socio_patri', type_court=nom_type_court)
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsitefct_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsitefct_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_sitefct', id_rela_auth='id_auteur' )
|
||||
|
||||
df = pd.merge(df,dic, how='left', left_on='id_fct', right_on='id', suffixes=(None,'_y')) \
|
||||
@@ -325,7 +325,7 @@ class zh():
|
||||
dic = self._get_param(param_table='param_type_connect')
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsiteconnect_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsiteconnect_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_siteconnect', id_rela_auth='id_auteur' )
|
||||
df = pd.merge(df,dic, how='left', left_on='id_param_connect', right_on='id', suffixes=(None,'_y')) \
|
||||
.drop(columns=['id_y','id_param_connect']) \
|
||||
@@ -345,9 +345,11 @@ class zh():
|
||||
d2 = dic[dic.type == 'Submersion fréquente']
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsitesub_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsitesub_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_sitesub', id_rela_auth='id_auteur' )
|
||||
|
||||
df.id_etendsub = df.id_etendsub.astype(float)
|
||||
|
||||
df = pd.merge(df,d1, how='left', left_on='id_etendsub', right_on='id', suffixes=(None,'_y')) \
|
||||
.drop(columns=['id_y','id_etendsub', 'type']) \
|
||||
.rename(columns={'description':'desc_param_etend', 'nom':'Submersion étendue'})
|
||||
@@ -375,7 +377,7 @@ class zh():
|
||||
dic3 = self._get_param(param_table='param_impact')
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsiteusage_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsiteusage_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_siteusage', id_rela_auth='id_auteur' )
|
||||
|
||||
df = pd.merge(df,dic1, how='left', left_on='id_activ_hum', right_on='id', suffixes=(None,'_y')) \
|
||||
@@ -422,7 +424,7 @@ class zh():
|
||||
dic2 = self._get_param(param_table='param_permanence')
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsitehydro_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsitehydro_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_sitehydro', id_rela_auth='id_auteur' )
|
||||
|
||||
# dic3 = self._get_r_toponymie(ids=df.rmq_toponymie.unique().tolist())
|
||||
@@ -454,7 +456,7 @@ class zh():
|
||||
params_col={'id_type_milieu':self.id_milieux.astype(str)}, statut=statut)
|
||||
|
||||
if not df.empty:
|
||||
df = _get_relation_autor(df, relation_tab='r_rsitehab_auteur', schema=self.schema,
|
||||
df = _get_relation_autor2(df, relation_tab='r_rsitehab_auteur', schema=self.schema,
|
||||
id_df='id', id_relation='id_sitehab', id_rela_auth='id_auteur' )
|
||||
|
||||
ids = df[~df.id_cb.isna()].id_cb.unique().tolist()
|
||||
@@ -638,7 +640,7 @@ class ref_hydro:
|
||||
#####################################
|
||||
### Update ###
|
||||
#####################################
|
||||
def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
||||
def update_to_sql(df, con, table_name, schema_name, key_name,geom_col='geom'):
|
||||
from geopandas import GeoDataFrame
|
||||
a = []
|
||||
b = []
|
||||
@@ -681,4 +683,17 @@ def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
||||
cnx.execute(drop_stmt)
|
||||
return print('END update')
|
||||
|
||||
|
||||
|
||||
# [SQL: INSERT INTO zones_humides.r_site_reghydro (id, id_geom_site, id_reg_hydro, id_permanence, rmq_toponymie, in_out)
|
||||
# VALUES (%(id)s, %(id_geom_site)s, %(id_reg_hydro)s, %(id_permanence)s, %(rmq_toponymie)s, %(in_out)s)]
|
||||
# [parameters: ({'id': 0, 'id_geom_site': 5, 'id_reg_hydro': '0', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': True},
|
||||
# {'id': 1, 'id_geom_site': 5, 'id_reg_hydro': '1', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': False},
|
||||
# {'id': 2, 'id_geom_site': 6, 'id_reg_hydro': '0', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': True},
|
||||
# {'id': 3, 'id_geom_site': 6, 'id_reg_hydro': '1', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': False},
|
||||
# {'id': 4, 'id_geom_site': 7, 'id_reg_hydro': '2', 'id_permanence': '2', 'rmq_toponymie': 'plusieurs petites sources dans versant', 'in_out': True},
|
||||
# {'id': 5, 'id_geom_site': 7, 'id_reg_hydro': '1', 'id_permanence': '2', 'rmq_toponymie': 'longe la route D209a', 'in_out': False},
|
||||
# {'id': 6, 'id_geom_site': 8, 'id_reg_hydro': '0', 'id_permanence': '2', 'rmq_toponymie': '', 'in_out': True},
|
||||
# {'id': 7, 'id_geom_site': 8, 'id_reg_hydro': '3', 'id_permanence': None, 'rmq_toponymie': '', 'in_out': False}
|
||||
# ... displaying 10 of 5779 total bound parameter sets ...
|
||||
# {'id': 5777, 'id_geom_site': 1951, 'id_reg_hydro': '0', 'id_permanence': None, 'rmq_toponymie': '', 'in_out': True},
|
||||
# {'id': 5778, 'id_geom_site': 1951, 'id_reg_hydro': '3', 'id_permanence': None, 'rmq_toponymie': '', 'in_out': False})]
|
||||
|
||||
Reference in New Issue
Block a user