def insertC2CWeekPartnerRegionAdm(self, weekString): prevWeekString = Utils.getPrevWeekString(weekString) prevWeekData = self.getWeekValues(prevWeekString) weekData = self.getWeekValues(weekString) for c2c in weekData: for prevC2C in prevWeekData: if (prevC2C.partnerId == c2c.partnerId and prevC2C.regionAdm == c2c.regionAdm): c2c.c2cS1 = prevC2C.c2c c2c.evolS1 = c2c.c2c - prevC2C.c2c sessionFactory = SessionFactory() session = sessionFactory.Session() try: print(time.strftime("%d/%m/%Y %H:%M:%S"), "Début insertion ") session.add_all(weekData) session.commit() print(time.strftime("%d/%m/%Y %H:%M:%S"), "Fin insertion ") print(time.strftime("%d/%m/%Y %H:%M:%S"), "Fin insertions avec succès") except Exception as ex: self.view_traceback() print(time.strftime("%d/%m/%Y %H:%M:%S"), "Echec de l'insertion, annulation des modifications") session.rollback() finally: session.close() print(time.strftime("%d/%m/%Y %H:%M:%S"), "Session close")
def insertNewWeek(self, weekString): print( time.strftime("%d/%m/%Y %H:%M:%S"), "Début calculs préalables à l'insertion d'une nouvelle semaine c2s_week_stkb", weekString) prevWeekString = Utils.getPrevWeekString(weekString) print( time.strftime("%d/%m/%Y %H:%M:%S"), "Fin des calculs préalables à l'insertion d'une nouvelle semaine c2s_week_stkb", weekString) print(time.strftime("%d/%m/%Y %H:%M:%S"), "Chargement des données pour la semaine précédente") stkbsPreviousWeek = self.getC2SWeek(prevWeekString) print(time.strftime("%d/%m/%Y %H:%M:%S"), "Chargement des données pour la semaine en cours") stkbsWeek = self.getAllStkbForWeek(weekString) print(time.strftime("%d/%m/%Y %H:%M:%S"), "Début de la complétion des lignes") stkbsToAdd = [] for stkb in stkbsWeek: print(time.strftime("%d/%m/%Y %H:%M:%S"), ">>>> Début de la complétion pour", stkb) stkbPrev = stkbsPreviousWeek.get(stkb) if stkbPrev != None: stkbsWeek[stkb].c2sMoins1 = stkbPrev.c2s stkbsWeek[ stkb].evolutionS1 = stkbsWeek[stkb].c2s - stkbPrev.c2s stkbsToAdd.append(stkbsWeek[stkb]) print(time.strftime("%d/%m/%Y %H:%M:%S"), "Fin de la complétion des lignes") # à ce niveau ont a toutes les données sur l'évolution et on peut donce enregistrer la nouvelle semaine sessionFactory = SessionFactory() session = sessionFactory.Session() try: print(time.strftime("%d/%m/%Y %H:%M:%S"), "Début insertion ") session.add_all(stkbsToAdd) session.commit() print(time.strftime("%d/%m/%Y %H:%M:%S"), "Fin insertion ") print(time.strftime("%d/%m/%Y %H:%M:%S"), "Fin insertions avec succès") except Exception as ex: self.view_traceback() print(time.strftime("%d/%m/%Y %H:%M:%S"), "Echec de l'insertion, annulation des modifications") session.rollback() finally: session.close() print(time.strftime("%d/%m/%Y %H:%M:%S"), "Session close")