Bläddra i källkod

Modeles et requetes de mise à jour terminées (non testées)

olivier.massot 7 år sedan
förälder
incheckning
69d91b2e3f
3 ändrade filer med 172 tillägg och 113 borttagningar
  1. 38 3
      core/pde.py
  2. 4 0
      logging.yaml
  3. 130 110
      wincan2ctrl.py

+ 38 - 3
core/pde.py

@@ -65,7 +65,7 @@ class ControlesDb(ParcDb):
     _path = CONTROLES_DB_PATH
 
 class WincanDb(ParcDb):
-    _path = COMMUN_DB_PATH
+    _path = WINCAN_DB_PATH
 
 class CommunDb(ParcDb):
     _path = FACTURES_DB_PATH
@@ -274,8 +274,43 @@ class Ligne(Model):
         self.strPUAff = "", str
         self.strQteAff = "", str
 
-
-
+class InspectionTronconWincan(Model):
+    """ Inspection vidéo d'un tronçon de réseau d'assainissement dans Wincan """
+    def __init__(self):
+        self.s_guid = "", str
+        self.si_guid = "", str
+        self.nom_chantier = "", str
+        self.lng_chantier_id = 0, int
+        self.byt_interv_id = 0, int
+        self.si_autonumber = 0, int
+        self.classement_troncons = "", str
+        self.nom_troncon = "", str
+        self.startnode_type = "", str
+        self.endnode_type = "", str
+        self.sens_ecoul = "", str
+        self.startnode_z = 0.0, float
+        self.endnode_z = 0.0, float
+        self.section_length = 0.0, float
+        self.section_purpose = "", str
+        self.section_use = "", str
+        self.section_type = "", str
+        self.materiau = "", str
+        self.annee_pose = 0, int
+        self.diametre = "", str
+        self.route = "", str
+        self.n_route = "", str
+        self.pipe_shape = "", str
+        self.pipe_length = 0.0, float
+        self.arbres = "", str
+        self.test_ecoulement = "", str
+        self.si_date = None, datetime
+        self.nb_ops = 0, int
+        self.nb_photos = 0, int
+        self.rate_1 = 0, int
+        self.rate_2 = 0, int
+        self.rate_3 = 0, int
+        self.rate_4 = 0, int
+        self.rate_5 = 0, int
 
 
 if __name__ == "__main__":

+ 4 - 0
logging.yaml

@@ -39,6 +39,10 @@ loggers:
         level: DEBUG
         handlers: [console, file, mail]
         propagate: no
+    wincan2ctrl:
+        level: DEBUG
+        handlers: [console, file, mail]
+        propagate: no
     ctrl2analytique:
         level: DEBUG
         handlers: [console, file, mail]

+ 130 - 110
wincan2ctrl.py

@@ -9,7 +9,7 @@ from path import Path
 
 from core import logconf
 from core.db import AccessSqlHelper
-from core.pde import ControlesDb, WincanDb, CommunDb
+from core.pde import ControlesDb, WincanDb, CommunDb, InspectionTronconWincan
 from core.sqlformatter import SqlFormatter
 
 
@@ -56,7 +56,10 @@ def get_lib(tbl_id, lib_id):
                                         FROM LISTE_LIBELLE_WINCAN
                                         WHERE TLB_ID='{}' AND LIB_ID={}""", tbl_id, lib_id)).LIB_LIB
 
-
+def get_materiau(wincan_id):
+    return controles_db.first(Sql.format("""SELECT strMateriauCourt
+                                            FROM tblMateriaux
+                                            WHERE strWincanId='{}'""", wincan_id)).strMateriauCourt
 
 
 
@@ -98,113 +101,130 @@ for nontraite in wincan_db.read(sql):
         wincan_db.execute(sql)
 
         # Met a jour la table tbl_so_rate de Controles
-        logger.info("Mise à jour de tblso_Rate_Analyse")
-
-
-
-        # 1. Extrait les données des essais
-#         sql = """SELECT SI_T.SI_Spare1, SI_T.SI_Spare2, SI_T.SI_MediaNumber1, S_T.S_SectionFlow, S_T.S_StartNode, S_T.S_StartNodeType,
-#                     S_T.S_StartNodeCoord_Z, S_T.S_EndNode, S_T.S_EndNodeType, S_T.S_EndNodeCoord_Z, S_T.S_Sectionlength, S_T.S_SectionPurpose,
-#                     S_T.S_SectionUse, S_T.S_SectionType, S_T.S_PipeMaterial, S_T.S_YearLayed, S_T.S_PipeDia, S_T.S_Situation, S_T.S_Spare1,
-#                     S_T.S_EndStreet, P_T.P_Name, P_T.P_Date, S_T.S_Location, S_T.S_StartStreet, S_T.S_Spare2, SI_T.SI_AutoNumber,
-#                     S_T.S_PipeShape, S_T.S_Pipelength, S_T.S_Spare3, SI_T.SI_ID, S_T.S_ID, SI_T.SI_InspName, S_T.S_SectionPurpose,
-#                     S_T.S_SectionUse, S_T.S_SectionType, SI_T.SI_Spare0 AS Test_ecoulement, SI_T.SI_Date, SI_T.SI_ReasonOfInspection,
-#                     S_T.S_SectionPurpose, SO_T.SO_ID, SO_T.SO_Rate, SO_T.SO_Photonumber1, SO_T.SO_Photonumber2
-#                 FROM ((P_T INNER JOIN S_T ON P_T.P_ID = S_T.S_Project_ID) INNER JOIN SI_T ON S_T.S_ID = SI_T.SI_Section_ID)
-#                     INNER JOIN SO_T ON SI_T.SI_ID = SO_T.SO_Inspecs_ID
-#                 WHERE SO_T.SO_Rate <= 6 or SO_T.SO_Rate Is Null
-#                 ORDER BY SI_T.SI_InspName, SI_T.SI_MediaNumber1
-#                 """
-
-#         sql = """
-
-
-
-
-        # 2. Enrichir / transformer les données
-
-        # * SI_Spare1                             => lngChantierId (convertir en num)
-        # * SI_Spare2                             => bytIntervId (convertir en num)
-        # * SI_MediaNumber1                       => [Classement troncons]
-        # * S_StartNode, S_EndNode, S_SectionFlow => Nom_troncon ("Start-End" si S_SectionFlow == 2, sinon "End-Start")
-        # * S_StartNodeType                       => S_StartNodeType (get_lib, tbl='S_StartNodeType'; trim)
-        # * S_SectionFlow                         => Sens_ecoul ('>>' si SectionFlow = '1', '<<' si SectionFlow=2, '' sinon)
-        # * S_StartNodeCoord_Z                    => S_StartNodeCoord_Z
-        # * S_EndNodeCoord_Z                      => S_EndNodeCoord_Z
-        # * S_Sectionlength
-        # * S_EndNodeType                         => S_EndNodeType (get_lib, tbl='S_EndNodeType'; trim)
-        # ** S_SectionPurpose                      => [Nature Reseau] (get_lib, tbl='S_SectionPurpose')
-        # ** S_SectionUse                          => [Fonction Reseau] (get_lib, tbl='S_SectionUse')
-        # ** S_SectionType                         => [Type de Réseau] (get_lib, tbl='S_SectionType')
-        # S_PipeMaterial                        => Materiau (get_lib, tbl='S_PipeMaterial')
-        # *                                    ET => MateriauCourt (strMateriauCourt FROM tblMateriaux WHERE strWincanId='{}') (c'est celui qui est utilisé)
-        # * S_YearLayed                           => ANNEE_POSE
-        # * S_PipeDia                             => Diametre (get_lib, tbl='S_PipeDia')
-        # * S_Situation                           => Route (get_lib, tbl='S_Situation')
-        # * S_Spare1                              => NRoute
-        # S_EndStreet                           => Rue
-        # P_Name                                => P_Name
-        # P_Date                                => P_Date
-        # S_Location                            => Loc (strTiersMnemo FROM tblTiers WHERE strCompteComptable='{}')
-        # S_StartStreet                         => MOu
-        # S_Spare2                              => N°CHIMERE
-        # SI_AutoNumber                         => SI_AutoNumber
-        # * S_PipeShape                           => S_PipeShape
-        # * S_Pipelength                          => S_Pipelength
-        # * S_Spare3                              => nb_Arbres (get_lib, tbl='S_Spare3')
-        # SI_ID
-        # S_ID
-        # ? SI_InspName
-        # * SI_Spare0                             => Test_ecoulement
-        # * SI_Date                               => SI_Date
-        # SI_ReasonOfInspection                 => raison_insp (get_lib, tbl='SI_ReasonOfInspection')
-        # * SO_Photonumber1, SO_Photonumber2      => nb_photos (VraiFaux([SO_Photonumber2] Est Pas Null;1;0)+VraiFaux([SO_Photonumber1] Est Pas Null;1;0))
-
-
-        # 3. Reorganisation
-
-
-        # Les données sont croisées de cette manière:
-        # Regroupement des lignes sur la plupart des champs
-        # Compte de SO_ID
-        # cpt_photos = somme de nb_photos
-        # Les résultats (SO_Rate) passent en colonnes, avec un decompte par valeur (comprise entre 1 et 5)
-
-
-
-
-        # 4. Insertion
-        sql = """INSERT INTO tblso_Rate_Analyse (
-                        lngChantierId, bytIntervId, SI_InspName, SI_AutoNumber, [Classement tronons], Nom_troncon, S_StartNodeType, Sens_ecoul, S_EndNodeType,
-                        S_PipeShape, MateriauCourt, SI_Date, nb_Arbres, ANNEE_POSE, Route, NRoute, Test_ecoulement, MaxDeS_StartNodeCoord_Z, MaxDeS_EndNodeCoord_Z,
-                        MaxDeS_Sectionlength, MaxDeS_Pipelength, MaxDeDiametre, cpt_Photos, [Total de SO_ID], 1, 2, 3, 4, 5
-                        )
-                SELECT  lngChantierId, bytIntervId, SI_InspName, SI_AutoNumber, [Classement tronons], Nom_troncon, S_StartNodeType,
-                        Sens_ecoul, S_EndNodeType, S_PipeShape, MateriauCourt, SI_Date, nb_Arbres, ANNEE_POSE, Route,
-                        NRoute, Test_ecoulement, MaxDeS_StartNodeCoord_Z, MaxDeS_EndNodeCoord_Z, MaxDeS_Sectionlength, MaxDeS_Pipelength,
-                        MaxDeDiametre, cpt_Photos, [Total de SO_ID], [1], [2], [3], [4], [5]
-                FROM r_so_rate_Analyse
-                WHERE lngChantierId= {} AND bytIntervId= {}
-                """.format(chantier, interv)
-
-        controles_db.execute(sql)
-
-
-        # Met à jour tblvideointervs.strResGlobal avec le resultat global
-        #  le resultat global vaut '-' si un de ces trois champs n'est pas nul: tbl_so_rate.1, tbl_so_rate.2, tbl_so_rate.3
-        logger.info("Mise à jour du resultat global dans tblvideointervs")
-        resGlobal = ''
-        "Update  tblvideointervs set strResGlobal='{}' WHERE lngChantierId= {} AND bytIntervId= {}".format(resGlobal, chantier, interv)
-
-        # Met à jour la table tblVideoBases pour marquer le chantier comme traité
-        logger.info("Mise à jour de tblVideoBases")
-        sql = "update tblVideoBases set blnWincan=-1,bytNbInterv={} where  lngChantierId={}".format(interv, chantier)
-
-        # Met à jour les données du réseau dans tblChantiers
-        logger.info("Mise à jour des données du réseau dans tblChantiers")
-        fctReseauId, natureReseauId, typeReseauId = 0, 0, 0
-        sql = "update tblChantiers set  bytFoncReseauId ={} , bytNatureReseauId={}, bytTypeReseauId={} where  lngChantierId={}".format(fctReseauId, natureReseauId, typeReseauId, chantier)
-
-        logger.info("Commit")
+        logger.info("Traitement des inspections de tronçons")
+
+        # Extrait les données des tronçons
+
+        sql = """SELECT SI_T.SI_ID, S_T.S_ID, SI_T.SI_InspName, SI_T.SI_Spare1, SI_T.SI_Spare2, SI_T.SI_AutoNumber, SI_T.SI_MediaNumber1, S_T.S_SectionFlow,
+                    S_T.S_StartNode, S_T.S_EndNode, S_T.S_StartNodeType, S_T.S_EndNodeType, S_T.S_StartNodeCoord_Z, S_T.S_EndNodeCoord_Z,
+                    S_T.S_Sectionlength, S_T.S_SectionPurpose, S_T.S_SectionUse, S_T.S_SectionType, S_T.S_PipeMaterial, S_T.S_YearLayed,
+                    S_T.S_PipeDia, S_T.S_Situation, S_T.S_Spare1, S_T.S_PipeShape, S_T.S_Pipelength, S_T.S_Spare3,
+                    SI_T.SI_Spare0 AS Test_ecoulement, SI_T.SI_Date
+                FROM S_T INNER JOIN SI_T ON S_T.S_ID = SI_T.SI_Section_ID
+                """
+
+        for data in wincan_db.read(sql):
+
+            logger.info("* Traitement de %s (S_ID: %s)", data.SI_InspName, data.S_ID)
+
+            inspection = InspectionTronconWincan()
+
+            inspection.s_guid = data.S_ID
+            inspection.si_guid = data.SI_ID
+            inspection.nom_chantier = data.SI_InspName
+            inspection.lng_chantier_id = data.SI_Spare1
+            inspection.byt_interv_id = data.SI_Spare2
+            inspection.si_autonumber = data.SI_AutoNumber
+            inspection.classement_troncons = data.SI_MediaNumber1
+            inspection.nom_troncon = ("{0}-{1}" if data.S_SectionFlow == 2 else "{1}-{0}").format(data.S_StartNode, data.S_EndNode)
+            inspection.startnode_type = get_lib(data.S_T.S_StartNodeType, "S_StartNodeType")
+            inspection.endnode_type = get_lib(data.S_T.S_StartNodeType, "S_EndNodeType")
+            inspection.sens_ecoul = ">>" if data.S_SectionFlow == '1' else ('<<' if data.S_SectionFlow == '2' else '')
+            inspection.startnode_z = data.S_StartNodeCoord_Z
+            inspection.endnode_z = data.S_EndNodeCoord_Z
+            inspection.section_length = data.S_Sectionlength
+            inspection.section_purpose = data.S_SectionPurpose
+            inspection.section_use = data.S_SectionUse
+            inspection.section_type = data.S_SectionType
+            inspection.materiau = get_materiau(data.S_PipeMaterial)
+            inspection.annee_pose = data.S_YearLayed
+            inspection.diametre = get_lib(data.S_PipeDia, "S_PipeDia")
+            inspection.route = get_lib(data.S_Situation, "S_Situation")
+            inspection.n_route = data.S_Spare1
+            inspection.pipe_shape = data.S_PipeShape
+            inspection.pipe_length = data.S_Pipelength
+            inspection.arbres = get_lib(data.S_Spare3, "S_Spare3")
+            inspection.test_ecoulement = data.SI_Spare0
+            inspection.si_date = data.SI_Date
+
+            sql = """ SELECT SO_T.SO_ID, SO_T.SO_Rate, SO_T.SO_Photonumber1, SO_T.SO_Photonumber2
+                        FROM SO_T
+                        WHERE SO_T.SO_Inspecs_ID='{}'
+                    """.format(data.SI_ID)
+
+            # Parcours les opérations réalisées au cours de l'inspection du tronçon
+            for opdata in wincan_db.read(sql):
+                inspection.nb_ops += 1
+
+                if opdata.SO_Rate == 1:
+                    inspection.rate_1 += 1
+                elif opdata.SO_Rate == 2:
+                    inspection.rate_2 += 1
+                elif opdata.SO_Rate == 3:
+                    inspection.rate_3 += 1
+                elif opdata.SO_Rate == 4:
+                    inspection.rate_4 += 1
+                elif opdata.SO_Rate == 5:
+                    inspection.rate_5 += 1
+                elif opdata.SO_Rate >= 6:
+                    logger.error("Attention: une valeur de [SO_Rate] supérieure à 5 a été enregistrée (SO_ID: %s)", opdata.SO_ID)
+
+                if opdata.SO_Photonumber1:
+                    inspection.cpt_photos += 1
+                if opdata.SO_Photonumber2:
+                    inspection.cpt_photos += 1
+
+            logger.info("\t- Mise à jour de tblso_Rate_Analyse")
+            sql = """INSERT INTO tblso_Rate_Analyse (
+                            lngChantierId, bytIntervId, SI_InspName, SI_AutoNumber,
+                            [Classement tronons], Nom_troncon, S_StartNodeType, Sens_ecoul, S_EndNodeType,
+                            S_PipeShape, MateriauCourt, SI_Date, nb_Arbres, ANNEE_POSE,
+                            Route, NRoute, Test_ecoulement, MaxDeS_StartNodeCoord_Z, MaxDeS_EndNodeCoord_Z,
+                            MaxDeS_Sectionlength, MaxDeS_Pipelength, MaxDeDiametre, cpt_Photos, [Total de SO_ID],
+                            1, 2, 3, 4, 5
+                            )
+                    VALUES ({inspection.lng_chantier_id}, {inspection.byt_interv_id}, {inspection.nom_chantier}, {inspection.si_autonumber},
+                            {inspection.classement_troncons}, {inspection.nom_troncon}, {inspection.startnode_type}, {inspection.sens_ecoul}, {inspection.endnode_type},
+                            {inspection.pipe_shape}, {inspection.materiau}, {inspection.si_date}, {inspection.arbres}, {inspection.annee_pose},
+                            {inspection.route}, {inspection.n_route}, {inspection.test_ecoulement}, {inspection.startnode_z}, {inspection.endnode_z},
+                            {inspection.section_length}, {inspection.pipe_length}, {inspection.diametre}, {inspection.nb_photos}, {inspection.nb_ops},
+                            {inspection.rate_1}, {inspection.rate_2}, {inspection.rate_3}, {inspection.rate_4}, {inspection.rate_5}
+                            )
+                    """.format(inspection)
+            controles_db.execute(sql)
+
+            # Met à jour tblvideointervs.strResGlobal avec le resultat global
+            #  le resultat global vaut '-' si un de ces trois champs n'est pas nul: tbl_so_rate.1, tbl_so_rate.2, tbl_so_rate.3
+            logger.info("\t- Mise à jour du resultat global dans tblvideointervs")
+            sql = """UPDATE  tblvideointervs
+                     SET strResGlobal='{}'
+                     WHERE lngChantierId= {} AND bytIntervId= {}
+                    """.format('-' if (inspection.rate_1 or inspection.rate_2 or inspection.rate_3) else '+',
+                               inspection.lng_chantier_id,
+                               inspection.byt_interv_id)
+            controles_db.execute(sql)
+
+            # Met à jour la table tblVideoBases pour marquer le chantier comme traité
+            logger.info("\t- Mise à jour de tblVideoBases")
+            sql = """UPDATE tblVideoBases
+                     SET blnWincan=-1,bytNbInterv={}
+                     WHERE lngChantierId={}
+                     """.format(inspection.byt_interv_id,
+                                inspection.lng_chantier_id)
+            controles_db.execute(sql)
+
+            # Met à jour les données du réseau dans tblChantiers
+            logger.info("\t- Mise à jour des données du réseau dans tblChantiers")
+            sql = """UPDATE tblChantiers
+                     SET  bytFoncReseauId ={} , bytNatureReseauId={}, bytTypeReseauId={}
+                     WHERE lngChantierId={}
+                     """.format(inspection.section_use,
+                                inspection.section_purpose,
+                                inspection.section_type,
+                                inspection.inspection.lng_chantier_id)
+            controles_db.execute(sql)
+
+
+        logger.info("Commit des modifications")
         controles_db.commit()
         wincan_db.commit()