various small adjustments, renaming tsunamis by topics because we gonna extend it to the categories at some point

This commit is contained in:
mose 2019-09-05 06:52:47 +08:00
parent 24016d2f2a
commit e8dc51b0ce
8 changed files with 124 additions and 120 deletions

View file

@ -13,32 +13,32 @@ def createElement(label, color, data) :
"data": data
}
def setTsunamyInfo(tsunamy, messagesDataTsunamy, id, length):
if tsunamy & Tsunami.GLOBAL:
messagesDataTsunamy[Tsunami.GLOBAL][id] += length
if tsunamy & Tsunami.PROJECT:
messagesDataTsunamy[Tsunami.PROJECT][id] += length
if tsunamy & Tsunami.DEMOCRACY:
messagesDataTsunamy[Tsunami.DEMOCRACY][id] += length
if tsunamy & Tsunami.ECOLOGY:
messagesDataTsunamy[Tsunami.ECOLOGY][id] += length
if tsunamy & Tsunami.TECHNOLOGY:
messagesDataTsunamy[Tsunami.TECHNOLOGY][id] += length
def setTopicInfo(tsunamy, messagesDataTopic, id, length):
if tsunamy & Topics.GLOBAL:
messagesDataTopic[Topics.GLOBAL][id] += length
if tsunamy & Topics.PROJECT:
messagesDataTopic[Topics.PROJECT][id] += length
if tsunamy & Topics.DEMOCRACY:
messagesDataTopic[Topics.DEMOCRACY][id] += length
if tsunamy & Topics.ECOLOGY:
messagesDataTopic[Topics.ECOLOGY][id] += length
if tsunamy & Topics.TECHNOLOGY:
messagesDataTopic[Topics.TECHNOLOGY][id] += length
def getTsunamy(channel):
value = Tsunami.GLOBAL
def getTopic(channel):
value = Topics.GLOBAL
if 'description' in channel:
if channel['description'].find("#projet") != -1:
value |= Tsunami.PROJECT
value |= Topics.PROJECT
if channel['description'].find("#democratie") != -1:
value |= Tsunami.DEMOCRACY
value |= Topics.DEMOCRACY
if channel['description'].find("#ecologie") != -1:
value |= Tsunami.ECOLOGY
value |= Topics.ECOLOGY
if channel['description'].find("#technologie") != -1:
value |= Tsunami.TECHNOLOGY
value |= Topics.TECHNOLOGY
return value
class Tsunami:
class Topics:
GLOBAL = 1 << 0
PROJECT = 1 << 1
DEMOCRACY = 1 << 2

View file

@ -11,7 +11,7 @@ import random
from datetime import datetime, timedelta
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save
from common.charthelper import createElement, getColor, setTsunamyInfo, getTsunamy, Tsunami
from common.charthelper import createElement, getColor, setTopicInfo, getTopic, Topics
begin = datetime.now()
end = datetime.now()
@ -25,12 +25,12 @@ def main():
labels = [None] * nbElements
messagesByChannel = []
usersByChannel = []
messagesDataTsunamy = {
Tsunami.GLOBAL: [0] * nbElements,
Tsunami.PROJECT: [0] * nbElements,
Tsunami.DEMOCRACY: [0] * nbElements,
Tsunami.ECOLOGY: [0] * nbElements,
Tsunami.TECHNOLOGY: [0] * nbElements,
messagesDataTopic = {
Topics.GLOBAL: [0] * nbElements,
Topics.PROJECT: [0] * nbElements,
Topics.DEMOCRACY: [0] * nbElements,
Topics.ECOLOGY: [0] * nbElements,
Topics.TECHNOLOGY: [0] * nbElements,
}
usersGlobal = []
@ -38,16 +38,16 @@ def main():
date = datetime(now.year, now.month, now.day, 0,0,0)
info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"updated": "{:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels,
"messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel,
"messagesByTsunamy": [
createElement("global", getColor(), messagesDataTsunamy[Tsunami.GLOBAL]),
createElement("project", getColor(), messagesDataTsunamy[Tsunami.PROJECT]),
createElement("democratie", getColor(), messagesDataTsunamy[Tsunami.DEMOCRACY]),
createElement("ecologie", getColor(), messagesDataTsunamy[Tsunami.ECOLOGY]),
createElement("technologie", getColor(), messagesDataTsunamy[Tsunami.TECHNOLOGY])
"messagesByTopic": [
createElement("global", getColor(), messagesDataTopic[Topics.GLOBAL]),
createElement("project", getColor(), messagesDataTopic[Topics.PROJECT]),
createElement("democratie", getColor(), messagesDataTopic[Topics.DEMOCRACY]),
createElement("ecologie", getColor(), messagesDataTopic[Topics.ECOLOGY]),
createElement("technologie", getColor(), messagesDataTopic[Topics.TECHNOLOGY])
],
"usersGlobal": usersGlobal
}
@ -61,7 +61,7 @@ def main():
begin = date - timedelta(nbElements)
end = begin + timedelta(nbElements)
tsunamy = getTsunamy(channel)
tsunamy = getTopic(channel)
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate= end, count= channel["msgs"])
end = begin + timedelta(1)
@ -77,7 +77,7 @@ def main():
dataMess.append(length)
if length > 0:
setTsunamyInfo(tsunamy, messagesDataTsunamy, id, length)
setTopicInfo(tsunamy, messagesDataTopic, id, length)
users = []
for mess in resultMess:

View file

@ -12,7 +12,7 @@ from datetime import datetime
from monthdelta import monthdelta
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
from common.savehelper import save
from common.charthelper import createElement, getColor, setTsunamyInfo, Tsunami, getTsunamy
from common.charthelper import createElement, getColor, setTopicInfo, Topics, getTopic
begin = datetime.now()
end = datetime.now()
@ -26,12 +26,12 @@ def main():
labels = [None] * 12
messagesByChannel = []
usersByChannel = []
messagesDataTsunamy = {
Tsunami.GLOBAL: [0] * 12,
Tsunami.PROJECT: [0] * 12,
Tsunami.DEMOCRACY: [0] * 12,
Tsunami.ECOLOGY: [0] * 12,
Tsunami.TECHNOLOGY: [0] * 12,
messagesDataTopic = {
Topics.GLOBAL: [0] * 12,
Topics.PROJECT: [0] * 12,
Topics.DEMOCRACY: [0] * 12,
Topics.ECOLOGY: [0] * 12,
Topics.TECHNOLOGY: [0] * 12,
}
usersGlobal = []
@ -39,16 +39,16 @@ def main():
date = datetime(now.year, now.month, now.day, 0,0,0)
info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"updated": "{:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels,
"messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel,
"messagesByTsunamy": [
createElement("global", getColor(), messagesDataTsunamy[Tsunami.GLOBAL]),
createElement("project", getColor(), messagesDataTsunamy[Tsunami.PROJECT]),
createElement("democratie", getColor(), messagesDataTsunamy[Tsunami.DEMOCRACY]),
createElement("ecologie", getColor(), messagesDataTsunamy[Tsunami.ECOLOGY]),
createElement("technologie", getColor(), messagesDataTsunamy[Tsunami.TECHNOLOGY])
"messagesByTopic": [
createElement("global", getColor(), messagesDataTopic[Topics.GLOBAL]),
createElement("project", getColor(), messagesDataTopic[Topics.PROJECT]),
createElement("democratie", getColor(), messagesDataTopic[Topics.DEMOCRACY]),
createElement("ecologie", getColor(), messagesDataTopic[Topics.ECOLOGY]),
createElement("technologie", getColor(), messagesDataTopic[Topics.TECHNOLOGY])
],
"usersGlobal": usersGlobal
}
@ -64,7 +64,7 @@ def main():
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs'])
tsunamy = getTsunamy(channel)
tsunamy = getTopic(channel)
for id in range(0, 12):
if uniqueUserGlobal[id] == None:
@ -77,7 +77,7 @@ def main():
dataMess.append(length)
if length > 0:
setTsunamyInfo(tsunamy, messagesDataTsunamy, id, length)
setTopicInfo(tsunamy, messagesDataTopic, id, length)
users = []
for mess in resultMess:

View file

@ -56,7 +56,7 @@
<div class="row">
<div class="col">
<a href="/"><img src="images/crapovecto_small.svg" height="100" class="float-left logo" /></a>
<a href="index.html"><img src="images/crapovecto_small.svg" height="100" class="float-left logo" /></a>
</div>
</div>
@ -67,11 +67,11 @@
<div class="row">
<div class="col">
<canvas id="byChannel"></canvas>
<canvas id="byTsunamy"></canvas>
<canvas id="byTopic"></canvas>
<canvas id="usersByChannel"></canvas>
<canvas id="usersGlobal"></canvas>
<canvas id="byChannel_daily"></canvas>
<canvas id="byTsunamy_daily"></canvas>
<canvas id="byTopic_daily"></canvas>
<canvas id="usersByChannel_daily"></canvas>
<canvas id="usersGlobal_daily"></canvas>
</div>

View file

@ -1,20 +1,24 @@
$(document).ready(function () {
$.getJSON("data/chat_stat_monthly.json", function (data) {
updated = data.updated;
updated = "mise à jour " + data.updated;
labels = data.labels;
console.log(data);
graphDisplay($('#byChannel'), data.messagesByChannel, "Nombre de messages par canal sur 1 an (" + updated + ")");
graphDisplay($('#byTsunamy'), data.messagesByTsunamy, "Nombre de messages par Tsunami sur 1 an (" + updated + ")");
graphDisplay($('#byTopic'), data.messagesByTopic, "Nombre de messages par thème sur 1 an (" + updated + ")");
graphDisplay($("#usersByChannel"), data.usersByChannel, "Nombre d'utilisateurs actifs par canal sur 1 an (" + updated + ")");
graphDisplay($("#usersGlobal"), data.usersGlobal, "Nombre d'utilisateurs actifs sur 1 an (" + updated + ")");
});
$.getJSON("data/chat_stat_daily.json", function (data) {
updated = data.updated;
updated = "mise à jour " + data.updated;
labels = data.labels;
graphDisplay($('#byChannel_daily'), data.messagesByChannel, "Nombre de messages par canal sur 30 jours (" + updated + ")");
graphDisplay($('#byTsunamy_daily'), data.messagesByTsunamy, "Nombre de messages par Tsunami sur 30 jours (" + updated + ")");
graphDisplay($('#byTopic_daily'), data.messagesByTopic, "Nombre de messages par thème sur 30 jours (" + updated + ")");
graphDisplay($("#usersByChannel_daily"), data.usersByChannel, "Nombre d'utilisateurs actifs par canal sur 30 jours (" + updated + ")");
graphDisplay($("#usersGlobal_daily"), data.usersGlobal, "Nombre d'utilisateurs actifs sur 30 jours (" + updated + ")");
});
});
function graphDisplay(ctx, data, title) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "",
"short_name": "",
"name": "Les Crapauds fous",
"short_name": "Crapauds Fous",
"icons": [
{
"src": "android-chrome-192x192.png",