diff --git a/scripts/common/charthelper.py b/scripts/common/charthelper.py new file mode 100644 index 0000000..e5aad4a --- /dev/null +++ b/scripts/common/charthelper.py @@ -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 \ No newline at end of file diff --git a/scripts/common/rocketchathelper.py b/scripts/common/rocketchathelper.py index e4b8927..b8d84fa 100644 --- a/scripts/common/rocketchathelper.py +++ b/scripts/common/rocketchathelper.py @@ -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 = [] diff --git a/scripts/generate_chat_stat_monthly.py b/scripts/generate_chat_stat_monthly.py index b5412ca..8c6f86c 100644 --- a/scripts/generate_chat_stat_monthly.py +++ b/scripts/generate_chat_stat_monthly.py @@ -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()