Generate Monthly is faster

This commit is contained in:
Mickael 2019-09-04 17:48:57 +02:00
parent 80bf0769ac
commit b4b664cb45

View file

@ -14,7 +14,13 @@ from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save from common.savehelper import save
from common.charthelper import createElement, getColor, setTsunamyInfo, Tsunami, getTsunamy from common.charthelper import createElement, getColor, setTsunamyInfo, Tsunami, getTsunamy
begin = datetime.now()
end = datetime.now()
def main(): def main():
global begin, end
rocket = Connection() rocket = Connection()
labels = [None] * 12 labels = [None] * 12
@ -56,6 +62,8 @@ def main():
begin = date - monthdelta(12) begin = date - monthdelta(12)
end = begin + monthdelta(1) end = begin + monthdelta(1)
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs'])
tsunamy = getTsunamy(channel) tsunamy = getTsunamy(channel)
for id in range(0, 12): for id in range(0, 12):
@ -63,11 +71,8 @@ def main():
uniqueUserGlobal[id] = [] uniqueUserGlobal[id] = []
labels[id] = begin.strftime("%b %Y") labels[id] = begin.strftime("%b %Y")
print(f"\t{labels[id]}") print(f"\t{labels[id]}")
begindate = begin.isoformat()
enddate = end.isoformat() resultMess = list(filter(lambda mess: begin < datetime.strptime(mess["ts"], "%Y-%m-%dT%H:%M:%S.%fZ") < end, messages))
resultMess = getAllMessages(rocket, channel['_id'], begindate= begindate, enddate=enddate)
resultMess = list(filter(lambda mess: 't' not in mess, resultMess))
length = len(resultMess) length = len(resultMess)
dataMess.append(length) dataMess.append(length)