Correction typo
This commit is contained in:
parent
54add4c93a
commit
737edcb7c5
@ -14,8 +14,8 @@ STAT_DIR = '/srv/visio.chapril.org/statistiques/'
|
|||||||
|
|
||||||
STATS_TOT_FIELDS = ['total_conferences_created','total_failed_conferences','total_conferences_completed','total_conference_seconds','total_bytes_received','total_bytes_sent','total_participants','conferences','videochannels','endpoints_sending_audio',]
|
STATS_TOT_FIELDS = ['total_conferences_created','total_failed_conferences','total_conferences_completed','total_conference_seconds','total_bytes_received','total_bytes_sent','total_participants','conferences','videochannels','endpoints_sending_audio',]
|
||||||
STATS_FR_TOT_FIELDS = ['conferences creees total','conferences totalement echouees','conferences terminees total','duree totale conferences','total octets reçus','total octets envoyés','total participants','nombre de conferences','canaux video','clients en audio',]
|
STATS_FR_TOT_FIELDS = ['conferences creees total','conferences totalement echouees','conferences terminees total','duree totale conferences','total octets reçus','total octets envoyés','total participants','nombre de conferences','canaux video','clients en audio',]
|
||||||
STATS_AVG_FIELDS = ['largest_conference',]
|
STATS_MAX_FIELDS = ['largest_conference',]
|
||||||
STATS_FR_AVG_FIELDS = ['plus grande conference',]
|
STATS_FR_MAX_FIELDS = ['plus grande conference',]
|
||||||
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
|
dbPath = '/srv/visio.chapril.org/statistiques/stats_sqlite.db'
|
||||||
dbName = 'jitsi_stats'
|
dbName = 'jitsi_stats'
|
||||||
|
|
||||||
@ -36,7 +36,6 @@ class Stats:
|
|||||||
maxDays = monthrange(self.year,self.mois)[1]
|
maxDays = monthrange(self.year,self.mois)[1]
|
||||||
self.__setEndDate(f'{self.year}-{self.mois}-{maxDays} 23:59:59')
|
self.__setEndDate(f'{self.year}-{self.mois}-{maxDays} 23:59:59')
|
||||||
|
|
||||||
|
|
||||||
def __setStartDate(self,thisDate):
|
def __setStartDate(self,thisDate):
|
||||||
self.startDate = self.__date2timestamp(thisDate)
|
self.startDate = self.__date2timestamp(thisDate)
|
||||||
|
|
||||||
@ -60,7 +59,6 @@ class Stats:
|
|||||||
return int(timestamp)
|
return int(timestamp)
|
||||||
|
|
||||||
def __conv(self,octets,dataType='b'):
|
def __conv(self,octets,dataType='b'):
|
||||||
|
|
||||||
if dataType == 'b':
|
if dataType == 'b':
|
||||||
unit = 'octets'
|
unit = 'octets'
|
||||||
if int(octets) > 1024:
|
if int(octets) > 1024:
|
||||||
@ -83,7 +81,7 @@ class Stats:
|
|||||||
octets = int(octets * 10) / 10
|
octets = int(octets * 10) / 10
|
||||||
return octets,unit
|
return octets,unit
|
||||||
|
|
||||||
def parse2(self):
|
def parse(self):
|
||||||
res = self.db.dbQuery(f"""SELECT * FROM {dbName} WHERE timestamp > {self.startDate} AND timestamp < {self.endDate}""")
|
res = self.db.dbQuery(f"""SELECT * FROM {dbName} WHERE timestamp > {self.startDate} AND timestamp < {self.endDate}""")
|
||||||
consolided = {}
|
consolided = {}
|
||||||
for line in res:
|
for line in res:
|
||||||
@ -93,7 +91,7 @@ class Stats:
|
|||||||
consolided[field] = consolided[field] + int(line[3])
|
consolided[field] = consolided[field] + int(line[3])
|
||||||
else:
|
else:
|
||||||
consolided[field] = int(line[3])
|
consolided[field] = int(line[3])
|
||||||
if field in STATS_AVG_FIELDS:
|
if field in STATS_MAX_FIELDS:
|
||||||
if field in consolided:
|
if field in consolided:
|
||||||
if consolided[field] < int(line[3]):
|
if consolided[field] < int(line[3]):
|
||||||
consolided[field] = int(line[3])
|
consolided[field] = int(line[3])
|
||||||
@ -104,54 +102,11 @@ class Stats:
|
|||||||
if 'seconds' in k:
|
if 'seconds' in k:
|
||||||
(v,u) = self.__conv(consolided[k],dataType='t')
|
(v,u) = self.__conv(consolided[k],dataType='t')
|
||||||
consolided.pop(k)
|
consolided.pop(k)
|
||||||
n_k = k.replace('seconds','')
|
n_k = k.replace('_seconds','')
|
||||||
consolided[n_k] = f"{v} {u}"
|
consolided[n_k] = f"{v} {u}"
|
||||||
|
|
||||||
|
|
||||||
return consolided
|
return consolided
|
||||||
|
|
||||||
def parse(self):
|
|
||||||
if len(self.files) <= 0:
|
|
||||||
return None
|
|
||||||
for f in self.files:
|
|
||||||
if '.db' in f:
|
|
||||||
continue
|
|
||||||
ts = int(f.split('.')[0].split('_')[3])
|
|
||||||
if ts >= self.startDate and ts <= self.endDate:
|
|
||||||
with open(f"{STAT_DIR}/{f}") as fh:
|
|
||||||
datas = fh.readlines()
|
|
||||||
for line in datas:
|
|
||||||
if line.split(';')[0].lower() in STATS_TOT_FIELDS:
|
|
||||||
key = line.split(';')[0].lower()
|
|
||||||
value = int(line.split(';')[1])
|
|
||||||
if key in self.consolided_datas:
|
|
||||||
datas = self.consolided_datas[key]
|
|
||||||
if datas[0] <= 0:
|
|
||||||
self.consolided_datas[key][0] = value
|
|
||||||
else:
|
|
||||||
if value > datas[1]:
|
|
||||||
self.consolided_datas[key][1] = value
|
|
||||||
else:
|
|
||||||
self.consolided_datas[key] = [value,0]
|
|
||||||
|
|
||||||
if line.split(';')[0].lower() in STATS_AVG_FIELDS:
|
|
||||||
key = line.split(';')[0].lower()
|
|
||||||
value = int(line.split(';')[1])
|
|
||||||
if key in self.consolided:
|
|
||||||
if self.consolided[key] < int(value):
|
|
||||||
self.consolided[key] = int(value)
|
|
||||||
else:
|
|
||||||
self.consolided[key] = 0
|
|
||||||
|
|
||||||
for (k,v) in self.consolided_datas.items():
|
|
||||||
self.consolided[k] = v[1] - v[0]
|
|
||||||
if 'byte' in k:
|
|
||||||
octets,unit = self.__conv(self.consolided[k])
|
|
||||||
self.consolided[k] = f"{octets} {unit}"
|
|
||||||
elif 'seconds' in k:
|
|
||||||
octets,unit = self.__conv(self.consolided[k],'t')
|
|
||||||
self.consolided[k] = f"{octets} {unit}"
|
|
||||||
return self.consolided
|
|
||||||
|
|
||||||
class SQLite:
|
class SQLite:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -165,8 +120,7 @@ class SQLite:
|
|||||||
timestamp text,
|
timestamp text,
|
||||||
key_field text,
|
key_field text,
|
||||||
value_field text
|
value_field text
|
||||||
)
|
)''')
|
||||||
''')
|
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
self.__closeDb()
|
self.__closeDb()
|
||||||
|
|
||||||
@ -216,7 +170,7 @@ def runMain():
|
|||||||
year = currentDate.year
|
year = currentDate.year
|
||||||
|
|
||||||
stats = Stats(year,mois)
|
stats = Stats(year,mois)
|
||||||
res = stats.parse2()
|
res = stats.parse()
|
||||||
for (k,v) in res.items():
|
for (k,v) in res.items():
|
||||||
print(f"{k}={v}")
|
print(f"{k}={v}")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user