UPDATE pycen pour script rapport
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é
|
# Ajout d'un style justifié
|
||||||
styles = getSampleStyleSheet()
|
styles = getSampleStyleSheet()['Normal']
|
||||||
styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
|
styles.wordWrap = 'LTR'
|
||||||
|
# styles.add(ParagraphStyle(name='Justify', alignment=TA_JUSTIFY))
|
||||||
|
|
||||||
# page size
|
# page size
|
||||||
page_size = A4
|
page_size = A4
|
||||||
@@ -51,10 +52,13 @@ class Rapport(object):
|
|||||||
self.story.append(im)
|
self.story.append(im)
|
||||||
self.spacer()
|
self.spacer()
|
||||||
|
|
||||||
def paragraph(self, text, fontsize=12, style="Normal"):
|
def paragraph(self, text, style="Normal",
|
||||||
ptext = u'<font size={0:d}>{1:s}</font>'.format(fontsize, text)
|
# 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.story.append(Paragraph(ptext, styles[style]))
|
||||||
self.spacer()
|
# self.spacer()
|
||||||
|
|
||||||
def table(self, data):
|
def table(self, data):
|
||||||
TableStyle()
|
TableStyle()
|
||||||
@@ -69,7 +73,7 @@ class Rapport(object):
|
|||||||
lista = [df.columns[:, ].values.astype(str).tolist()] + df.values.tolist()
|
lista = [df.columns[:, ].values.astype(str).tolist()] + df.values.tolist()
|
||||||
ts = [('LINEABOVE', (0, 0), (-1, 0), 1, colors.purple),
|
ts = [('LINEABOVE', (0, 0), (-1, 0), 1, colors.purple),
|
||||||
('LINEBELOW', (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))
|
self.story.append(Table(lista, style=ts))
|
||||||
|
|
||||||
@@ -87,15 +91,15 @@ class Rapport(object):
|
|||||||
|
|
||||||
def myFirstPage(self, canvas, doc):
|
def myFirstPage(self, canvas, doc):
|
||||||
canvas.saveState()
|
canvas.saveState()
|
||||||
canvas.setFont('Times-Bold', 22)
|
canvas.setFont('Times', 22)
|
||||||
canvas.drawCentredString(page_with / 2.0, page_height - 108, self.titre)
|
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.drawString(0.5 * inch, 0.5 * inch, "%s" % self.pied_de_page)
|
||||||
canvas.restoreState()
|
canvas.restoreState()
|
||||||
|
|
||||||
def myLaterPages(self, canvas, doc):
|
def myLaterPages(self, canvas, doc):
|
||||||
canvas.saveState()
|
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(0.5 * inch, 0.5 * inch, "%s" % self.pied_de_page)
|
||||||
canvas.drawString(4 * inch, 0.5 * inch, "Page %d " % doc.page)
|
canvas.drawString(4 * inch, 0.5 * inch, "Page %d " % doc.page)
|
||||||
canvas.restoreState()
|
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
|
#Version : 1.0
|
||||||
|
|
||||||
from ..tools import _get_table
|
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:
|
if 'id_auteur' in df.columns:
|
||||||
df.drop(columns='id_auteur', inplace=True)
|
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_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
|
# merge type_site
|
||||||
if 'id_type_site' in df.columns:
|
if 'id_type_site' in df.columns:
|
||||||
df = merge(df, typ_site, how='left', left_on='id_type_site', right_on='id', suffixes=('','_y') ) \
|
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:
|
if 'id_auteur' in df.columns:
|
||||||
df.drop(columns='id_auteur', inplace=True)
|
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_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:
|
if 'auteur' in df.columns:
|
||||||
df.rename(columns={'auteur': 'auteur_geom'}, inplace=True)
|
df.rename(columns={'auteur': 'auteur_geom'}, inplace=True)
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,6 @@
|
|||||||
#Auteur : Colas Geier
|
#Auteur : Colas Geier
|
||||||
#Version : 1.0
|
#Version : 1.0
|
||||||
|
|
||||||
from numpy.core.numeric import True_
|
|
||||||
from pandas import Series, Index, read_sql, merge
|
from pandas import Series, Index, read_sql, merge
|
||||||
|
|
||||||
|
|
||||||
@@ -131,6 +130,7 @@ def _set_geom(df, hex=True):
|
|||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _get_param(schema, param_table, type_table=None, type_court=True):
|
def _get_param(schema, param_table, type_table=None, type_court=True):
|
||||||
from .params import con
|
from .params import con
|
||||||
|
|
||||||
|
|||||||
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.
+24
-20
@@ -16,7 +16,7 @@ import pandas as pd
|
|||||||
from geoalchemy2 import Geometry
|
from geoalchemy2 import Geometry
|
||||||
from .pers.pers import _get_table
|
from .pers.pers import _get_table
|
||||||
from .sites.sites import _get_typ_milieux
|
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)
|
dic = self._get_param(type_table='type_param_delim_fct', param_table='param_delim_fct', type_court=nom_type_court)
|
||||||
|
|
||||||
if not df.empty:
|
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' )
|
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')) \
|
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)
|
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:
|
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' )
|
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')) \
|
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')
|
dic = self._get_param(param_table='param_type_connect')
|
||||||
|
|
||||||
if not df.empty:
|
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' )
|
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')) \
|
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']) \
|
.drop(columns=['id_y','id_param_connect']) \
|
||||||
@@ -345,9 +345,11 @@ class zh():
|
|||||||
d2 = dic[dic.type == 'Submersion fréquente']
|
d2 = dic[dic.type == 'Submersion fréquente']
|
||||||
|
|
||||||
if not df.empty:
|
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' )
|
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')) \
|
df = pd.merge(df,d1, how='left', left_on='id_etendsub', right_on='id', suffixes=(None,'_y')) \
|
||||||
.drop(columns=['id_y','id_etendsub', 'type']) \
|
.drop(columns=['id_y','id_etendsub', 'type']) \
|
||||||
.rename(columns={'description':'desc_param_etend', 'nom':'Submersion étendue'})
|
.rename(columns={'description':'desc_param_etend', 'nom':'Submersion étendue'})
|
||||||
@@ -375,7 +377,7 @@ class zh():
|
|||||||
dic3 = self._get_param(param_table='param_impact')
|
dic3 = self._get_param(param_table='param_impact')
|
||||||
|
|
||||||
if not df.empty:
|
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' )
|
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')) \
|
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')
|
dic2 = self._get_param(param_table='param_permanence')
|
||||||
|
|
||||||
if not df.empty:
|
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' )
|
id_df='id', id_relation='id_sitehydro', id_rela_auth='id_auteur' )
|
||||||
|
|
||||||
# dic3 = self._get_r_toponymie(ids=df.rmq_toponymie.unique().tolist())
|
# 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)
|
params_col={'id_type_milieu':self.id_milieux.astype(str)}, statut=statut)
|
||||||
|
|
||||||
if not df.empty:
|
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' )
|
id_df='id', id_relation='id_sitehab', id_rela_auth='id_auteur' )
|
||||||
|
|
||||||
ids = df[~df.id_cb.isna()].id_cb.unique().tolist()
|
ids = df[~df.id_cb.isna()].id_cb.unique().tolist()
|
||||||
@@ -638,8 +640,7 @@ class ref_hydro:
|
|||||||
#####################################
|
#####################################
|
||||||
### Update ###
|
### 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):
|
||||||
from geopandas import GeoDataFrame
|
|
||||||
a = []
|
a = []
|
||||||
b = []
|
b = []
|
||||||
table = table_name
|
table = table_name
|
||||||
@@ -651,16 +652,6 @@ def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
|||||||
b.append("t.{col}=f.{col}".format(col=col))
|
b.append("t.{col}=f.{col}".format(col=col))
|
||||||
else:
|
else:
|
||||||
a.append("{col}=t.{col}".format(col=col))
|
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(
|
df.to_sql(
|
||||||
name = 'temp_table',
|
name = 'temp_table',
|
||||||
con = con,
|
con = con,
|
||||||
@@ -682,3 +673,16 @@ def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
|||||||
return print('END update')
|
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