UPDATE pycen pour script rapport
This commit is contained in:
parent
9716e61ea4
commit
0416810bf2
Binary file not shown.
Binary file not shown.
@ -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
|
||||
|
||||
|
||||
|
||||
@ -61,7 +61,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 +120,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)
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
BIN
pycen/vrac/__pycache__/Modif_caract_connect.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_connect.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pycen/vrac/__pycache__/Modif_caract_delim.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_delim.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pycen/vrac/__pycache__/Modif_caract_fct.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_fct.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pycen/vrac/__pycache__/Modif_caract_hab.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_hab.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pycen/vrac/__pycache__/Modif_caract_reghydro.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_reghydro.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pycen/vrac/__pycache__/Modif_caract_sub.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_sub.cpython-38.pyc
Normal file
Binary file not shown.
BIN
pycen/vrac/__pycache__/Modif_caract_usageprocess.cpython-38.pyc
Normal file
BIN
pycen/vrac/__pycache__/Modif_caract_usageprocess.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
62
pycen/zh.py
62
pycen/zh.py
@ -16,7 +16,7 @@ import pandas as pd
|
||||
from geoalchemy2 import Geometry
|
||||
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
|
||||
|
||||
|
||||
#####################################
|
||||
@ -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,8 +640,7 @@ class ref_hydro:
|
||||
#####################################
|
||||
### Update ###
|
||||
#####################################
|
||||
def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
||||
from geopandas import GeoDataFrame
|
||||
def update_to_sql(df, con, table_name, schema_name, key_name):
|
||||
a = []
|
||||
b = []
|
||||
table = table_name
|
||||
@ -651,24 +652,14 @@ def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
||||
b.append("t.{col}=f.{col}".format(col=col))
|
||||
else:
|
||||
a.append("{col}=t.{col}".format(col=col))
|
||||
if isinstance(df,GeoDataFrame):
|
||||
df.to_postgis(
|
||||
name = 'temp_table',
|
||||
con = con,
|
||||
schema = schema,
|
||||
if_exists = 'replace',
|
||||
index = False,
|
||||
geom_col=geom_col,
|
||||
)
|
||||
else:
|
||||
df.to_sql(
|
||||
name = 'temp_table',
|
||||
con = con,
|
||||
schema = schema,
|
||||
if_exists = 'replace',
|
||||
index = False,
|
||||
method = 'multi'
|
||||
)
|
||||
df.to_sql(
|
||||
name = 'temp_table',
|
||||
con = con,
|
||||
schema = schema,
|
||||
if_exists = 'replace',
|
||||
index = False,
|
||||
method = 'multi'
|
||||
)
|
||||
update_stmt_1 = "UPDATE {sch}.{final_table} f".format(sch=schema,final_table=table)
|
||||
update_stmt_2 = " FROM {sch}.temp_table t".format(sch=schema)
|
||||
update_stmt_6 = " WHERE %s"%' AND '.join(b)
|
||||
@ -681,4 +672,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})]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user