Ajout traitement des donneed de la Bdd SQLite

This commit is contained in:
David 2022-12-19 00:22:37 +01:00
parent e1e10f5c47
commit a3e6532bd3

View File

@ -17,6 +17,7 @@ STATS_FR_TOT_FIELDS = ['conferences creees total','conferences totalement echoue
STATS_AVG_FIELDS = ['largest_conference',]
STATS_FR_AVG_FIELDS = ['plus grande conference',]
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
dbName = 'jitsi_stats'
# Classes
class Stats:
@ -83,8 +84,20 @@ class Stats:
return octets,unit
def parse2(self):
res = self.db.dbQuery(f"""SELECT * FROM {dbname} WHERE ts > {self.startDate} AND ts < {self.endDate}""")
return res
res = self.db.dbQuery(f"""SELECT * FROM {dbName} WHERE timestamp > {self.startDate} AND timestamp < {self.endDate}""")
consolided = {}
for line in res:
field = line[2]
if field in STATS_TOT_FIELDS:
if field in consolided:
consolided[field] = consolided[field] + int(line[3])
else:
consolided[field] = int(line[3])
if field in STATS_AVG_FIELDS:
if field in consolided:
if consolided[field] < int(line[3]):
consolided[field] = int(line[3])
return consolided
def parse(self):
if len(self.files) <= 0:
@ -192,13 +205,16 @@ def runMain():
year = currentDate.year
stats = Stats(year,mois)
res = stats.parse()
res = stats.parse2()
for (k,v) in res.items():
if k in STATS_TOT_FIELDS:
chaine = STATS_FR_TOT_FIELDS[STATS_TOT_FIELDS.index(k)]
elif k in STATS_AVG_FIELDS:
chaine = STATS_FR_AVG_FIELDS[STATS_AVG_FIELDS.index(k)]
print(f"{chaine} : {v}")
print(f"{k}={v}")
#for (k,v) in res.items():
# if k in STATS_TOT_FIELDS:
# chaine = STATS_FR_TOT_FIELDS[STATS_TOT_FIELDS.index(k)]
# elif k in STATS_AVG_FIELDS:
# chaine = STATS_FR_AVG_FIELDS[STATS_AVG_FIELDS.index(k)]
# print(f"{chaine} : {v}")
if __name__ == '__main__':
runMain()