Add labels

This commit is contained in:
Mickael 2019-06-08 22:32:24 +02:00
parent a1825bbf10
commit d0d161ab08
3 changed files with 13 additions and 4 deletions

View file

@ -15,9 +15,11 @@ Statistiques du <a href="https://coa.crapaud-fou.org">chat</a> (aussi connu sous
<canvas id="usersByChannel"></canvas> <canvas id="usersByChannel"></canvas>
<script> <script>
updated = "updated 02/05/2019" updated = "updated 02/05/2019"
labels = ["mai 2018","juin 2018","juillet 2018","août 2018","septembre 2018","octobre 2018","novembre 2018","décembre 2018","janvier 2019","février 2019","mars 2019","avril 2019"];
$.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){ $.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (datas){
labels = datas['labels'];
var ctx = document.getElementById('byChannel').getContext('2d'); var ctx = document.getElementById('byChannel').getContext('2d');
var chart = new Chart(ctx, { var chart = new Chart(ctx, {
// The type of chart we want to create // The type of chart we want to create
@ -26,7 +28,7 @@ $.getJSON("{{ site.baseurl }}/public/data/messagesByChannel.json", function (dat
// The data for our dataset // The data for our dataset
data: { data: {
labels: labels, labels: labels,
datasets: datas, datasets: datas['messagesByChannel'],
}, },
// Configuration options go here // Configuration options go here

File diff suppressed because one or more lines are too long

View file

@ -21,6 +21,7 @@ def getColor():
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='https://coa.crapaud-fou.org')
index = 0 index = 0
labels = [None] * 12
messagesByChannel = [] messagesByChannel = []
now = datetime.now() now = datetime.now()
@ -36,6 +37,7 @@ while True:
begin = date - monthdelta(12) begin = date - monthdelta(12)
end = begin + monthdelta(1) end = begin + monthdelta(1)
for id in range(0, 12): for id in range(0, 12):
labels[id] = begin.strftime("%b %Y")
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()
@ -60,8 +62,13 @@ rootFolder = os.path.join(os.path.dirname(__file__), '..')
# Répertoire pour stocker le fichier de sortie # Répertoire pour stocker le fichier de sortie
dataFolder = os.path.join(rootFolder, 'public', 'data') dataFolder = os.path.join(rootFolder, 'public', 'data')
info = {
"labels": labels,
"messagesByChannel": messagesByChannel
}
statsFilePath = os.path.abspath( statsFilePath = os.path.abspath(
os.path.join(dataFolder, 'messagesByChannel.json')) os.path.join(dataFolder, 'messagesByChannel.json'))
with open(statsFilePath, "w") as file_write: with open(statsFilePath, "w") as file_write:
json.dump(messagesByChannel, file_write) json.dump(info, file_write)