refacto
This commit is contained in:
parent
2c188c4ccf
commit
f7baf818e1
3 changed files with 133 additions and 126 deletions
|
@ -37,3 +37,18 @@ class Tsunami:
|
||||||
DEMOCRACY = 1 << 2
|
DEMOCRACY = 1 << 2
|
||||||
ECOLOGY = 1 << 3
|
ECOLOGY = 1 << 3
|
||||||
TECHNOLOGY = 1 << 4
|
TECHNOLOGY = 1 << 4
|
||||||
|
|
||||||
|
def getAllChannels(rocket):
|
||||||
|
index = 0
|
||||||
|
allChannels = []
|
||||||
|
while True:
|
||||||
|
channels = rocket.channels_list(offset= index).json()
|
||||||
|
|
||||||
|
allChannels.extend([ channel for channel in channels['channels'] if 'archived' not in channel])
|
||||||
|
if channels['count'] + channels['offset'] >= channels['total']:
|
||||||
|
break
|
||||||
|
index += channels['count']
|
||||||
|
return allChannels
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("Ce fichier est juste une librarie")
|
|
@ -9,7 +9,9 @@ import json
|
||||||
import dev_config as cfg
|
import dev_config as cfg
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from common.channelhelper import getNodesOrigin
|
from common.channelhelper import getNodesOrigin, getAllChannels, Tsunami
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
colorInfo = {
|
colorInfo = {
|
||||||
'global': 'orange',
|
'global': 'orange',
|
||||||
|
@ -19,7 +21,7 @@ colorInfo = {
|
||||||
'project': 'blue'
|
'project': 'blue'
|
||||||
}
|
}
|
||||||
|
|
||||||
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'], server_url='https://coa.crapaud-fou.org')
|
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'], server_url=cfg.rocket['server'])
|
||||||
|
|
||||||
sizebase = 100
|
sizebase = 100
|
||||||
datas = []
|
datas = []
|
||||||
|
@ -31,18 +33,11 @@ datas.append( { 'data':{'id':'project', 'label': 'projet', 'size': sizebase, 'co
|
||||||
|
|
||||||
cohortes = { 'fr': { 'updateMap': 'france_fr'}}
|
cohortes = { 'fr': { 'updateMap': 'france_fr'}}
|
||||||
cohortescolor = { 'fr': 'green' }
|
cohortescolor = { 'fr': 'green' }
|
||||||
index = 0
|
|
||||||
nbChannels = 0
|
nbChannels = 0
|
||||||
nbCohorte = 0
|
nbCohorte = 0
|
||||||
totalChannels = 0
|
totalChannels = 0
|
||||||
while True:
|
for channel in getAllChannels(rocket):
|
||||||
channels = rocket.channels_list(offset= index).json()
|
|
||||||
totalChannels = channels['total']
|
|
||||||
|
|
||||||
for channel in channels['channels']:
|
|
||||||
print("{}".format(channel['name']))
|
print("{}".format(channel['name']))
|
||||||
if ('archived' in channel) and channel['archived']:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if channel['name'].find('cohorte') != -1:
|
if channel['name'].find('cohorte') != -1:
|
||||||
if 'description' in channel:
|
if 'description' in channel:
|
||||||
|
@ -64,7 +59,7 @@ while True:
|
||||||
'label': channel['fname'] if 'fname' in channel else channel['name'],
|
'label': channel['fname'] if 'fname' in channel else channel['name'],
|
||||||
'size': size,
|
'size': size,
|
||||||
'color': 'grey',
|
'color': 'grey',
|
||||||
'href': 'https://coa.crapaud-fou.org/channel/'+channel['name']
|
'href': f"{cfg.rocket['server']}/channel/{channel['name']}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
datas.append(node)
|
datas.append(node)
|
||||||
|
@ -76,10 +71,6 @@ while True:
|
||||||
|
|
||||||
nbChannels += 1
|
nbChannels += 1
|
||||||
|
|
||||||
if channels['count'] + channels['offset'] >= channels['total']:
|
|
||||||
break
|
|
||||||
index += channels['count']
|
|
||||||
|
|
||||||
# Récupération du répertoire racine du repo
|
# Récupération du répertoire racine du repo
|
||||||
rootFolder = os.path.join(os.path.dirname(__file__), '..')
|
rootFolder = os.path.join(os.path.dirname(__file__), '..')
|
||||||
# Répertoire pour stocker le fichier de sortie
|
# Répertoire pour stocker le fichier de sortie
|
||||||
|
@ -103,4 +94,6 @@ with open(cohorteFilePath, "w") as file_write:
|
||||||
|
|
||||||
pprint("Nb displayed channels : " + str(nbChannels))
|
pprint("Nb displayed channels : " + str(nbChannels))
|
||||||
pprint("Nb cohorte channels : " + str(nbCohorte))
|
pprint("Nb cohorte channels : " + str(nbCohorte))
|
||||||
pprint("Nb total channels : " + str(totalChannels))
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -3,7 +3,7 @@
|
||||||
# toutes les chaines sont en unicode (même les docstrings)
|
# toutes les chaines sont en unicode (même les docstrings)
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from pprint import pprint
|
# from pprint import pprint
|
||||||
from rocketchat_API.rocketchat import RocketChat
|
from rocketchat_API.rocketchat import RocketChat
|
||||||
import json
|
import json
|
||||||
import dev_config as cfg
|
import dev_config as cfg
|
||||||
|
@ -11,8 +11,7 @@ import os
|
||||||
import random
|
import random
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from monthdelta import monthdelta
|
from monthdelta import monthdelta
|
||||||
from common.channelhelper import getTsunamy
|
from common.channelhelper import getTsunamy, Tsunami, getAllChannels
|
||||||
from common.channelhelper import Tsunami
|
|
||||||
|
|
||||||
def getColor():
|
def getColor():
|
||||||
r = random.randrange(255)
|
r = random.randrange(255)
|
||||||
|
@ -38,19 +37,31 @@ def createElement(label, color, data) :
|
||||||
"data": data
|
"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 main():
|
def main():
|
||||||
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
|
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
|
||||||
server_url='https://coa.crapaud-fou.org')
|
server_url=cfg.rocket['server'])
|
||||||
index = 0
|
|
||||||
labels = [None] * 12
|
labels = [None] * 12
|
||||||
messagesByChannel = []
|
messagesByChannel = []
|
||||||
usersByChannel = []
|
usersByChannel = []
|
||||||
messagesDataTsunamy = {
|
messagesDataTsunamy = {
|
||||||
"global": [0] * 12,
|
Tsunami.GLOBAL: [0] * 12,
|
||||||
"project": [0] * 12,
|
Tsunami.PROJECT: [0] * 12,
|
||||||
"democraty": [0] * 12,
|
Tsunami.DEMOCRACY: [0] * 12,
|
||||||
"ecology": [0] * 12,
|
Tsunami.ECOLOGY: [0] * 12,
|
||||||
"technology": [0] * 12,
|
Tsunami.TECHNOLOGY: [0] * 12,
|
||||||
}
|
}
|
||||||
usersGlobal = []
|
usersGlobal = []
|
||||||
|
|
||||||
|
@ -63,56 +74,46 @@ def main():
|
||||||
"messagesByChannel": messagesByChannel,
|
"messagesByChannel": messagesByChannel,
|
||||||
"usersByChannel": usersByChannel,
|
"usersByChannel": usersByChannel,
|
||||||
"messagesByTsunamy": [
|
"messagesByTsunamy": [
|
||||||
createElement("global", getColor(), messagesDataTsunamy['global']),
|
createElement("global", getColor(), messagesDataTsunamy[Tsunami.GLOBAL]),
|
||||||
createElement("project", getColor(), messagesDataTsunamy['project']),
|
createElement("project", getColor(), messagesDataTsunamy[Tsunami.PROJECT]),
|
||||||
createElement("democratie", getColor(), messagesDataTsunamy['democraty']),
|
createElement("democratie", getColor(), messagesDataTsunamy[Tsunami.DEMOCRACY]),
|
||||||
createElement("ecologie", getColor(), messagesDataTsunamy['ecology']),
|
createElement("ecologie", getColor(), messagesDataTsunamy[Tsunami.ECOLOGY]),
|
||||||
createElement("technologie", getColor(), messagesDataTsunamy['technology'])
|
createElement("technologie", getColor(), messagesDataTsunamy[Tsunami.TECHNOLOGY])
|
||||||
],
|
],
|
||||||
"usersGlobal": usersGlobal
|
"usersGlobal": usersGlobal
|
||||||
}
|
}
|
||||||
|
|
||||||
usersTest = [None] * 12
|
uniqueUserGlobal = [None] * 12
|
||||||
|
|
||||||
while True:
|
for channel in getAllChannels(rocket):
|
||||||
channels = rocket.channels_list(offset=index).json()
|
|
||||||
|
|
||||||
for channel in channels['channels']:
|
|
||||||
dataMess = []
|
dataMess = []
|
||||||
dataUsers = []
|
dataUsers = []
|
||||||
pprint( channel['name'] )
|
print( channel['name'] )
|
||||||
begin = date - monthdelta(12)
|
begin = date - monthdelta(12)
|
||||||
end = begin + monthdelta(1)
|
end = begin + monthdelta(1)
|
||||||
|
|
||||||
tsunamy = getTsunamy(channel)
|
tsunamy = getTsunamy(channel)
|
||||||
|
|
||||||
for id in range(0, 12):
|
for id in range(0, 12):
|
||||||
if usersTest[id] == None:
|
if uniqueUserGlobal[id] == None:
|
||||||
usersTest[id] = []
|
uniqueUserGlobal[id] = []
|
||||||
labels[id] = begin.strftime("%b %Y")
|
labels[id] = begin.strftime("%b %Y")
|
||||||
|
print(f"\t{labels[id]}")
|
||||||
begindate = begin.isoformat()
|
begindate = begin.isoformat()
|
||||||
enddate = end.isoformat()
|
enddate = end.isoformat()
|
||||||
|
|
||||||
resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json()
|
resultMess = rocket.channels_history(channel['_id'], oldest= begindate, latest=enddate, count= 10000).json()
|
||||||
resultMess = list(filter(lambda mess: 't' not in mess, resultMess['messages']))
|
resultMess = list(filter(lambda mess: 't' not in mess, resultMess['messages']))
|
||||||
lenght = len(resultMess)
|
length = len(resultMess)
|
||||||
dataMess.append(lenght)
|
dataMess.append(length)
|
||||||
|
|
||||||
if lenght > 0:
|
if length > 0:
|
||||||
if tsunamy & Tsunami.GLOBAL:
|
setTsunamyInfo(tsunamy, messagesDataTsunamy, id, length)
|
||||||
messagesDataTsunamy['global'][id] += lenght
|
|
||||||
if tsunamy & Tsunami.PROJECT:
|
|
||||||
messagesDataTsunamy['project'][id] += lenght
|
|
||||||
if tsunamy & Tsunami.DEMOCRACY:
|
|
||||||
messagesDataTsunamy['democraty'][id] += lenght
|
|
||||||
if tsunamy & Tsunami.ECOLOGY:
|
|
||||||
messagesDataTsunamy['ecology'][id] += lenght
|
|
||||||
if tsunamy & Tsunami.TECHNOLOGY:
|
|
||||||
messagesDataTsunamy['technology'][id] += lenght
|
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
for mess in resultMess:
|
for mess in resultMess:
|
||||||
users.append(mess['u']['_id'])
|
users.append(mess['u']['_id'])
|
||||||
usersTest[id].append(mess['u']['_id'])
|
uniqueUserGlobal[id].append(mess['u']['_id'])
|
||||||
usersDistinct = set(users)
|
usersDistinct = set(users)
|
||||||
dataUsers.append(len(usersDistinct))
|
dataUsers.append(len(usersDistinct))
|
||||||
else:
|
else:
|
||||||
|
@ -128,17 +129,15 @@ def main():
|
||||||
messagesByChannel.append(messageByChannel)
|
messagesByChannel.append(messageByChannel)
|
||||||
usersByChannel.append(userByChannel)
|
usersByChannel.append(userByChannel)
|
||||||
|
|
||||||
if channels['count'] + channels['offset'] >= channels['total']:
|
|
||||||
break
|
|
||||||
index += channels['count']
|
|
||||||
|
|
||||||
for id in range(0, 12):
|
for id in range(0, 12):
|
||||||
usersTest[id] = len(set(usersTest[id]))
|
uniqueUserGlobal[id] = len(set(uniqueUserGlobal[id]))
|
||||||
|
|
||||||
userGlobal = createElement( 'global', 'red', usersTest)
|
userGlobal = createElement( 'global', 'red', uniqueUserGlobal)
|
||||||
usersGlobal.append(userGlobal)
|
usersGlobal.append(userGlobal)
|
||||||
|
|
||||||
save(info)
|
save(info)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in a new issue