refacto charthelper
This commit is contained in:
parent
8f99caa42c
commit
2673fc3acf
3 changed files with 48 additions and 46 deletions
46
scripts/common/charthelper.py
Normal file
46
scripts/common/charthelper.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
import random
|
||||
|
||||
def getColor():
|
||||
r = random.randrange(255)
|
||||
g = random.randrange(255)
|
||||
b = random.randrange(255)
|
||||
return 'rgb({:0},{:0},{:0})'.format(r,g,b)
|
||||
|
||||
def createElement(label, color, data) :
|
||||
return {
|
||||
"label": label,
|
||||
"backgroundColor": color,
|
||||
"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 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
|
|
@ -25,26 +25,6 @@ def getNodesOrigin(channel):
|
|||
|
||||
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
|
||||
|
||||
def getAllChannels(rocket):
|
||||
index = 0
|
||||
allChannels = []
|
||||
|
|
|
@ -10,33 +10,9 @@ import os
|
|||
import random
|
||||
from datetime import datetime
|
||||
from monthdelta import monthdelta
|
||||
from common.rocketchathelper import getTsunamy, Tsunami, getAllChannels, getAllMessages, Connection
|
||||
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
|
||||
from common.savehelper import save
|
||||
|
||||
def getColor():
|
||||
r = random.randrange(255)
|
||||
g = random.randrange(255)
|
||||
b = random.randrange(255)
|
||||
return 'rgb({:0},{:0},{:0})'.format(r,g,b)
|
||||
|
||||
def createElement(label, color, data) :
|
||||
return {
|
||||
"label": label,
|
||||
"backgroundColor": color,
|
||||
"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
|
||||
from common.charthelper import createElement, getColor, setTsunamyInfo, Tsunami, getTsunamy
|
||||
|
||||
def main():
|
||||
rocket = Connection()
|
||||
|
|
Loading…
Reference in a new issue