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
script/dev.config.py
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="usersByChannel"></canvas>
<script>
updated = "updated 02/05/2019"
$.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){
updated = datas['updated']
labels = datas['labels'];
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){
@ -96,40 +132,5 @@ $.getJSON("{{ site.baseurl }}/public/data/messagesByTsunami.json", function (dat
});
$.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>

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
labels = [None] * 12
messagesByChannel = []
usersByChannel = []
now = datetime.now()
date = datetime(now.year, now.month, now.day, 0,0,0)
@ -32,26 +33,45 @@ while True:
totalChannels = channels['total']
for channel in channels['channels']:
data = []
dataMess = []
dataUsers = []
pprint( channel['name'] )
begin = date - monthdelta(12)
end = begin + monthdelta(1)
users = []
for id in range(0, 12):
labels[id] = begin.strftime("%b %Y")
begindate = begin.isoformat()
enddate = end.isoformat()
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
end = begin + monthdelta(1)
messageByChannel = {
"label": channel['name'],
"backgroundColor": getColor(),
"data": data
"data": dataMess
}
userByChannel = {
"label": channel['name'],
"backgroundColor": getColor(),
"data": dataUsers
}
messagesByChannel.append(messageByChannel)
usersByChannel.append(userByChannel)
if channels['count'] + channels['offset'] >= channels['total']:
break
@ -63,8 +83,10 @@ rootFolder = os.path.join(os.path.dirname(__file__), '..')
dataFolder = os.path.join(rootFolder, 'public', 'data')
info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels,
"messagesByChannel": messagesByChannel
"messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel
}
statsFilePath = os.path.abspath(