=t.length-1?t[0]:t[e+1]:e>=t.length-1?t[t.length-1]:t[e+1]},ut.previousItem=function(t,e,i){return i?e<=0?t[t.length-1]:t[e-1]:e<=0?t[0]:t[e-1]},ut.niceNum=function(t,e){var i=Math.floor(ut.log10(t)),n=t/Math.pow(10,i);return(e?n<1.5?1:n<3?2:n<7?5:10:n<=1?1:n<=2?2:n<=5?5:10)*Math.pow(10,i)},ut.requestAnimFrame="undefined"==typeof window?function(t){t()}:window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){return window.setTimeout(t,1e3/60)},ut.getRelativePosition=function(t,e){var i,n,a=t.originalEvent||t,r=t.target||t.srcElement,o=r.getBoundingClientRect(),s=a.touches;s&&s.length>0?(i=s[0].clientX,n=s[0].clientY):(i=a.clientX,n=a.clientY);var l=parseFloat(ut.getStyle(r,"padding-left")),u=parseFloat(ut.getStyle(r,"padding-top")),d=parseFloat(ut.getStyle(r,"padding-right")),h=parseFloat(ut.getStyle(r,"padding-bottom")),c=o.right-o.left-l-d,f=o.bottom-o.top-u-h;return{x:i=Math.round((i-o.left-l)/c*r.width/e.currentDevicePixelRatio),y:n=Math.round((n-o.top-u)/f*r.height/e.currentDevicePixelRatio)}},ut.getConstraintWidth=function(t){return i(t,"max-width","clientWidth")},ut.getConstraintHeight=function(t){return i(t,"max-height","clientHeight")},ut._calculatePadding=function(t,e,i){return(e=ut.getStyle(t,e)).indexOf("%")>-1?i*parseInt(e,10)/100:parseInt(e,10)},ut._getParentNode=function(t){var e=t.parentNode;return e&&"[object ShadowRoot]"===e.toString()&&(e=e.host),e},ut.getMaximumWidth=function(t){var e=ut._getParentNode(t);if(!e)return t.clientWidth;var i=e.clientWidth,n=i-ut._calculatePadding(e,"padding-left",i)-ut._calculatePadding(e,"padding-right",i),a=ut.getConstraintWidth(t);return isNaN(a)?n:Math.min(n,a)},ut.getMaximumHeight=function(t){var e=ut._getParentNode(t);if(!e)return t.clientHeight;var i=e.clientHeight,n=i-ut._calculatePadding(e,"padding-top",i)-ut._calculatePadding(e,"padding-bottom",i),a=ut.getConstraintHeight(t);return isNaN(a)?n:Math.min(n,a)},ut.getStyle=function(t,e){return t.currentStyle?t.currentStyle[e]:document.defaultView.getComputedStyle(t,null).getPropertyValue(e)},ut.retinaScale=function(t,e){var i=t.currentDevicePixelRatio=e||"undefined"!=typeof window&&window.devicePixelRatio||1;if(1!==i){var n=t.canvas,a=t.height,r=t.width;n.height=a*i,n.width=r*i,t.ctx.scale(i,i),n.style.height||n.style.width||(n.style.height=a+"px",n.style.width=r+"px")}},ut.fontString=function(t,e,i){return e+" "+t+"px "+i},ut.longestText=function(t,e,i,n){var a=(n=n||{}).data=n.data||{},r=n.garbageCollect=n.garbageCollect||[];n.font!==e&&(a=n.data={},r=n.garbageCollect=[],n.font=e),t.font=e;var o=0;ut.each(i,function(e){null!=e&&!0!==ut.isArray(e)?o=ut.measureText(t,a,r,o,e):ut.isArray(e)&&ut.each(e,function(e){null==e||ut.isArray(e)||(o=ut.measureText(t,a,r,o,e))})});var s=r.length/2;if(s>i.length){for(var l=0;ln&&(n=r),n},ut.numberOfLabelLines=function(t){var e=1;return ut.each(t,function(t){ut.isArray(t)&&t.length>e&&(e=t.length)}),e},ut.color=G?function(t){return t instanceof CanvasGradient&&(t=ot.global.defaultColor),G(t)}:function(t){return console.error("Color.js not found!"),t},ut.getHoverColor=function(t){return t instanceof CanvasPattern||t instanceof CanvasGradient?t:ut.color(t).saturate(.5).darken(.1).rgbString()}}(),ai._adapters=si,ai.Animation=pt,ai.animationService=vt,ai.controllers=ue,ai.DatasetController=kt,ai.defaults=ot,ai.Element=gt,ai.elements=Nt,ai.Interaction=pe,ai.layouts=xe,ai.platform=Ve,ai.plugins=He,ai.Scale=fi,ai.scaleService=Ee,ai.Ticks=li,ai.Tooltip=Je,ai.helpers.each(en,function(t,e){ai.scaleService.registerScaleType(e,t,t._defaults)}),kn)kn.hasOwnProperty(Dn)&&ai.plugins.register(kn[Dn]);ai.platform.initialize();var Cn=ai;return"undefined"!=typeof window&&(window.Chart=ai),ai.Chart=ai,ai.Legend=kn.legend._element,ai.Title=kn.title._element,ai.pluginService=ai.plugins,ai.PluginBase=ai.Element.extend({}),ai.canvasHelpers=ai.helpers.canvas,ai.layoutService=ai.layouts,ai.LinearScaleBase=yi,ai.helpers.each(["Bar","Bubble","Doughnut","Line","PolarArea","Radar","Scatter"],function(t){ai[t]=function(e,i){return new ai(e,ai.helpers.merge(i||{},{type:t.charAt(0).toLowerCase()+t.slice(1)}))}}),Cn});
diff --git a/script/README.md b/script/README.md
index 41e2bf5..498a2ad 100644
--- a/script/README.md
+++ b/script/README.md
@@ -1,5 +1,4 @@
-# getchannels
-## installation
+# installation
## pre-requis
Il faut Python 3 & pip car le code est fait en python.
## Installation
@@ -13,8 +12,25 @@ Il faut créer un fichier dev_config.py avec ses infos de connection au Rocket.c
'user' : 'username',
'password': 'pwd'
}
-# Lancer
+# Get Channels
+Permet de générer les infos pour la page
+https://crapaud-fou.org/channelslist/
+## Lancer
python getchannels.py
-# Commit
-Un fichier sera créé dans le répertoire [../public/data/result.json](../public/data/result.json)
+## Commit
+Des fichiers seront créé
+* [../public/data/channelslist.json](../public/data/channelslist.json)
+* [../public/data/cohortescolor.json](../public/data/cohortescolor.json)
+* [../public/data/cohorteslist.json](../public/data/cohorteslist.json)
+
+# Get Stats
+Permet de générer les infos pour la page
+https://crapaud-fou.org/channelsstats/
+
+## Lancer
+ python getstats.py
+
+## Commit
+Un fichier sera créé
+* [../public/data/channelsstat.json](../public/data/channelsstat.json)
\ No newline at end of file
diff --git a/script/common/channelhelper.py b/script/common/channelhelper.py
new file mode 100644
index 0000000..5be16e4
--- /dev/null
+++ b/script/common/channelhelper.py
@@ -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
\ No newline at end of file
diff --git a/script/getchannels.py b/script/getchannels.py
index 6f577ec..84e52f8 100644
--- a/script/getchannels.py
+++ b/script/getchannels.py
@@ -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']}})
diff --git a/script/getstats.py b/script/getstats.py
new file mode 100644
index 0000000..76a788c
--- /dev/null
+++ b/script/getstats.py
@@ -0,0 +1,148 @@
+# coding: utf8
+
+# toutes les chaines sont en unicode (même les docstrings)
+from __future__ import unicode_literals
+
+from pprint import pprint
+from rocketchat_API.rocketchat import RocketChat
+import json
+import dev_config as cfg
+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)
+ g = random.randrange(255)
+ b = random.randrange(255)
+ return 'rgb({:0},{:0},{:0})'.format(r,g,b)
+
+rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
+ server_url='https://coa.crapaud-fou.org')
+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']
+
+ for channel in channels['channels']:
+ dataMess = []
+ dataUsers = []
+ pprint( channel['name'] )
+ 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()
+ enddate = end.isoformat()
+ resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json()
+ lenght = len(resultMess['messages'])
+ 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'])
+ usersDistinct = set(users)
+ dataUsers.append(len(usersDistinct))
+ else:
+ dataUsers.append(0)
+
+ begin = end
+ end = begin + monthdelta(1)
+
+ color = getColor()
+ messageByChannel = {
+ "label": channel['name'],
+ "backgroundColor": color,
+ "data": dataMess
+ }
+
+ userByChannel = {
+ "label": channel['name'],
+ "backgroundColor": color,
+ "data": dataUsers
+ }
+
+ messagesByChannel.append(messageByChannel)
+ usersByChannel.append(userByChannel)
+
+ if channels['count'] + channels['offset'] >= channels['total']:
+ break
+ index += channels['count']
+
+# 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:
+ json.dump(info, file_write)
+
diff --git a/script/requirements.txt b/script/requirements.txt
index 82e395a..778ed34 100644
--- a/script/requirements.txt
+++ b/script/requirements.txt
@@ -1 +1,2 @@
rocketchat_API==0.6.32
+MonthDelta==0.9.1
\ No newline at end of file
diff --git a/statpages/channelsstats.html b/statpages/channelsstats.html
deleted file mode 100644
index 29fbefc..0000000
--- a/statpages/channelsstats.html
+++ /dev/null
@@ -1,129 +0,0 @@
----
-layout: default
-permalink: /channelsstats/
-title: Statistiques du Chat
-linktitle: "Statistiques du Chat"
-linkurl: /channelsstats/
-description: "Statistiques sur le chat https://coa.crapaud-fou.org"
----
-
-
-
-Statistiques du chat (aussi connu sous le nom de mare aux crapauds) :
-
-
-
-
\ No newline at end of file