Add messages by tsunamy in script generation
This commit is contained in:
parent
e44dfd8990
commit
c4146eb191
8 changed files with 5903 additions and 166 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -6,5 +6,5 @@ vendor/
|
|||
.bundle
|
||||
script/dev.config.py
|
||||
script/__pycache__/*.pyc
|
||||
|
||||
script/common/__pycache__/*.pyc
|
||||
\.vscode/\.ropeproject/
|
|
@ -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 chart3 = new Chart(ctx3, {
|
||||
// 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>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
]
|
||||
}
|
||||
]
|
39
script/common/channelhelper.py
Normal file
39
script/common/channelhelper.py
Normal 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
|
|
@ -9,26 +9,7 @@ import json
|
|||
import dev_config as cfg
|
||||
import os
|
||||
import re
|
||||
|
||||
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
|
||||
from common.channelhelper import getNodesOrigin
|
||||
|
||||
colorInfo = {
|
||||
'global': 'orange',
|
||||
|
@ -73,7 +54,7 @@ while True:
|
|||
for channel in channels['channels']:
|
||||
if channel['name'].find('cohorte') != -1:
|
||||
if 'description' in channel:
|
||||
m = re.findall('#([\w-]+)', channel['description'])
|
||||
m = re.findall(r'#([\w-]+)', channel['description'])
|
||||
for region in m:
|
||||
cohortescolor.update( { region: 'green' } )
|
||||
cohortes.update( { region: { 'link': channel['name']}})
|
||||
|
|
|
@ -11,6 +11,8 @@ import os
|
|||
import random
|
||||
from datetime import datetime
|
||||
from monthdelta import monthdelta
|
||||
from common.channelhelper import getTsunamy
|
||||
from common.channelhelper import Tsunami
|
||||
|
||||
def getColor():
|
||||
r = random.randrange(255)
|
||||
|
@ -23,11 +25,51 @@ rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
|
|||
index = 0
|
||||
labels = [None] * 12
|
||||
messagesByChannel = []
|
||||
messagesByTsunamy = []
|
||||
usersByChannel = []
|
||||
messagesDataTsunamy = {
|
||||
"global": [0] * 12,
|
||||
"project": [0] * 12,
|
||||
"democraty": [0] * 12,
|
||||
"ecology": [0] * 12,
|
||||
"technology": [0] * 12,
|
||||
}
|
||||
|
||||
now = datetime.now()
|
||||
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:
|
||||
channels = rocket.channels_list(offset=index).json()
|
||||
totalChannels = channels['total']
|
||||
|
@ -39,6 +81,8 @@ while True:
|
|||
begin = date - monthdelta(12)
|
||||
end = begin + monthdelta(1)
|
||||
|
||||
tsunamy = getTsunamy(channel)
|
||||
|
||||
for id in range(0, 12):
|
||||
labels[id] = begin.strftime("%b %Y")
|
||||
begindate = begin.isoformat()
|
||||
|
@ -48,6 +92,17 @@ while True:
|
|||
dataMess.append(lenght)
|
||||
|
||||
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 = []
|
||||
for mess in resultMess['messages']:
|
||||
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
|
||||
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(
|
||||
os.path.join(dataFolder, 'messagesByChannel.json'))
|
||||
|
|
Loading…
Reference in a new issue