Add unique users by channels

This commit is contained in:
Mickael 2019-06-08 23:21:30 +02:00
parent d0d161ab08
commit 2473e8af21
4 changed files with 67 additions and 42 deletions

2
.gitignore vendored
View file

@ -6,3 +6,5 @@ vendor/
.bundle .bundle
script/dev.config.py script/dev.config.py
script/__pycache__/*.pyc script/__pycache__/*.pyc
\.vscode/\.ropeproject/

View file

@ -14,10 +14,10 @@ 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"
$.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){ $.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){
updated = datas['updated']
labels = datas['labels']; labels = datas['labels'];
var ctx = document.getElementById('byChannel').getContext('2d'); var ctx = document.getElementById('byChannel').getContext('2d');
@ -55,6 +55,42 @@ $.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (dat
} }
} }
}); });
var ctx3 = document.getElementById('usersByChannel').getContext('2d');
var chart3 = new Chart(ctx3, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: labels,
datasets: datas['usersByChannel'],
},
// Configuration options go here
options: {
legend: {
display: false
},
title: {
display: true,
text: "Nombre d'utilisateur actifs par canaux (" + updated + ")",
position: "top"
},
responsive: true,
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true,
ticks: {
stepSize: 50
}
}]
}
}
});
}); });
$.getJSON("{{ site.baseurl }}/public/data/messagesByTsunami.json", function (datas){ $.getJSON("{{ site.baseurl }}/public/data/messagesByTsunami.json", function (datas){
@ -96,40 +132,5 @@ $.getJSON("{{ site.baseurl }}/public/data/messagesByTsunami.json", function (dat
}); });
$.getJSON("{{ site.baseurl }}/public/data/activeUsersByChannel.json", function (datas){ $.getJSON("{{ site.baseurl }}/public/data/activeUsersByChannel.json", function (datas){
var ctx3 = document.getElementById('usersByChannel').getContext('2d');
var chart3 = new Chart(ctx3, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: labels,
datasets: datas,
},
// Configuration options go here
options: {
legend: {
display: false
},
title: {
display: true,
text: "Nombre d'utilisateur actifs par canaux (" + updated + ")",
position: "top"
},
responsive: true,
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true,
ticks: {
stepSize: 50
}
}]
}
}
});
}); });
</script> </script>

File diff suppressed because one or more lines are too long

View file

@ -23,6 +23,7 @@ rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
index = 0 index = 0
labels = [None] * 12 labels = [None] * 12
messagesByChannel = [] messagesByChannel = []
usersByChannel = []
now = datetime.now() now = datetime.now()
date = datetime(now.year, now.month, now.day, 0,0,0) date = datetime(now.year, now.month, now.day, 0,0,0)
@ -32,26 +33,45 @@ while True:
totalChannels = channels['total'] totalChannels = channels['total']
for channel in channels['channels']: for channel in channels['channels']:
data = [] dataMess = []
dataUsers = []
pprint( channel['name'] ) pprint( channel['name'] )
begin = date - monthdelta(12) begin = date - monthdelta(12)
end = begin + monthdelta(1) end = begin + monthdelta(1)
users = []
for id in range(0, 12): for id in range(0, 12):
labels[id] = begin.strftime("%b %Y") labels[id] = begin.strftime("%b %Y")
begindate = begin.isoformat() begindate = begin.isoformat()
enddate = end.isoformat() enddate = end.isoformat()
resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json() resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json()
data.append(len(resultMess['messages'])) lenght = len(resultMess['messages'])
dataMess.append(lenght)
if lenght > 0:
for mess in resultMess['messages']:
users.append(mess['u']['_id'])
usersDistinct = set(users)
dataUsers.append(len(usersDistinct))
else:
dataUsers.append(0)
begin = end begin = end
end = begin + monthdelta(1) end = begin + monthdelta(1)
messageByChannel = { messageByChannel = {
"label": channel['name'], "label": channel['name'],
"backgroundColor": getColor(), "backgroundColor": getColor(),
"data": data "data": dataMess
}
userByChannel = {
"label": channel['name'],
"backgroundColor": getColor(),
"data": dataUsers
} }
messagesByChannel.append(messageByChannel) messagesByChannel.append(messageByChannel)
usersByChannel.append(userByChannel)
if channels['count'] + channels['offset'] >= channels['total']: if channels['count'] + channels['offset'] >= channels['total']:
break break
@ -63,8 +83,10 @@ rootFolder = os.path.join(os.path.dirname(__file__), '..')
dataFolder = os.path.join(rootFolder, 'public', 'data') dataFolder = os.path.join(rootFolder, 'public', 'data')
info = { info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels, "labels": labels,
"messagesByChannel": messagesByChannel "messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel
} }
statsFilePath = os.path.abspath( statsFilePath = os.path.abspath(