def insertC2CJourPartnerRegionAdm(self, day):
        sessionFactory = SessionFactory()

        session = sessionFactory.Session()

        data = []

        connection = sessionFactory.getConnection()
        result = connection.execute(
            "select partner_id, partner_name, region_adm, region_com, sem, jour, sum(c2c) c2c  from dd_c2c_jour_stkp where jour = '"
            + day + "' group by partner_id, region_adm")

        for row in result:
            tmpElt = DDC2CJourPartnerRegionAdm(row)
            data.append(tmpElt)

        connection.close()

        try:
            print(time.strftime("%d/%m/%Y %H:%M:%S"), "Début insertion ")
            session.add_all(data)
            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")
示例#2
0
    def insertObjectifsMensuelACVI(self, month):

        sessionFactory = SessionFactory()

        data = []

        #01082017

        connection = sessionFactory.getConnection()
        requete = "select  acvi, mois,  sum(objectif) objectif from dd_objectif_mensuel_c2s_stkb where mois = '" + month + "' GROUP BY acvi"
        result = connection.execute(requete)

        for row in result:
            tmpElt = DDObjectifMensuelACVI(row)
            print(tmpElt)
            data.append(tmpElt)
        connection.close()

        session = sessionFactory.Session()
        try:
            session.add_all(data)
            session.commit()
            print(time.strftime("%d/%m/%Y %H:%M:%S"),
                  "Fin insertion avec succès")
        except Exception as ex:
            self.view_traceback()
            session.rollback()
            print(time.strftime("%d/%m/%Y %H:%M:%S"),
                  "Fin insertion avec erreur, rollback fait!")
        finally:
            session.close()
            print(time.strftime("%d/%m/%Y %H:%M:%S"), "Session close")
示例#3
0
    def insertC2CSTKADay(self, day):
        
        sessionFactory = SessionFactory()

        session = sessionFactory.Session()

        stkps = session.query(DDC2CJourSTKP).filter_by(jour = day)

        resultat = dict()

        sem = Utils.getWeekNumberFromDate(day, self._DATE_FORMAT)

        for stkp in stkps:
            if(resultat.get(stkp.stkaMsisdn) == None):                
                tmp = DDC2CJourSTKA(stkp)
                tmp.jour = day
                tmp.sem = sem
                tmp.stkaMsisdn = stkp.stkaMsisdn
                resultat[stkp.stkaMsisdn] = tmp       
                
        connection = sessionFactory.getConnection()
        result = connection.execute("select sum(c2c) c2c, stka_msisdn  from dd_c2c_jour_stkp where jour= '"+day+"' group by stka_msisdn")

        for row in result:            
            stkaMsisdn = row['stka_msisdn']
            tmpC2c = row['c2c']
            resultat[stkaMsisdn].c2c = tmpC2c

        connection.close()    

        toAdd = []

        for res, val in resultat.items():
            toAdd.append(val)

        try:
            print(time.strftime("%d/%m/%Y %H:%M:%S"), "Début insertion ")
            session.add_all(toAdd)
            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 getWeekValues(self, weekString):
        sessionFactory = SessionFactory()

        session = sessionFactory.Session()

        data = []

        connection = sessionFactory.getConnection()
        result = connection.execute(
            "select partner_id, partner_name, region_adm, region_com, sem, sum(c2c) c2c  from dd_c2c_jour_stkp where sem = '"
            + weekString + "' group by partner_id, region_adm")

        for row in result:
            tmpElt = DDC2CWeekPartnerRegionAdm(row)
            data.append(tmpElt)
        connection.close()

        return data
    def getMonthValues(self, month):
        sessionFactory = SessionFactory()

        session = sessionFactory.Session()

        data = []

        #01082017

        connection = sessionFactory.getConnection()
        requete = "select partner_id, partner_name, region_adm, region_com, concat(substr(replace(jour, '/', ''), 5), substr(replace(jour, '/', ''), 3, 2))  mois, sum(c2c) c2c  from dd_c2c_jour_stkp where concat(substr(replace(jour, '/', ''), 5), substr(replace(jour, '/', ''), 3, 2)) = '" + month + "' group by partner_id, region_adm"
        result = connection.execute(requete)

        for row in result:
            tmpElt = DDC2CMoisPartnerRegionAdm(row)
            data.append(tmpElt)
        connection.close()

        return data