|
|
@@ -16,7 +16,7 @@ from path import Path
|
|
|
|
|
|
from core import logconf
|
|
|
from core.model import Model
|
|
|
-from core.pde import ControlesDb, AnalytiqueDb, mk_workdir
|
|
|
+from core.pde import ControlesDb, AnalytiqueDb, mk_workdir, CommunDb
|
|
|
|
|
|
logger = logging.getLogger("ctrl2analytique")
|
|
|
logconf.start("ctrl2analytique", logging.DEBUG)
|
|
|
@@ -27,6 +27,7 @@ logconf.start("ctrl2analytique", logging.DEBUG)
|
|
|
logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
|
|
|
ControlesDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\cg67Parc_data.mdb")
|
|
|
AnalytiqueDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Db_analytique.mdb")
|
|
|
+CommunDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Commun_Data.mdb")
|
|
|
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
@@ -43,11 +44,17 @@ analytique_db = AnalytiqueDb(autocommit=False)
|
|
|
# Connexion à Controles
|
|
|
controles_db = ControlesDb(autocommit=False)
|
|
|
|
|
|
+# Connexion à CommunDb
|
|
|
+commun_db = CommunDb(autocommit=False)
|
|
|
+
|
|
|
# Make the working directory
|
|
|
workdir = mk_workdir("ctrl2analytique")
|
|
|
affaires_file = workdir / "affaires.csv"
|
|
|
intervs_file = workdir / "intervs.csv"
|
|
|
|
|
|
+errors = []
|
|
|
+
|
|
|
+
|
|
|
# > Supprime les fichiers d'import s'il existent
|
|
|
for file in (affaires_file, intervs_file):
|
|
|
if file.exists():
|
|
|
@@ -104,6 +111,7 @@ with open(affaires_file, 'w+') as f:
|
|
|
|
|
|
# on insère les affaires depuis tblCommandes et tblChantier (le lien est strLiaisonControle)
|
|
|
|
|
|
+compteur = 0
|
|
|
sql = """ SELECT tblCommandes.lngChantierId, tblCommandes.bytCommandeId, tblChantiers.strSubdivisionId, tblChantiers.strCollectiviteId as ChantierCollectiviteId, tblChantiers.strLocChantier,
|
|
|
tblChantiers.strEntrepriseId, tblCommandes.strCollectiviteId as CommandeCollectiviteId, tblCommandes.dtmCommande, tblCommandes.strRefCommande, tblCommandes.blnMarche, tblCommandes.dblMtMarche, tblCommandes.strdevis
|
|
|
FROM tblChantiers INNER JOIN tblCommandes ON tblChantiers.lngChantierId = tblCommandes.lngChantierId
|
|
|
@@ -132,13 +140,16 @@ for data in controles_db.read(sql):
|
|
|
with open(affaires_file, 'a') as f:
|
|
|
f.write(affaire.to_csv())
|
|
|
|
|
|
+ compteur += 1
|
|
|
+
|
|
|
+logger.info("> {} affaires ajoutées à {}".format(compteur, affaires_file))
|
|
|
|
|
|
# *** 2- Import des interventions de contrôle du compactage dans le fichier intervs.csv
|
|
|
|
|
|
class Interv(Model):
|
|
|
_FIELDS = ["strEquipeId", "strEnginId", "strRapportId", "strTypeInterventionId",
|
|
|
"strTypeInterventionId", "strCatégorieInterventionId", "dblquantite", "strunite", "dtmIntervention",
|
|
|
- "dtmDureeIntervention", "dtmDureeInstallation", "strLiaisonControle", "strArticleId",
|
|
|
+ "dtmDureeIntervention", "dtmDureeInstallation", "strLiaisonControle", "strArticleId", "intPeriode",
|
|
|
"remarques", "strgrandeur1", "strgrandeur2", "strgrandeur3",
|
|
|
"strcaracteristique1", "strcaracteristique2", "strcaracteristique3",
|
|
|
"dtmImportation", "strTest", "LienAff"
|
|
|
@@ -149,6 +160,17 @@ firstline = "\t".join(Interv._FIELDS + ["\n"])
|
|
|
with open(intervs_file, 'w+') as f:
|
|
|
f.write(firstline)
|
|
|
|
|
|
+def engin_existe(strEnginId):
|
|
|
+ return analytique_db.exists("SELECT strEnginId FROM tbl_Engin WHERE strEnginId='{}'".format(strEnginId))
|
|
|
+
|
|
|
+def get_periode_validite(date_interv):
|
|
|
+ sql = """SELECT intPeriodeValiditeId FROM tblTarifValidite
|
|
|
+ WHERE [dtmValiditeDebut] <= #{date_interv}# AND [dtmValiditeFin] > #{date_interv}# AND [bytClasseTarifId]=1
|
|
|
+ """.format(date_interv=date_interv)
|
|
|
+ return commun_db.first(sql).intPeriodeValiditeId
|
|
|
+
|
|
|
+compteur = 0
|
|
|
+
|
|
|
sql = """SELECT tblCompactageIntervs.lngChantierId, tblCompactageIntervs.bytCommandeId, tblCompactageIntervs.bytIntervId, tblCompactageIntervs.strEquipeId,
|
|
|
tblCompactageEngins.strEnginId, tblCompactageIntervs.lngRapportId, tblCompactageBases.memTravaux, tblCompactageResultats.dtmEssai,
|
|
|
tblCompactageResultats.dtmDuree, tblCompactagePartChantiers.strTrcRegard, tblMateriaux.strMatériau,
|
|
|
@@ -179,10 +201,12 @@ def get_type_compactage_interv(observation):
|
|
|
for data in controles_db.read(sql):
|
|
|
interv = Interv()
|
|
|
|
|
|
+ if not engin_existe(data.strEnginId):
|
|
|
+ errors.append("""Intervention compactage {}/{}/{}/{}: l'engin {} n'existe pas"""
|
|
|
+ .format(data.lngChantierId, data.bytCommandeId, data.bytIntervId, data.bytPartChantierId, data.strEnginId))
|
|
|
+
|
|
|
interv.strEquipeId = "C{}".format(data.strEquipeId)
|
|
|
interv.strEnginId = data.strEnginId
|
|
|
- # TODO: Contrôler si l'engin existe dans tbl_Engin
|
|
|
- interv.strEnginId = data.strEnginId
|
|
|
interv.strRapportId = data.strRapportId
|
|
|
interv.strTypeInterventionId = get_type_compactage_interv(data.memTravaux)
|
|
|
interv.strCatégorieInterventionId = "CC"
|
|
|
@@ -193,6 +217,7 @@ for data in controles_db.read(sql):
|
|
|
interv.dtmDureeInstallation = 0 # Les temps d'installation seront recalculés en fin de traitement
|
|
|
interv.strLiaisonControle = "{}/{}/{}".format(data.lngChantierId, data.bytCommandeId, data.bytIntervId)
|
|
|
interv.strArticleId = data.strEnginId
|
|
|
+ interv.intPeriode = get_periode_validite(data.dtmEssai)
|
|
|
interv.remarques = data.strTrcRegard
|
|
|
interv.strgrandeur1 = data.strMatériau
|
|
|
interv.strgrandeur2 = data.strMatériau
|
|
|
@@ -207,7 +232,12 @@ for data in controles_db.read(sql):
|
|
|
with open(intervs_file, 'a') as f:
|
|
|
f.write(interv.to_csv())
|
|
|
|
|
|
+ compteur += 1
|
|
|
+
|
|
|
+logger.info("> {} interventions Compactage ajoutées à {}".format(compteur, intervs_file))
|
|
|
+
|
|
|
# *** 3- Import des interventions de contrôle d'étanchéité dans le fichier intervs.csv
|
|
|
+compteur = 0
|
|
|
|
|
|
sql = """SELECT tblEtancheiteIntervs.lngChantierId, tblEtancheiteIntervs.bytCommandeId, tblEtancheiteIntervs.bytIntervId, tblEtancheiteIntervs.strEquipeId,
|
|
|
tblEtancheiteIntervs.lngRapportId, tblEtancheitePartChantiers.bytTypeEssai, tblMateriaux.strMateriauId, tblMateriaux.strMatériau,
|
|
|
@@ -244,6 +274,7 @@ for data in controles_db.read(sql):
|
|
|
interv.dtmDureeInstallation = 0 # Les temps d'installation seront recalculés en fin de traitement
|
|
|
interv.strLiaisonControle = "{}/{}/{}".format(data.lngChantierId, data.bytCommandeId, data.bytIntervId)
|
|
|
interv.strArticleId = interv.strEnginId
|
|
|
+ interv.intPeriode = get_periode_validite(data.dtmEssai)
|
|
|
interv.remarques = data.strTrcRegard
|
|
|
interv.strgrandeur1 = data.strMatériau
|
|
|
interv.strgrandeur2 = data.intDiametre
|
|
|
@@ -260,8 +291,12 @@ for data in controles_db.read(sql):
|
|
|
with open(intervs_file, 'a') as f:
|
|
|
f.write(interv.to_csv())
|
|
|
|
|
|
+ compteur += 1
|
|
|
+
|
|
|
+logger.info("> {} interventions Etanchéité ajoutées à {}".format(compteur, intervs_file))
|
|
|
|
|
|
# *** 4- Import des interventions d'inspection vidéo dans le fichier intervs.csv
|
|
|
+compteur = 0
|
|
|
|
|
|
sql = """SELECT tblVideoIntervs.lngChantierId, tblVideoIntervs.bytCommandeId, tblVideoIntervs.bytIntervId, tblVideoIntervs.strEquipeId,
|
|
|
tblVideoEngins.strEnginId, tblVideoIntervs.lngRapportId, First(tblso_rate_Analyse.MateriauCourt) AS strmateriau, tblVideoIntervs.lngTroncon,
|
|
|
@@ -279,6 +314,11 @@ sql = """SELECT tblVideoIntervs.lngChantierId, tblVideoIntervs.bytCommandeId, tb
|
|
|
for data in controles_db.read(sql):
|
|
|
interv = Interv()
|
|
|
|
|
|
+
|
|
|
+ if not engin_existe(data.strEnginId):
|
|
|
+ errors.append("""Intervention compactage {}/{}/{}/1: l'engin {} n'existe pas"""
|
|
|
+ .format(data.lngChantierId, data.bytCommandeId, data.bytIntervId, data.strEnginId))
|
|
|
+
|
|
|
interv.strEquipeId = "C{}".format(data.strEquipeId)
|
|
|
interv.strEnginId = data.strEnginId
|
|
|
interv.strRapportId = data.lngRapportId
|
|
|
@@ -291,6 +331,7 @@ for data in controles_db.read(sql):
|
|
|
interv.dtmDureeInstallation = 0 # Les temps d'installation seront recalculés en fin de traitement
|
|
|
interv.strLiaisonControle = "{}/{}/{}".format(data.lngChantierId, data.bytCommandeId, data.bytIntervId)
|
|
|
interv.strArticleId = data.strEnginId
|
|
|
+ interv.intPeriode = get_periode_validite(data.dtmIntervDu)
|
|
|
interv.remarques = data.memObservation
|
|
|
interv.strgrandeur1 = data.strmateriau
|
|
|
interv.strgrandeur2 = data.diam
|
|
|
@@ -307,11 +348,78 @@ for data in controles_db.read(sql):
|
|
|
with open(intervs_file, 'a') as f:
|
|
|
f.write(interv.to_csv())
|
|
|
|
|
|
+ compteur += 1
|
|
|
+
|
|
|
+logger.info("> {} interventions ITV ajoutées à {}".format(compteur, intervs_file))
|
|
|
+
|
|
|
+# *** 5- Interruption pour corection manuelle des données (si nécessaire)
|
|
|
+logging.info("Les données à importer ont été ajoutées aux fichiers '{}' et '{}'".format(affaires_file, intervs_file))
|
|
|
+
|
|
|
+if errors:
|
|
|
+ logging.error("<!> Des erreurs ont été détectées dans les données à importer. <!>")
|
|
|
+ for msg in errors:
|
|
|
+ logging.error(msg)
|
|
|
+
|
|
|
+prompt = ""
|
|
|
+while prompt != "v":
|
|
|
+ prompt = input(">> Veuillez contrôler les données, puis taper 'v' pour continuer, ou 'q' pour quitter...")
|
|
|
+ if prompt == "q":
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+
|
|
|
+# *** 6- Insertion des données dans les tables Analytique
|
|
|
+with open(affaires_file) as f:
|
|
|
+ next(f) # saute la première ligne
|
|
|
+
|
|
|
+ for line in f:
|
|
|
+ affaire = Affaire.from_csv(line)
|
|
|
+
|
|
|
+ sql = """ INSERT INTO tbl_Affaires ( strMOId, strMOeId, strEntrepriseId, strCommneId, strLieux, strTypeId, dtmCommande, Ref,
|
|
|
+ blnMarche, dblMarche, intTypeContrat, strCT, strAvancement, strLiaisonControle, intDevisId, blnTarification,
|
|
|
+ blnAnalyse, remarques, strSituation, dtmFin, intCoefFG )
|
|
|
+ SELECT {strMOId}, {strMOeId}, {strEntrepriseId}, {strCommneId}, {strLieux}, {strTypeId}, {dtmCommande},
|
|
|
+ {Ref}, {blnMarche}, {dblMarche}, {intTypeContrat}, {strCT}, {strAvancement}, {strLiaisonControle}, {intDevisId},
|
|
|
+ {blnTarification}, {blnAnalyse}, {remarques}, {strSituation}, {dtmFin}, {intCoefFG}
|
|
|
+ """.format(strMOId=affaire.strMOId,
|
|
|
+ strMOeId=affaire.strMOeId,
|
|
|
+ strEntrepriseId=affaire.strEntrepriseId,
|
|
|
+ strCommneId=affaire.strCommneId,
|
|
|
+ dtmCommande=affaire.dtmCommande,
|
|
|
+ Ref=affaire.Ref,
|
|
|
+ blnMarche=affaire.blnMarche,
|
|
|
+ dblMarche=affaire.dblMarche,
|
|
|
+ intTypeContrat=affaire.intTypeContrat,
|
|
|
+ strCT=affaire.strCT,
|
|
|
+ strAvancement=affaire.strAvancement,
|
|
|
+ strLiaisonControle=affaire.strLiaisonControle,
|
|
|
+ intDevisId=affaire.intDevisId,
|
|
|
+ blnTarification=affaire.blnTarification,
|
|
|
+ blnAnalyse=affaire.blnAnalyse,
|
|
|
+ remarques=affaire.remarques,
|
|
|
+ strSituation=affaire.strSituation,
|
|
|
+ dtmFin=affaire.dtmFin,
|
|
|
+ intCoefFG=affaire.intCoefFG)
|
|
|
+
|
|
|
+ analytique_db.execute(sql)
|
|
|
+
|
|
|
+ affaire.affaireId = analytique_db.first("SELECT TOP 1 DblAffaireId FROM tbl_Affaires ORDER BY DblAffaireId DESC").DblAffaireId
|
|
|
+ # Stocker cette valeur dans un dico associéeau strLiaisonControle, pour la maj de tblIntervs
|
|
|
+
|
|
|
+ # Insérer ici les intervs liées à l'affaire (?)
|
|
|
+
|
|
|
+ # Maj champs MOS, puis committer
|
|
|
+
|
|
|
+
|
|
|
+with open(intervs_file) as f:
|
|
|
+ next(f) # saute la première ligne
|
|
|
|
|
|
-# *** 5- Mises à jours et contrôles des erreurs
|
|
|
+ for line in f:
|
|
|
+ interv = Interv.from_csv(line)
|
|
|
|
|
|
|
|
|
+# Reprendre la fonction PostVerif
|
|
|
|
|
|
+# Maj des temps d'installation
|
|
|
|
|
|
|
|
|
|