portail/scripts/common/charthelper.py

44 lines
953 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
}
2020-01-01 18:52:21 +00:00
def setTopicsInfo(topics, messagesDataTopic, id, length):
for topic in topics:
2020-01-01 18:52:21 +00:00
result = None
if len(messagesDataTopic) > 0:
result = next((x for x in messagesDataTopic if x['label'] == topic), None)
if result is None:
result = createElement(topic, getColor(), [0] * 30)
messagesDataTopic.append(result)
result['data'][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
2020-01-01 18:52:21 +00:00
if __name__ == "__main__":
print("not executable")