| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- '''
- '''
- from core.pde import AgrhumDb , FraisDeplacement, HeureSupp
- import logging
- import sys
- import json
- from datetime import datetime
- from path import Path # @UnusedImport
- from core import logconf
- from core.model import Sql
- 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
- ##-----------------------------------------------
- AgrhumDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\BDD_ParcRH.mdb")
- #CommunDb._path = Path(r"\\h2o\local\4-transversal\BDD\mdb_test\Commun_Data.mdb")
- #logger.handlers = [h for h in logger.handlers if (type(h) == logging.StreamHandler)]
- #logger.warning("<<<<<<<<<<<<<< Mode TEST >>>>>>>>>>>>>>>>>")
- ##-----------------------------------------------
- print ("La recherche du python de l'amazonie commence ici, pas encore l'anaconda :")
- agrhum_db = AgrhumDb(autocommit=False)
- CodeAgent = "T9"
- MoisRH = 12
- AnneeRH = 2017
- #Verification dans la table tbl_suiviRH suivi si la ligne agent mois annnée existe
- #Verfification si etat != de Importé ou si valide = True : demande confirmation pour retraitement
- #Si retraitement on suprime des tables cibles tbl_formHS et tbl_formDep
- #Parcours de tbl_importRH transfo donnée et écriture dans tbl_formdep
- #Parcours de tbl_importRH transfo donnée et écriture dans tbl_formHS
- def main():
- if agrhum_db.exists("select * from tbl_suiviRH where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH)):
- #if input("Voulez vous retarite ces donnees(o/n)") != "o" :
- # print("Annulation")
- # return
- agrhum_db.execute("delete * from tbl_formDep where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH))
- agrhum_db.execute("delete * from tbl_formHS where codeagent ='{}' and moisrh = {} and anneerh = {}".format(CodeAgent, MoisRH,AnneeRH))
- data = agrhum_db.read_all("select * from tbl_importrh where codeagent ='{}' and Month([daterh]) = {} and Year([daterh]) = {}".format(CodeAgent, MoisRH,AnneeRH))
- sql = Sql.format("""SELECT
- tbl_baremes.NomBareme,
- tbl_baremes.BorneInf,
- tbl_baremes.BorneSup,
- tbl_baremes.Valeur,
- tbl_PeriodeBareme.DateInf,
- tbl_PeriodeBareme.DateSup
- FROM tbl_baremes
- INNER JOIN tbl_PeriodeBareme ON (tbl_baremes.PeriodeValidite = tbl_PeriodeBareme.CodePeriode) AND (tbl_baremes.NomBareme = tbl_PeriodeBareme.NomBareme)
- WHERE tbl_baremes.NomBareme = 'Heures de route'
- AND tbl_PeriodeBareme.DateInf <= {:date}
- AND (tbl_PeriodeBareme.DateSup is null or tbl_PeriodeBareme.DateSup > {:date}) """, datetime(AnneeRH,MoisRH,1), datetime(AnneeRH,MoisRH,1))
- baremes = agrhum_db.read_all(sql)
- index = {}
- for el in data :
- if not el.DateRH.day in index :
- fraisdep = FraisDeplacement()
- fraisdep.AnneeRH = AnneeRH
- fraisdep.CodeAgent = CodeAgent
- fraisdep.MoisRH = MoisRH
- fraisdep.JourRH = el.DateRH.day
- fraisdep.Depart = el.Depart
- # mettre a jour le codedepart
- fraisdep.Itineraire = " - ".join([loc for loc in (fraisdep.Depart, el.Localisation) if loc])
- fraisdep.Distance1_perso = int(el.DistanceTranche1) if el.VehiculePersoTranche1 == "True" else 0
- fraisdep.Distance2_perso = int(el.DistanceTranche2) if el.VehiculePersoTranche2 == "True" else 0
- fraisdep.Distance2_service = int(el.DistanceTranche2) if not el.VehiculePersoTranche2 == "True" else 0
- fraisdep.Repas = int(el.Repas)
- index[el.DateRH.day] = fraisdep
- else :
- index[el.DateRH.day].Itineraire += " - " + el.Localisation
- index[el.DateRH.day].Distance1_perso += int(el.DistanceTranche1) if el.VehiculePersoTranche1 == "True" else 0
- index[el.DateRH.day].Distance2_perso += int(el.DistanceTranche2) if el.VehiculePersoTranche2 == "True" else 0
- index[el.DateRH.day].Distance2_service += int(el.DistanceTranche2) if not el.VehiculePersoTranche2 == "True" else 0
- index[el.DateRH.day].Repas += int(el.Repas)
- for fraisdep in index.values() :
- distance2 = (fraisdep.Distance2_perso + fraisdep.Distance2_service)
- fraisdep.HeuresDep = next((bareme.Valeur for bareme in baremes if bareme.BorneInf <= distance2 and bareme.BorneSup > distance2))
- fraisdep.HeuresDepNuit = next((bareme.Valeur for bareme in baremes if bareme.BorneInf <= fraisdep.Distance1_perso and bareme.BorneSup > fraisdep.Distance1_perso))
- with open(Path(r"%temp%\test.json").expandvars(), "w+") as f:
- f.write(str(index))
- if __name__ == "__main__":
- main()
|