Change to get topic to be more flexible
This commit is contained in:
parent
cc1272bf08
commit
aa0b0b4353
5 changed files with 36 additions and 72 deletions
|
@ -1,46 +1,34 @@
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
def getColor():
|
def getColor():
|
||||||
r = random.randrange(255)
|
r = random.randrange(255)
|
||||||
g = random.randrange(255)
|
g = random.randrange(255)
|
||||||
b = random.randrange(255)
|
b = random.randrange(255)
|
||||||
return 'rgb({:0},{:0},{:0})'.format(r,g,b)
|
return 'rgb({:0},{:0},{:0})'.format(r, g, b)
|
||||||
|
|
||||||
def createElement(label, color, data) :
|
|
||||||
|
def createElement(label, color, data):
|
||||||
return {
|
return {
|
||||||
"label": label,
|
"label": label,
|
||||||
"backgroundColor": color,
|
"backgroundColor": color,
|
||||||
"data": data
|
"data": data
|
||||||
}
|
}
|
||||||
|
|
||||||
def setTopicInfo(tsunamy, messagesDataTopic, id, length):
|
def setTopicsInfo(topics, messagesDataTopic, id, length):
|
||||||
if tsunamy & Topics.GLOBAL:
|
for topic in topics:
|
||||||
messagesDataTopic[Topics.GLOBAL][id] += length
|
if topic not in messagesDataTopic:
|
||||||
if tsunamy & Topics.PROJECT:
|
messagesDataTopic[topic] = [0] * 30
|
||||||
messagesDataTopic[Topics.PROJECT][id] += length
|
messagesDataTopic[topic][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
|
|
||||||
|
|
||||||
def getTopic(channel):
|
def getTopics(channel):
|
||||||
value = Topics.GLOBAL
|
|
||||||
if 'description' in channel:
|
if 'description' in channel:
|
||||||
if channel['description'].find("#projet") != -1:
|
topics = re.findall(r"#(\w+)\W?", channel['description'])
|
||||||
value |= Topics.PROJECT
|
if len(topics) == 0:
|
||||||
if channel['description'].find("#democratie") != -1:
|
topics.append('global')
|
||||||
value |= Topics.DEMOCRACY
|
return topics
|
||||||
if channel['description'].find("#ecologie") != -1:
|
return ['global']
|
||||||
value |= Topics.ECOLOGY
|
|
||||||
if channel['description'].find("#technologie") != -1:
|
|
||||||
value |= Topics.TECHNOLOGY
|
|
||||||
return value
|
|
||||||
|
|
||||||
class Topics:
|
if __name__ == "__main__":
|
||||||
GLOBAL = 1 << 0
|
print("not executable")
|
||||||
PROJECT = 1 << 1
|
|
||||||
DEMOCRACY = 1 << 2
|
|
||||||
ECOLOGY = 1 << 3
|
|
||||||
TECHNOLOGY = 1 << 4
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import random
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
|
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
|
||||||
from common.savehelper import save
|
from common.savehelper import save
|
||||||
from common.charthelper import createElement, getColor, setTopicInfo, getTopic, Topics
|
from common.charthelper import createElement, getColor, setTopicsInfo, getTopics
|
||||||
|
|
||||||
begin = datetime.now()
|
begin = datetime.now()
|
||||||
end = datetime.now()
|
end = datetime.now()
|
||||||
|
@ -25,13 +25,7 @@ def main():
|
||||||
labels = [None] * nbElements
|
labels = [None] * nbElements
|
||||||
messagesByChannel = []
|
messagesByChannel = []
|
||||||
usersByChannel = []
|
usersByChannel = []
|
||||||
messagesDataTopic = {
|
messagesByTopic = {}
|
||||||
Topics.GLOBAL: [0] * nbElements,
|
|
||||||
Topics.PROJECT: [0] * nbElements,
|
|
||||||
Topics.DEMOCRACY: [0] * nbElements,
|
|
||||||
Topics.ECOLOGY: [0] * nbElements,
|
|
||||||
Topics.TECHNOLOGY: [0] * nbElements,
|
|
||||||
}
|
|
||||||
usersGlobal = []
|
usersGlobal = []
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
@ -42,13 +36,7 @@ def main():
|
||||||
"labels": labels,
|
"labels": labels,
|
||||||
"messagesByChannel": messagesByChannel,
|
"messagesByChannel": messagesByChannel,
|
||||||
"usersByChannel": usersByChannel,
|
"usersByChannel": usersByChannel,
|
||||||
"messagesByTopic": [
|
"messagesByTopic": messagesByTopic,
|
||||||
createElement("global", getColor(), messagesDataTopic[Topics.GLOBAL]),
|
|
||||||
createElement("project", getColor(), messagesDataTopic[Topics.PROJECT]),
|
|
||||||
createElement("democratie", getColor(), messagesDataTopic[Topics.DEMOCRACY]),
|
|
||||||
createElement("ecologie", getColor(), messagesDataTopic[Topics.ECOLOGY]),
|
|
||||||
createElement("technologie", getColor(), messagesDataTopic[Topics.TECHNOLOGY])
|
|
||||||
],
|
|
||||||
"usersGlobal": usersGlobal
|
"usersGlobal": usersGlobal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +49,8 @@ def main():
|
||||||
begin = date - timedelta(nbElements)
|
begin = date - timedelta(nbElements)
|
||||||
end = begin + timedelta(nbElements)
|
end = begin + timedelta(nbElements)
|
||||||
|
|
||||||
tsunamy = getTopic(channel)
|
topics = getTopics(channel)
|
||||||
|
print(topics)
|
||||||
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate= end, count= channel["msgs"])
|
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate= end, count= channel["msgs"])
|
||||||
end = begin + timedelta(1)
|
end = begin + timedelta(1)
|
||||||
|
|
||||||
|
@ -77,7 +65,7 @@ def main():
|
||||||
dataMess.append(length)
|
dataMess.append(length)
|
||||||
|
|
||||||
if length > 0:
|
if length > 0:
|
||||||
setTopicInfo(tsunamy, messagesDataTopic, id, length)
|
setTopicsInfo(topics, messagesByTopic, id, length)
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for mess in resultMess:
|
for mess in resultMess:
|
||||||
|
|
|
@ -12,7 +12,7 @@ from datetime import datetime
|
||||||
from monthdelta import monthdelta
|
from monthdelta import monthdelta
|
||||||
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
|
from common.rocketchathelper import getAllChannels, getAllMessages, Connection
|
||||||
from common.savehelper import save
|
from common.savehelper import save
|
||||||
from common.charthelper import createElement, getColor, setTopicInfo, Topics, getTopic
|
from common.charthelper import createElement, getColor, setTopicsInfo, getTopics
|
||||||
|
|
||||||
begin = datetime.now()
|
begin = datetime.now()
|
||||||
end = datetime.now()
|
end = datetime.now()
|
||||||
|
@ -26,13 +26,7 @@ def main():
|
||||||
labels = [None] * 12
|
labels = [None] * 12
|
||||||
messagesByChannel = []
|
messagesByChannel = []
|
||||||
usersByChannel = []
|
usersByChannel = []
|
||||||
messagesDataTopic = {
|
messagesByTopic = {}
|
||||||
Topics.GLOBAL: [0] * 12,
|
|
||||||
Topics.PROJECT: [0] * 12,
|
|
||||||
Topics.DEMOCRACY: [0] * 12,
|
|
||||||
Topics.ECOLOGY: [0] * 12,
|
|
||||||
Topics.TECHNOLOGY: [0] * 12,
|
|
||||||
}
|
|
||||||
usersGlobal = []
|
usersGlobal = []
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
@ -43,13 +37,7 @@ def main():
|
||||||
"labels": labels,
|
"labels": labels,
|
||||||
"messagesByChannel": messagesByChannel,
|
"messagesByChannel": messagesByChannel,
|
||||||
"usersByChannel": usersByChannel,
|
"usersByChannel": usersByChannel,
|
||||||
"messagesByTopic": [
|
"messagesByTopic": messagesByTopic,
|
||||||
createElement("global", getColor(), messagesDataTopic[Topics.GLOBAL]),
|
|
||||||
createElement("project", getColor(), messagesDataTopic[Topics.PROJECT]),
|
|
||||||
createElement("democratie", getColor(), messagesDataTopic[Topics.DEMOCRACY]),
|
|
||||||
createElement("ecologie", getColor(), messagesDataTopic[Topics.ECOLOGY]),
|
|
||||||
createElement("technologie", getColor(), messagesDataTopic[Topics.TECHNOLOGY])
|
|
||||||
],
|
|
||||||
"usersGlobal": usersGlobal
|
"usersGlobal": usersGlobal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,8 +52,8 @@ def main():
|
||||||
|
|
||||||
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs'])
|
messages = getAllMessages(rocket, channel['_id'], begindate= begin, enddate=date, count= channel['msgs'])
|
||||||
|
|
||||||
tsunamy = getTopic(channel)
|
topics = getTopics(channel)
|
||||||
|
print(topics)
|
||||||
for id in range(0, 12):
|
for id in range(0, 12):
|
||||||
if uniqueUserGlobal[id] == None:
|
if uniqueUserGlobal[id] == None:
|
||||||
uniqueUserGlobal[id] = []
|
uniqueUserGlobal[id] = []
|
||||||
|
@ -77,7 +65,7 @@ def main():
|
||||||
dataMess.append(length)
|
dataMess.append(length)
|
||||||
|
|
||||||
if length > 0:
|
if length > 0:
|
||||||
setTopicInfo(tsunamy, messagesDataTopic, id, length)
|
setTopicsInfo(topics, messagesByTopic, id, length)
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for mess in resultMess:
|
for mess in resultMess:
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue