Accelerate daily stat

This commit is contained in:
Mickael 2019-09-03 21:21:07 +02:00 committed by Mickael
parent 720bce3a85
commit e2b75d6cc5
1 changed files with 25 additions and 6 deletions

View File

@ -13,10 +13,15 @@ from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save
from common.charthelper import createElement, getColor, setTsunamyInfo, getTsunamy, Tsunami
begin = datetime.now()
end = datetime.now()
def main():
rocket = Connection()
nbElements = 30
global begin, end
labels = [None] * nbElements
messagesByChannel = []
usersByChannel = []
@ -54,20 +59,20 @@ def main():
dataUsers = []
print( channel['name'] )
begin = date - timedelta(nbElements)
end = begin + timedelta(1)
end = begin + timedelta(nbElements)
tsunamy = getTsunamy(channel)
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate= end)
end = begin + timedelta(1)
for id in range(0, nbElements):
if uniqueUserGlobal[id] == None:
uniqueUserGlobal[id] = []
labels[id] = begin.strftime("%x")
print(f"\t{labels[id]}")
begindate = begin.isoformat()
enddate = end.isoformat()
resultMess = getAllMessages(rocket, channel['_id'], begindate= begindate, enddate=enddate)
resultMess = list(filter(lambda mess: 't' not in mess, resultMess))
resultMess = list(filter(filter_message, messages))
length = len(resultMess)
dataMess.append(length)
@ -101,5 +106,19 @@ def main():
save(info, "chat_stat_daily")
def filter_message(mess):
if 't' in mess:
return False
date = datetime.strptime(mess["ts"], "%Y-%m-%dT%H:%M:%S.%fZ")
if date < begin:
return False
if end < date:
return False
return True
if __name__ == "__main__":
main()