Add new stats to know active user

This commit is contained in:
Mickael 2019-06-27 21:19:19 +02:00
parent 50945b0068
commit 70c37f49c0
3 changed files with 57 additions and 5 deletions

View file

@ -13,6 +13,7 @@ Statistiques du <a href="https://coa.crapaud-fou.org">chat</a> (aussi connu sous
<canvas id="byChannel"></canvas>
<canvas id="byTsunamy"></canvas>
<canvas id="usersByChannel"></canvas>
<canvas id="usersGlobal"></canvas>
<script>
$.getJSON("{{ site.baseurl }}/public/data/channelsstat.json", function (datas){
@ -127,5 +128,41 @@ $.getJSON("{{ site.baseurl }}/public/data/channelsstat.json", function (datas){
}
}
});
var ctx4 = document.getElementById('usersGlobal').getContext('2d');
var chart4 = new Chart(ctx4, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: labels,
datasets: datas['usersGlobal'],
},
// Configuration options go here
options: {
legend: {
display: false
},
title: {
display: true,
text: "Nombre d'utilisateur actifs (" + 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

@ -34,6 +34,7 @@ messagesDataTsunamy = {
"ecology": [0] * 12,
"technology": [0] * 12,
}
usersGlobal = []
now = datetime.now()
date = datetime(now.year, now.month, now.day, 0,0,0)
@ -67,9 +68,12 @@ info = {
"label": "technologie",
"backgroundColor": getColor(),
"data": messagesDataTsunamy['technology']
}]
}],
"usersGlobal": usersGlobal
}
usersTest = [None] * 12
while True:
channels = rocket.channels_list(offset=index).json()
totalChannels = channels['total']
@ -84,6 +88,8 @@ while True:
tsunamy = getTsunamy(channel)
for id in range(0, 12):
if usersTest[id] == None:
usersTest[id] = []
labels[id] = begin.strftime("%b %Y")
begindate = begin.isoformat()
enddate = end.isoformat()
@ -107,6 +113,7 @@ while True:
users = []
for mess in resultMess:
users.append(mess['u']['_id'])
usersTest[id].append(mess['u']['_id'])
usersDistinct = set(users)
dataUsers.append(len(usersDistinct))
else:
@ -135,13 +142,21 @@ while True:
break
index += channels['count']
for id in range(0, 12):
usersTest[id] = len(set(usersTest[id]))
userGlobal = {
"label": 'global',
"backgroundColor": 'red',
"data": usersTest
}
usersGlobal.append(userGlobal)
# 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, 'channelsstat.json'))
with open(statsFilePath, "w") as file_write: