Fix generation of stats

This commit is contained in:
Mickael 2020-01-01 19:52:21 +01:00
parent b332c584a1
commit 06599a037f
3 changed files with 50 additions and 13 deletions

View file

@ -16,11 +16,19 @@ def createElement(label, color, data):
"data": data "data": data
} }
def setTopicsInfo(topics, messagesDataTopic, id, length): def setTopicsInfo(topics, messagesDataTopic, id, length):
for topic in topics: for topic in topics:
if topic not in messagesDataTopic: result = None
messagesDataTopic[topic] = [0] * 30 if len(messagesDataTopic) > 0:
messagesDataTopic[topic][id] += length result = next((x for x in messagesDataTopic if x['label'] == topic), None)
if result is None:
result = createElement(topic, getColor(), [0] * 30)
messagesDataTopic.append(result)
result['data'][id] += length
def getTopics(channel): def getTopics(channel):
if 'description' in channel: if 'description' in channel:
@ -30,5 +38,6 @@ def getTopics(channel):
return topics return topics
return ['global'] return ['global']
if __name__ == "__main__": if __name__ == "__main__":
print("not executable") print("not executable")

View file

@ -8,6 +8,7 @@ from rocketchat_API.rocketchat import RocketChat
import json import json
import os import os
import random import random
import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from common.rocketchathelper import getAllChannels, getAllMessages, Connection from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save from common.savehelper import save
@ -25,7 +26,7 @@ def main():
labels = [None] * nbElements labels = [None] * nbElements
messagesByChannel = [] messagesByChannel = []
usersByChannel = [] usersByChannel = []
messagesByTopic = {} messagesByTopic = []
usersGlobal = [] usersGlobal = []
now = datetime.now() now = datetime.now()
@ -42,7 +43,14 @@ def main():
uniqueUserGlobal = [None] * nbElements uniqueUserGlobal = [None] * nbElements
for channel in getAllChannels(rocket): waittest = 0
idChannel = 0
channels = getAllChannels(rocket)
for channel in channels:
idChannel += 1
if channel['name'].startswith("cohorte"):
continue
dataMess = [] dataMess = []
dataUsers = [] dataUsers = []
print( channel['name'] ) print( channel['name'] )
@ -52,6 +60,10 @@ def main():
topics = getTopics(channel) topics = getTopics(channel)
print(topics) print(topics)
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate= end, count= channel["msgs"]) messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate= end, count= channel["msgs"])
if messages is None:
print("ERROR to get messages")
break
end = begin + timedelta(1) end = begin + timedelta(1)
for id in range(0, nbElements): for id in range(0, nbElements):
@ -60,9 +72,6 @@ def main():
labels[id] = begin.strftime("%x") labels[id] = begin.strftime("%x")
print("\t{0}".format(labels[id])) print("\t{0}".format(labels[id]))
if messages is None:
continue
resultMess = list(filter(filter_message, messages)) resultMess = list(filter(filter_message, messages))
length = len(resultMess) length = len(resultMess)
dataMess.append(length) dataMess.append(length)
@ -88,6 +97,12 @@ def main():
messagesByChannel.append(messageByChannel) messagesByChannel.append(messageByChannel)
usersByChannel.append(userByChannel) usersByChannel.append(userByChannel)
waittest += 1
if waittest >= 5:
waittest = 0
print("Wait {}/{}".format(idChannel, len(channels)))
time.sleep(30)
for id in range(0, nbElements): for id in range(0, nbElements):
uniqueUserGlobal[id] = len(set(uniqueUserGlobal[id])) uniqueUserGlobal[id] = len(set(uniqueUserGlobal[id]))

View file

@ -8,6 +8,7 @@ from rocketchat_API.rocketchat import RocketChat
import json import json
import os import os
import random import random
import time
from datetime import datetime from datetime import datetime
from monthdelta import monthdelta from monthdelta import monthdelta
from common.rocketchathelper import getAllChannels, getAllMessages, Connection from common.rocketchathelper import getAllChannels, getAllMessages, Connection
@ -26,7 +27,7 @@ def main():
labels = [None] * 12 labels = [None] * 12
messagesByChannel = [] messagesByChannel = []
usersByChannel = [] usersByChannel = []
messagesByTopic = {} messagesByTopic = []
usersGlobal = [] usersGlobal = []
now = datetime.now() now = datetime.now()
@ -43,7 +44,14 @@ def main():
uniqueUserGlobal = [None] * 12 uniqueUserGlobal = [None] * 12
for channel in getAllChannels(rocket): waittest = 0
idChannel = 0
channels = getAllChannels(rocket)
for channel in channels:
idChannel += 1
if channel['name'].startswith("cohorte"):
continue
dataMess = [] dataMess = []
dataUsers = [] dataUsers = []
print( channel['name'] ) print( channel['name'] )
@ -51,6 +59,9 @@ def main():
end = begin + monthdelta(1) end = begin + monthdelta(1)
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs']) messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs'])
if messages is None:
print("ERROR to get messages")
break
topics = getTopics(channel) topics = getTopics(channel)
print(topics) print(topics)
@ -60,9 +71,6 @@ def main():
labels[id] = begin.strftime("%b %Y") labels[id] = begin.strftime("%b %Y")
print("\t{0}".format(labels[id])) print("\t{0}".format(labels[id]))
if messages is None:
continue
resultMess = list(filter(lambda mess: begin < datetime.strptime(mess["ts"], "%Y-%m-%dT%H:%M:%S.%fZ") < end, messages)) resultMess = list(filter(lambda mess: begin < datetime.strptime(mess["ts"], "%Y-%m-%dT%H:%M:%S.%fZ") < end, messages))
length = len(resultMess) length = len(resultMess)
dataMess.append(length) dataMess.append(length)
@ -88,6 +96,11 @@ def main():
messagesByChannel.append(messageByChannel) messagesByChannel.append(messageByChannel)
usersByChannel.append(userByChannel) usersByChannel.append(userByChannel)
waittest += 1
if waittest >= 5:
print("Wait {}/{}".format(idChannel, len(channels)))
waittest = 0
time.sleep(30)
for id in range(0, 12): for id in range(0, 12):
uniqueUserGlobal[id] = len(set(uniqueUserGlobal[id])) uniqueUserGlobal[id] = len(set(uniqueUserGlobal[id]))