1st refacto
This commit is contained in:
parent
20157b2cd3
commit
2c188c4ccf
1 changed files with 108 additions and 128 deletions
|
@ -20,63 +20,62 @@ def getColor():
|
||||||
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)
|
||||||
|
|
||||||
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
|
def save(info):
|
||||||
|
# Récupération du répertoire racine du repo
|
||||||
|
rootFolder = os.path.join(os.path.dirname(__file__), '..')
|
||||||
|
# Répertoire pour stocker le fichier de sortie
|
||||||
|
dataFolder = os.path.join(rootFolder, 'public', 'data')
|
||||||
|
|
||||||
|
statsFilePath = os.path.abspath(
|
||||||
|
os.path.join(dataFolder, 'channelsstat.json'))
|
||||||
|
with open(statsFilePath, "w") as file_write:
|
||||||
|
json.dump(info, file_write)
|
||||||
|
|
||||||
|
def createElement(label, color, data) :
|
||||||
|
return {
|
||||||
|
"label": label,
|
||||||
|
"backgroundColor": color,
|
||||||
|
"data": data
|
||||||
|
}
|
||||||
|
|
||||||
|
def main():
|
||||||
|
rocket = RocketChat(cfg.rocket['user'], cfg.rocket['password'],
|
||||||
server_url='https://coa.crapaud-fou.org')
|
server_url='https://coa.crapaud-fou.org')
|
||||||
index = 0
|
index = 0
|
||||||
labels = [None] * 12
|
labels = [None] * 12
|
||||||
messagesByChannel = []
|
messagesByChannel = []
|
||||||
messagesByTsunamy = []
|
usersByChannel = []
|
||||||
usersByChannel = []
|
messagesDataTsunamy = {
|
||||||
messagesDataTsunamy = {
|
|
||||||
"global": [0] * 12,
|
"global": [0] * 12,
|
||||||
"project": [0] * 12,
|
"project": [0] * 12,
|
||||||
"democraty": [0] * 12,
|
"democraty": [0] * 12,
|
||||||
"ecology": [0] * 12,
|
"ecology": [0] * 12,
|
||||||
"technology": [0] * 12,
|
"technology": [0] * 12,
|
||||||
}
|
}
|
||||||
usersGlobal = []
|
usersGlobal = []
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
date = datetime(now.year, now.month, now.day, 0,0,0)
|
date = datetime(now.year, now.month, now.day, 0,0,0)
|
||||||
|
|
||||||
info = {
|
info = {
|
||||||
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
|
"updated": "updated {:02}/{:02}/{:04}".format(now.day, now.month, now.year),
|
||||||
"labels": labels,
|
"labels": labels,
|
||||||
"messagesByChannel": messagesByChannel,
|
"messagesByChannel": messagesByChannel,
|
||||||
"usersByChannel": usersByChannel,
|
"usersByChannel": usersByChannel,
|
||||||
"messagesByTsunamy": [{
|
"messagesByTsunamy": [
|
||||||
"label": "global",
|
createElement("global", getColor(), messagesDataTsunamy['global']),
|
||||||
"backgroundColor": getColor(),
|
createElement("project", getColor(), messagesDataTsunamy['project']),
|
||||||
"data": messagesDataTsunamy['global']
|
createElement("democratie", getColor(), messagesDataTsunamy['democraty']),
|
||||||
},
|
createElement("ecologie", getColor(), messagesDataTsunamy['ecology']),
|
||||||
{
|
createElement("technologie", getColor(), messagesDataTsunamy['technology'])
|
||||||
"label": "projet",
|
],
|
||||||
"backgroundColor": getColor(),
|
|
||||||
"data": messagesDataTsunamy['project']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "democratie",
|
|
||||||
"backgroundColor": getColor(),
|
|
||||||
"data": messagesDataTsunamy['democraty']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "ecologie",
|
|
||||||
"backgroundColor": getColor(),
|
|
||||||
"data": messagesDataTsunamy['ecology']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "technologie",
|
|
||||||
"backgroundColor": getColor(),
|
|
||||||
"data": messagesDataTsunamy['technology']
|
|
||||||
}],
|
|
||||||
"usersGlobal": usersGlobal
|
"usersGlobal": usersGlobal
|
||||||
}
|
}
|
||||||
|
|
||||||
usersTest = [None] * 12
|
usersTest = [None] * 12
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
channels = rocket.channels_list(offset=index).json()
|
channels = rocket.channels_list(offset=index).json()
|
||||||
totalChannels = channels['total']
|
|
||||||
|
|
||||||
for channel in channels['channels']:
|
for channel in channels['channels']:
|
||||||
dataMess = []
|
dataMess = []
|
||||||
|
@ -123,17 +122,8 @@ while True:
|
||||||
end = begin + monthdelta(1)
|
end = begin + monthdelta(1)
|
||||||
|
|
||||||
color = getColor()
|
color = getColor()
|
||||||
messageByChannel = {
|
messageByChannel = createElement(channel['name'], color,dataMess)
|
||||||
"label": channel['name'],
|
userByChannel = createElement( channel['name'], color,dataUsers)
|
||||||
"backgroundColor": color,
|
|
||||||
"data": dataMess
|
|
||||||
}
|
|
||||||
|
|
||||||
userByChannel = {
|
|
||||||
"label": channel['name'],
|
|
||||||
"backgroundColor": color,
|
|
||||||
"data": dataUsers
|
|
||||||
}
|
|
||||||
|
|
||||||
messagesByChannel.append(messageByChannel)
|
messagesByChannel.append(messageByChannel)
|
||||||
usersByChannel.append(userByChannel)
|
usersByChannel.append(userByChannel)
|
||||||
|
@ -142,23 +132,13 @@ while True:
|
||||||
break
|
break
|
||||||
index += channels['count']
|
index += channels['count']
|
||||||
|
|
||||||
for id in range(0, 12):
|
for id in range(0, 12):
|
||||||
usersTest[id] = len(set(usersTest[id]))
|
usersTest[id] = len(set(usersTest[id]))
|
||||||
|
|
||||||
userGlobal = {
|
userGlobal = createElement( 'global', 'red', usersTest)
|
||||||
"label": 'global',
|
usersGlobal.append(userGlobal)
|
||||||
"backgroundColor": 'red',
|
|
||||||
"data": usersTest
|
|
||||||
}
|
|
||||||
usersGlobal.append(userGlobal)
|
|
||||||
|
|
||||||
# Récupération du répertoire racine du repo
|
save(info)
|
||||||
rootFolder = os.path.join(os.path.dirname(__file__), '..')
|
|
||||||
# Répertoire pour stocker le fichier de sortie
|
|
||||||
dataFolder = os.path.join(rootFolder, 'public', 'data')
|
|
||||||
|
|
||||||
statsFilePath = os.path.abspath(
|
|
||||||
os.path.join(dataFolder, 'channelsstat.json'))
|
|
||||||
with open(statsFilePath, "w") as file_write:
|
|
||||||
json.dump(info, file_write)
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue