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="byChannel"></canvas>
<canvas id="byTsunamy"></canvas> <canvas id="byTsunamy"></canvas>
<canvas id="usersByChannel"></canvas> <canvas id="usersByChannel"></canvas>
<canvas id="usersGlobal"></canvas>
<script> <script>
$.getJSON("{{ site.baseurl }}/public/data/channelsstat.json", function (datas){ $.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> </script>

File diff suppressed because one or more lines are too long

View file

@ -34,6 +34,7 @@ messagesDataTsunamy = {
"ecology": [0] * 12, "ecology": [0] * 12,
"technology": [0] * 12, "technology": [0] * 12,
} }
usersGlobal = []
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)
@ -67,9 +68,12 @@ info = {
"label": "technologie", "label": "technologie",
"backgroundColor": getColor(), "backgroundColor": getColor(),
"data": messagesDataTsunamy['technology'] "data": messagesDataTsunamy['technology']
}] }],
"usersGlobal": usersGlobal
} }
usersTest = [None] * 12
while True: while True:
channels = rocket.channels_list(offset=index).json() channels = rocket.channels_list(offset=index).json()
totalChannels = channels['total'] totalChannels = channels['total']
@ -84,6 +88,8 @@ while True:
tsunamy = getTsunamy(channel) tsunamy = getTsunamy(channel)
for id in range(0, 12): for id in range(0, 12):
if usersTest[id] == None:
usersTest[id] = []
labels[id] = begin.strftime("%b %Y") labels[id] = begin.strftime("%b %Y")
begindate = begin.isoformat() begindate = begin.isoformat()
enddate = end.isoformat() enddate = end.isoformat()
@ -106,7 +112,8 @@ while True:
users = [] users = []
for mess in resultMess: for mess in resultMess:
users.append(mess['u']['_id']) users.append(mess['u']['_id'])
usersTest[id].append(mess['u']['_id'])
usersDistinct = set(users) usersDistinct = set(users)
dataUsers.append(len(usersDistinct)) dataUsers.append(len(usersDistinct))
else: else:
@ -135,13 +142,21 @@ while True:
break break
index += channels['count'] 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 # Récupération du répertoire racine du repo
rootFolder = os.path.join(os.path.dirname(__file__), '..') rootFolder = os.path.join(os.path.dirname(__file__), '..')
# Répertoire pour stocker le fichier de sortie # Répertoire pour stocker le fichier de sortie
dataFolder = os.path.join(rootFolder, 'public', 'data') dataFolder = os.path.join(rootFolder, 'public', 'data')
statsFilePath = os.path.abspath( statsFilePath = os.path.abspath(
os.path.join(dataFolder, 'channelsstat.json')) os.path.join(dataFolder, 'channelsstat.json'))
with open(statsFilePath, "w") as file_write: with open(statsFilePath, "w") as file_write: