Add messages by tsunamy in script generation

This commit is contained in:
Mickael 2019-06-09 14:59:22 +02:00
parent e44dfd8990
commit c4146eb191
8 changed files with 5903 additions and 166 deletions

2
.gitignore vendored
View file

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

View file

@ -56,6 +56,42 @@ $.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (dat
} }
}); });
var ctx2 = document.getElementById('byTsunamy').getContext('2d');
var chart2 = new Chart(ctx2, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: labels,
datasets: datas['messagesByTsunamy'],
},
// Configuration options go here
options: {
legend: {
display: false
},
title: {
display: true,
text: "Nombre de message par Tsunami (" + updated + ")",
position: "top"
},
responsive: true,
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true,
ticks: {
stepSize: 500
}
}]
}
}
});
var ctx3 = document.getElementById('usersByChannel').getContext('2d'); var ctx3 = document.getElementById('usersByChannel').getContext('2d');
var chart3 = new Chart(ctx3, { var chart3 = new Chart(ctx3, {
// The type of chart we want to create // The type of chart we want to create
@ -92,45 +128,4 @@ $.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (dat
} }
}); });
}); });
$.getJSON("{{ site.baseurl }}/public/data/messagesByTsunami.json", function (datas){
var ctx2 = document.getElementById('byTsunamy').getContext('2d');
var chart2 = new Chart(ctx2, {
// 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 de message par Tsunami (" + updated + ")",
position: "top"
},
responsive: true,
scales: {
xAxes: [{
stacked: true
}],
yAxes: [{
stacked: true,
ticks: {
stepSize: 500
}
}]
}
}
});
});
$.getJSON("{{ site.baseurl }}/public/data/activeUsersByChannel.json", function (datas){
});
</script> </script>

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,92 +0,0 @@
[
{
"label": "Cohorte",
"backgroundColor": "rgb(147,49,67)",
"data": [
1063,
898,
340,
198,
170,
421,
357,
801,
689,
281,
496,
653
]
},
{
"label": "Democratie",
"backgroundColor": "rgb(204,154,254)",
"data": [
2278,
2133,
2475,
3056,
3253,
2490,
3161,
8463,
6675,
3330,
2608,
2204
]
},
{
"label": "Ecologie",
"backgroundColor": "rgb(251,203,43)",
"data": [
355,
935,
688,
1791,
2123,
1399,
1129,
616,
772,
947,
1397,
570
]
},
{
"label": "Technologie",
"backgroundColor": "rgb(229,184,170)",
"data": [
57,
2025,
549,
214,
442,
436,
708,
1680,
975,
835,
492,
1197
]
},
{
"label": "Global",
"backgroundColor": "rgb(37,122,28)",
"data": [
11628,
9083,
3933,
3825,
3978,
3877,
4509,
1600,
3467,
3848,
9191,
4581
]
}
]

View file

@ -0,0 +1,39 @@
def getNodesOrigin(channel):
nodes = []
if 'description' not in channel:
nodes.append("global")
return nodes
if channel['description'].find("#projet") != -1:
nodes.append("project")
if channel['description'].find("#democratie") != -1:
nodes.append("democratie")
if channel['description'].find("#ecologie") != -1:
nodes.append("ecologie")
if channel['description'].find("#technologie") != -1:
nodes.append("technologie")
if not nodes:
nodes.append("global")
return nodes
def getTsunamy(channel):
value = Tsunami.GLOBAL
if 'description' in channel:
if channel['description'].find("#projet") != -1:
value |= Tsunami.PROJECT
if channel['description'].find("#democratie") != -1:
value |= Tsunami.DEMOCRACY
if channel['description'].find("#ecologie") != -1:
value |= Tsunami.ECOLOGY
if channel['description'].find("#technologie") != -1:
value |= Tsunami.TECHNOLOGY
return value
class Tsunami:
GLOBAL = 1 << 0
PROJECT = 1 << 1
DEMOCRACY = 1 << 2
ECOLOGY = 1 << 3
TECHNOLOGY = 1 << 4

View file

@ -9,26 +9,7 @@ import json
import dev_config as cfg import dev_config as cfg
import os import os
import re import re
from common.channelhelper import getNodesOrigin
def getNodesOrigin(channel):
nodes = []
if 'description' not in channel:
nodes.append("global")
return nodes
if channel['description'].find("#projet") != -1:
nodes.append("project")
if channel['description'].find("#democratie") != -1:
nodes.append("democratie")
if channel['description'].find("#ecologie") != -1:
nodes.append("ecologie")
if channel['description'].find("#technologie") != -1:
nodes.append("technologie")
if not nodes:
nodes.append("global")
return nodes
colorInfo = { colorInfo = {
'global': 'orange', 'global': 'orange',
@ -73,7 +54,7 @@ while True:
for channel in channels['channels']: for channel in channels['channels']:
if channel['name'].find('cohorte') != -1: if channel['name'].find('cohorte') != -1:
if 'description' in channel: if 'description' in channel:
m = re.findall('#([\w-]+)', channel['description']) m = re.findall(r'#([\w-]+)', channel['description'])
for region in m: for region in m:
cohortescolor.update( { region: 'green' } ) cohortescolor.update( { region: 'green' } )
cohortes.update( { region: { 'link': channel['name']}}) cohortes.update( { region: { 'link': channel['name']}})

View file

@ -11,6 +11,8 @@ import os
import random import random
from datetime import datetime from datetime import datetime
from monthdelta import monthdelta from monthdelta import monthdelta
from common.channelhelper import getTsunamy
from common.channelhelper import Tsunami
def getColor(): def getColor():
r = random.randrange(255) r = random.randrange(255)
@ -23,11 +25,51 @@ rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
index = 0 index = 0
labels = [None] * 12 labels = [None] * 12
messagesByChannel = [] messagesByChannel = []
messagesByTsunamy = []
usersByChannel = [] usersByChannel = []
messagesDataTsunamy = {
"global": [0] * 12,
"project": [0] * 12,
"democraty": [0] * 12,
"ecology": [0] * 12,
"technology": [0] * 12,
}
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)
info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels,
"messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel,
"messagesByTsunamy": [{
"label": "global",
"backgroundColor": getColor(),
"data": messagesDataTsunamy['global']
},
{
"label": "projet",
"backgroundColor": getColor(),
"data": messagesDataTsunamy['project']
},
{
"label": "democratie",
"backgroundColor": getColor(),
"data": messagesDataTsunamy['democraty']
},
{
"label": "ecologie",
"backgroundColor": getColor(),
"data": messagesDataTsunamy['ecology']
},
{
"label": "technologie",
"backgroundColor": getColor(),
"data": messagesDataTsunamy['technology']
}]
}
while True: while True:
channels = rocket.channels_list(offset=index).json() channels = rocket.channels_list(offset=index).json()
totalChannels = channels['total'] totalChannels = channels['total']
@ -39,6 +81,8 @@ while True:
begin = date - monthdelta(12) begin = date - monthdelta(12)
end = begin + monthdelta(1) end = begin + monthdelta(1)
tsunamy = getTsunamy(channel)
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()
@ -48,6 +92,17 @@ while True:
dataMess.append(lenght) dataMess.append(lenght)
if lenght > 0: if lenght > 0:
if tsunamy & Tsunami.GLOBAL:
messagesDataTsunamy['global'][id] += lenght
if tsunamy & Tsunami.PROJECT:
messagesDataTsunamy['project'][id] += lenght
if tsunamy & Tsunami.DEMOCRACY:
messagesDataTsunamy['democraty'][id] += lenght
if tsunamy & Tsunami.ECOLOGY:
messagesDataTsunamy['ecology'][id] += lenght
if tsunamy & Tsunami.TECHNOLOGY:
messagesDataTsunamy['technology'][id] += lenght
users = [] users = []
for mess in resultMess['messages']: for mess in resultMess['messages']:
users.append(mess['u']['_id']) users.append(mess['u']['_id'])
@ -84,12 +139,7 @@ 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')
info = {
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
"labels": labels,
"messagesByChannel": messagesByChannel,
"usersByChannel": usersByChannel
}
statsFilePath = os.path.abspath( statsFilePath = os.path.abspath(
os.path.join(dataFolder, 'messagesByChannel.json')) os.path.join(dataFolder, 'messagesByChannel.json'))