init depot renew

This commit is contained in:
2026-09-22 11:58:57 +02:00
commit e9fa6a7309
205 changed files with 39721 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
from pycen import con_bdcen, update_to_sql
import pandas as pd
rq_prestation = "SELECT id, val_mat FROM ref_travaux.cr_valorisation_matiere"
cur = con_bdcen
cur = cur.execute(rq_prestation)
res_prestation = cur.fetchall()
dict_p = dict(res_prestation)
tab = 'cr_point_saisie_travaux'
sch = 'travaux'
c = 'val_mat'
# df = pd.read_sql_table(tab,con_bdcen,sch)
df = pd.read_sql_table(tab,con_bdcen,sch,columns=['gid',c])
df[c] = df[c].str.strip()
df[c] = df[c].replace({
'réalisé':'Réalisé',
'prévisionnel':'Prévisionnel'
})
df[c] = df[c].replace('',None)
df[c] = df[c].replace([*dict_p.values()],[*dict_p.keys()])
df[c] = df[c].astype(str)
df[c] = df[c].replace('None',None)
print(df[c].unique())
df.loc[df.prestation=='barre de coupe','prestation'] = '3'
sql = 'ALTER TABLE %s.%s DISABLE TRIGGER ALL'%(sch,tab)
with con_bdcen.begin() as cnx:
cnx.execute(sql)
update_to_sql(df,con_bdcen,tab,sch,'gid')
sql = 'ALTER TABLE %s.%s ENABLE TRIGGER ALL'%(sch,tab)
with con_bdcen.begin() as cnx:
cnx.execute(sql)
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
from pycen import con_bdcen as con
drop_line = "DROP VIEW IF EXISTS travaux.v_line_saisie_travaux;"
v_line_saisie_travaux = """
CREATE OR REPLACE VIEW travaux.v_line_saisie_travaux
AS SELECT a.gid AS serial,
a.geom,
a.id_site,
a.annee_trav,
b.legende AS id_gestion,
c.lib_presta,
a.etat_trav,
a.nom_presta,
a.date_debut,
a.duree_trav,
a.nb_etp,
a.nb_balle,
e.val_mat,
a.legende,
a.rmq,
d.val_mat AS prestation,
a.long_m,
a.crea_date,
a.date_update
FROM travaux.cr_line_saisie_travaux a
LEFT JOIN ref_travaux.cr_type_gestion b ON a.id_gestion = b.id_gestion::integer
LEFT JOIN ref_travaux.cr_type_prestataire c ON a.id_presta = c.id_presta::integer
LEFT JOIN ref_travaux.cr_type_prestation d ON a.prestation = d.id
LEFT JOIN ref_travaux.cr_valorisation_matiere e ON a.prestation = e.id
ORDER BY a.date_debut DESC;
"""
grant = """
ALTER TABLE travaux.v_line_saisie_travaux OWNER TO cen_admin;
GRANT ALL ON TABLE travaux.v_line_saisie_travaux TO cen_admin;
GRANT ALL ON TABLE travaux.v_line_saisie_travaux TO grp_admin;
GRANT SELECT ON TABLE travaux.v_line_saisie_travaux TO grp_consult;
GRANT SELECT, UPDATE, TRUNCATE, INSERT, DELETE ON TABLE travaux.v_line_saisie_travaux TO grp_travaux;
"""
with con.begin() as cnx:
cnx.execute(drop_line)
cnx.execute(v_line_saisie_travaux)
cnx.execute(grant)
drop_point = "DROP VIEW IF EXISTS travaux.v_point_saisie_travaux;"
v_point_saisie_travaux = """
"""
drop_poly = "DROP VIEW IF EXISTS travaux.v_poly_saisie_travaux;"
v_poly_saisie_travaux = """
"""