portail/scripts/common/charthelper.py

46 lines
1.4 KiB
Python
Raw Normal View History

2019-09-01 19:18:30 +00:00
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