|
|
@@ -8,26 +8,28 @@
|
|
|
|
|
|
@author: olivier.massot, févr. 2018
|
|
|
'''
|
|
|
-from datetime import datetime
|
|
|
+from datetime import datetime, timedelta
|
|
|
import logging
|
|
|
import sys
|
|
|
|
|
|
-from path import Path
|
|
|
+from path import Path # @UnusedImport
|
|
|
|
|
|
from core import logconf
|
|
|
from core.model import Model
|
|
|
from core.pde import ControlesDb, AnalytiqueDb, mk_workdir, CommunDb
|
|
|
|
|
|
+
|
|
|
logger = logging.getLogger("ctrl2analytique")
|
|
|
logconf.start("ctrl2analytique", logging.DEBUG)
|
|
|
|
|
|
# # POUR TESTER, décommenter les lignes suivantes
|
|
|
+# > Lancer le script /resources/test_ctrl2analytique.py pour reinitialiser les données de la base de test
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
-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")
|
|
|
+# 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")
|
|
|
|
|
|
##-----------------------------------------------
|
|
|
|
|
|
@@ -636,30 +638,36 @@ analytique_db.commit()
|
|
|
|
|
|
# > Le temps d'installation est le temps passé par chaque agent en transport, préparation, reporting...etc.
|
|
|
# > C'est donc le temps de travail théorique, moins le temps d'intervention.
|
|
|
+# > pour des raisons de performances, on ne commence le traitement qu'à partir de l'année N-1
|
|
|
|
|
|
logger.info("Mise à jour des temps d'installation...")
|
|
|
|
|
|
-sql = """ SELECT First(tbl_Intervention.dblInterventionId) AS dblInterventionId,
|
|
|
- tbl_Intervention.strEquipeId, tbl_Intervention.dtmIntervention,
|
|
|
- Year([dtmIntervention]) AS annee, Sum(tbl_Intervention.dtmDureeIntervention) AS SD
|
|
|
+# date zéro pour Access
|
|
|
+date0 = datetime(1899, 12, 30, 0, 0, 0)
|
|
|
+
|
|
|
+# On parcourt les interventions.
|
|
|
+# Lorsque le temps d'intervention total d'une même équipe un même jour est inférieur à 8h,
|
|
|
+# On affecte la différence de temps à la première intervention en tant que 'temps d'installation'
|
|
|
+
|
|
|
+sql = """SELECT First(tbl_Intervention.dblInterventionId) AS dblInterventionId, tbl_Intervention.strEquipeId,
|
|
|
+ tbl_Intervention.dtmIntervention, CDate(Sum(tbl_Intervention.dtmDureeIntervention)) AS SD
|
|
|
FROM tbl_Intervention
|
|
|
- WHERE (((tbl_Intervention.strLiaisonControle) Like '*/*'))
|
|
|
- GROUP BY tbl_Intervention.strEquipeId, Year([dtmIntervention]), tbl_Intervention.dtmIntervention
|
|
|
- HAVING (((tbl_Intervention.strEquipeId) Is Not Null)
|
|
|
- AND ((Year([dtmIntervention]))>=Year(Date())-1)
|
|
|
- AND ((tbl_Intervention.dtmIntervention) Is Not Null)
|
|
|
- AND ((Sum(tbl_Intervention.dtmDureeIntervention))>0
|
|
|
- And (Sum(tbl_Intervention.dtmDureeIntervention)) Is Not Null)
|
|
|
- AND ((Count(tbl_Intervention.dtmDureeIntervention))>0
|
|
|
- And (Count(tbl_Intervention.dtmDureeIntervention)) Is Not Null))"""
|
|
|
-
|
|
|
-for interv in analytique_db.read(sql):
|
|
|
- if interv.SD < (8 / 24):
|
|
|
- tps_install = ((8 / 24) - interv.SD)
|
|
|
- sql = """UPDATE tbl_Intervention SET tbl_Intervention.dtmDureeInstallation = #{}#
|
|
|
- WHERE (((tbl_Intervention.dblInterventionId)={}));""".format(tps_install, interv.dblInterventionId)
|
|
|
- analytique_db.execute(sql)
|
|
|
- logger.debug("* Mise à jour du temps d'installation de l'intervention {}".format(interv.dblInterventionId))
|
|
|
+ WHERE tbl_Intervention.strLiaisonControle Like '%/%'
|
|
|
+ AND Year([dtmIntervention])>={}
|
|
|
+ AND tbl_Intervention.dtmDureeIntervention > 0
|
|
|
+ AND tbl_Intervention.strEquipeId Is Not Null
|
|
|
+ GROUP BY tbl_Intervention.strEquipeId, tbl_Intervention.dtmIntervention
|
|
|
+ HAVING (((CDate(Sum(tbl_Intervention.dtmDureeIntervention)))<#1899/12/30 8:0:0#))
|
|
|
+ """.format(datetime.now().year - 1)
|
|
|
+
|
|
|
+for interv in analytique_db.read_all(sql):
|
|
|
+ tps_install = (date0 + timedelta(hours=8) - interv.SD)
|
|
|
+ sql = """UPDATE tbl_Intervention SET tbl_Intervention.dtmDureeInstallation = #{}#
|
|
|
+ WHERE (((tbl_Intervention.dblInterventionId)={}));""".format(date0 + tps_install, interv.dblInterventionId)
|
|
|
+ analytique_db.execute(sql)
|
|
|
+ logger.debug("* Mise à jour du temps d'installation de l'intervention {}".format(interv.dblInterventionId))
|
|
|
analytique_db.commit()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
logger.info("# Import terminé")
|