Add scripts to generate stats
This commit is contained in:
parent
ed92623bd7
commit
a1825bbf10
5 changed files with 72 additions and 4 deletions
|
@ -14,8 +14,8 @@ Statistiques du <a href="https://coa.crapaud-fou.org">chat</a> (aussi connu sous
|
||||||
<canvas id="byTsunamy"></canvas>
|
<canvas id="byTsunamy"></canvas>
|
||||||
<canvas id="usersByChannel"></canvas>
|
<canvas id="usersByChannel"></canvas>
|
||||||
<script>
|
<script>
|
||||||
updated = "updated 02/05/2019"
|
updated = "updated 02/05/2019"
|
||||||
labels = ["mai 2018","juin 2018","juillet 2018","août 2018","septembre 2018","octobre 2018","novembre 2018","décembre 2018","janvier 2019","février 2019","mars 2019","avril 2019",];
|
labels = ["mai 2018","juin 2018","juillet 2018","août 2018","septembre 2018","octobre 2018","novembre 2018","décembre 2018","janvier 2019","février 2019","mars 2019","avril 2019"];
|
||||||
|
|
||||||
$.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){
|
$.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){
|
||||||
var ctx = document.getElementById('byChannel').getContext('2d');
|
var ctx = document.getElementById('byChannel').getContext('2d');
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
67
script/getstats.py
Normal file
67
script/getstats.py
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# 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 dev_config as cfg
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
from monthdelta import monthdelta
|
||||||
|
|
||||||
|
def getColor():
|
||||||
|
r = random.randrange(255)
|
||||||
|
g = random.randrange(255)
|
||||||
|
b = random.randrange(255)
|
||||||
|
return 'rgb({:0},{:0},{:0})'.format(r,g,b)
|
||||||
|
|
||||||
|
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
|
||||||
|
server_url='https://coa.crapaud-fou.org')
|
||||||
|
index = 0
|
||||||
|
messagesByChannel = []
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
|
date = datetime(now.year, now.month, now.day, 0,0,0)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
channels = rocket.channels_list(offset=index).json()
|
||||||
|
totalChannels = channels['total']
|
||||||
|
|
||||||
|
for channel in channels['channels']:
|
||||||
|
data = []
|
||||||
|
pprint( channel['name'] )
|
||||||
|
begin = date - monthdelta(12)
|
||||||
|
end = begin + monthdelta(1)
|
||||||
|
for id in range(0, 12):
|
||||||
|
begindate = begin.isoformat()
|
||||||
|
enddate = end.isoformat()
|
||||||
|
resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json()
|
||||||
|
data.append(len(resultMess['messages']))
|
||||||
|
begin = end
|
||||||
|
end = begin + monthdelta(1)
|
||||||
|
|
||||||
|
messageByChannel = {
|
||||||
|
"label": channel['name'],
|
||||||
|
"backgroundColor": getColor(),
|
||||||
|
"data": data
|
||||||
|
}
|
||||||
|
|
||||||
|
messagesByChannel.append(messageByChannel)
|
||||||
|
|
||||||
|
if channels['count'] + channels['offset'] >= channels['total']:
|
||||||
|
break
|
||||||
|
index += channels['count']
|
||||||
|
|
||||||
|
# Récupération du répertoire racine du repo
|
||||||
|
rootFolder = os.path.join(os.path.dirname(__file__), '..')
|
||||||
|
# Répertoire pour stocker le fichier de sortie
|
||||||
|
dataFolder = os.path.join(rootFolder, 'public', 'data')
|
||||||
|
|
||||||
|
statsFilePath = os.path.abspath(
|
||||||
|
os.path.join(dataFolder, 'messagesByChannel.json'))
|
||||||
|
with open(statsFilePath, "w") as file_write:
|
||||||
|
json.dump(messagesByChannel, file_write)
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
rocketchat_API==0.6.32
|
rocketchat_API==0.6.32
|
||||||
|
MonthDelta==0.9.1
|
Loading…
Reference in a new issue