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 setTopicInfo(tsunamy, messagesDataTopic, id, length):
if tsunamy & Topics.GLOBAL:
messagesDataTopic[Topics.GLOBAL][id] += length
if tsunamy & Topics.PROJECT:
messagesDataTopic[Topics.PROJECT][id] += length
if tsunamy & Topics.DEMOCRACY:
messagesDataTopic[Topics.DEMOCRACY][id] += length
if tsunamy & Topics.ECOLOGY:
messagesDataTopic[Topics.ECOLOGY][id] += length
if tsunamy & Topics.TECHNOLOGY:
messagesDataTopic[Topics.TECHNOLOGY][id] += length
2019-09-01 19:18:30 +00:00
def getTopic(channel):
value = Topics.GLOBAL
2019-09-01 19:18:30 +00:00
if 'description' in channel:
if channel['description'].find("#projet") != -1:
value |= Topics.PROJECT
2019-09-01 19:18:30 +00:00
if channel['description'].find("#democratie") != -1:
value |= Topics.DEMOCRACY
2019-09-01 19:18:30 +00:00
if channel['description'].find("#ecologie") != -1:
value |= Topics.ECOLOGY
2019-09-01 19:18:30 +00:00
if channel['description'].find("#technologie") != -1:
value |= Topics.TECHNOLOGY
2019-09-01 19:18:30 +00:00
return value
class Topics:
2019-09-01 19:18:30 +00:00
GLOBAL = 1 << 0
PROJECT = 1 << 1
DEMOCRACY = 1 << 2
ECOLOGY = 1 << 3
TECHNOLOGY = 1 << 4