Add daily stats for chat

This commit is contained in:
Mickael 2019-09-02 21:36:59 +02:00
parent 2673fc3acf
commit af757691d0
4 changed files with 13633 additions and 4 deletions

View file

@ -0,0 +1,105 @@
# coding: utf8
# toutes les chaines sont en unicode (même les docstrings)
from __future__ import unicode_literals
# from pprint import pprint
from rocketchat_API.rocketchat import RocketChat
import json
import os
import random
from datetime import datetime, timedelta
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save
from common.charthelper import createElement, getColor, setTsunamyInfo, getTsunamy, Tsunami
def main():
rocket = Connection()
nbElements = 30
labels = [None] * nbElements
messagesByChannel = []
usersByChannel = []
messagesDataTsunamy = {
Tsunami.GLOBAL: [0] * nbElements,
Tsunami.PROJECT: [0] * nbElements,
Tsunami.DEMOCRACY: [0] * nbElements,
Tsunami.ECOLOGY: [0] * nbElements,
Tsunami.TECHNOLOGY: [0] * nbElements,
}
usersGlobal = []
now = datetime.now()
date = datetime(now.year, now.month, now.day, 0,0,0)
info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels,
"messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel,
"messagesByTsunamy": [
createElement("global", getColor(), messagesDataTsunamy[Tsunami.GLOBAL]),
createElement("project", getColor(), messagesDataTsunamy[Tsunami.PROJECT]),
createElement("democratie", getColor(), messagesDataTsunamy[Tsunami.DEMOCRACY]),
createElement("ecologie", getColor(), messagesDataTsunamy[Tsunami.ECOLOGY]),
createElement("technologie", getColor(), messagesDataTsunamy[Tsunami.TECHNOLOGY])
],
"usersGlobal": usersGlobal
}
uniqueUserGlobal = [None] * nbElements
for channel in getAllChannels(rocket):
dataMess = []
dataUsers = []
print( channel['name'] )
begin = date - timedelta(nbElements)
end = begin + timedelta(1)
tsunamy = getTsunamy(channel)
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))
length = len(resultMess)
dataMess.append(length)
if length > 0:
setTsunamyInfo(tsunamy, messagesDataTsunamy, id, length)
users = []
for mess in resultMess:
users.append(mess['u']['_id'])
uniqueUserGlobal[id].append(mess['u']['_id'])
usersDistinct = set(users)
dataUsers.append(len(usersDistinct))
else:
dataUsers.append(0)
begin = end
end = begin + timedelta(1)
color = getColor()
messageByChannel = createElement(channel['name'], color,dataMess)
userByChannel = createElement( channel['name'], color,dataUsers)
messagesByChannel.append(messageByChannel)
usersByChannel.append(userByChannel)
for id in range(0, nbElements):
uniqueUserGlobal[id] = len(set(uniqueUserGlobal[id]))
userGlobal = createElement( 'global', 'red', uniqueUserGlobal)
usersGlobal.append(userGlobal)
save(info, "chat_stat_daily")
if __name__ == "__main__":
main()

View file

@ -10,5 +10,9 @@
<canvas id="byTsunamy"></canvas>
<canvas id="usersByChannel"></canvas>
<canvas id="usersGlobal"></canvas>
<canvas id="byChannel_daily"></canvas>
<canvas id="byTsunamy_daily"></canvas>
<canvas id="usersByChannel_daily"></canvas>
<canvas id="usersGlobal_daily"></canvas>
</body>
</html>

View file

@ -4,13 +4,26 @@ $(document).ready(function () {
labels = datas['labels'];
graphDisplay($('#byChannel'), datas['messagesByChannel'], "Nombre de message par canaux (" + updated + ")");
graphDisplay($('#byChannel'), datas['messagesByChannel'], "Nombre de message par canaux sur 1 an (" + updated + ")");
graphDisplay($('#byTsunamy'), datas['messagesByTsunamy'], "Nombre de message par Tsunami (" + updated + ")");
graphDisplay($('#byTsunamy'), datas['messagesByTsunamy'], "Nombre de message par Tsunami sur 1 an (" + updated + ")");
graphDisplay($("#usersByChannel"), datas['usersByChannel'], "Nombre d'utilisateur actifs par canaux (" + updated + ")");
graphDisplay($("#usersByChannel"), datas['usersByChannel'], "Nombre d'utilisateur actifs par canaux sur 1 an (" + updated + ")");
graphDisplay($("#usersGlobal"), datas['usersGlobal'], "Nombre d'utilisateur actifs (" + updated + ")");
graphDisplay($("#usersGlobal"), datas['usersGlobal'], "Nombre d'utilisateur actifs sur 1 an (" + updated + ")");
});
$.getJSON("../../data/chat_stat_daily.json", function (datas) {
updated = datas['updated']
labels = datas['labels'];
graphDisplay($('#byChannel_daily'), datas['messagesByChannel'], "Nombre de message par canaux sur 30 jours (" + updated + ")");
graphDisplay($('#byTsunamy_daily'), datas['messagesByTsunamy'], "Nombre de message par Tsunami sur 30 jours (" + updated + ")");
graphDisplay($("#usersByChannel_daily"), datas['usersByChannel'], "Nombre d'utilisateur actifs par canaux sur 30 jours (" + updated + ")");
graphDisplay($("#usersGlobal_daily"), datas['usersGlobal'], "Nombre d'utilisateur actifs sur 30 jours (" + updated + ")");
});
});

13507
site/data/chat_stat_daily.json Normal file

File diff suppressed because it is too large Load diff