portail/scripts/common/charthelper.py

35 lines
781 B
Python
Raw Normal View History

2019-09-01 19:18:30 +00:00
import random
import re
2019-09-01 19:18:30 +00:00
def getColor():
r = random.randrange(255)
g = random.randrange(255)
b = random.randrange(255)
return 'rgb({:0},{:0},{:0})'.format(r, g, b)
2019-09-01 19:18:30 +00:00
def createElement(label, color, data):
2019-09-01 19:18:30 +00:00
return {
"label": label,
"backgroundColor": color,
"data": data
2019-09-01 19:18:30 +00:00
}
def setTopicsInfo(topics, messagesDataTopic, id, length):
for topic in topics:
if topic not in messagesDataTopic:
messagesDataTopic[topic] = [0] * 30
messagesDataTopic[topic][id] += length
2019-09-01 19:18:30 +00:00
def getTopics(channel):
if 'description' in channel:
topics = re.findall(r"#(\w+)\W?", channel['description'])
if len(topics) == 0:
topics.append('global')
return topics
return ['global']
2019-09-01 19:18:30 +00:00
if __name__ == "__main__":
print("not executable")