From 469a350223f4bc14e285f0c19a36640b3a8bb967 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sun, 14 Feb 2016 00:26:15 +0100 Subject: [PATCH] stats-web: Added 3 most said word by user --- stats-web/index.html | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/stats-web/index.html b/stats-web/index.html index bfd737d..9e10fb8 100644 --- a/stats-web/index.html +++ b/stats-web/index.html @@ -42,9 +42,9 @@ #totalmsg { text-align: center; padding-bottom: 1rem; } #usermsg i { font-size: 0.8rem; font-style: normal; } #usermsg tr:nth-child(even) { background-color: #fafafa; } - #usermsg td { text-align: center; padding: 0.3rem 0; } + #usermsg td { text-align: center; padding: 0.3rem 0; word-break: break-word; } #usermsg th { padding: 0.3rem 0.5rem; } - #usermsg td:first-child { text-align: left; padding: 0.3rem 0.6rem; } + #usermsg td:first-child, #usermsg td:nth-child(4) { text-align: left; padding: 0.3rem 0.6rem; } canvas { width: 100%; } @@ -87,9 +87,10 @@ - + +
NicknameNickname Messaggi totali % dei messaggiMamo
@@ -108,8 +109,9 @@ req([ Qapi("https://stats.crunchy.rocks/stats"), Qapi("https://stats.crunchy.rocks/users"), + Qapi("https://stats.crunchy.rocks/words"), Qready - ], function(stats, users) { + ], function(stats, users, words) { var font = "'Source Sans Pro', sans-serif"; Chart.defaults.global.defaultFontFamily = font; Chart.defaults.global.legend.labels.fontFamily = font; @@ -223,9 +225,25 @@ document.getElementById("totalcount").innerHTML = stats.TotalCount; /* User stats */ - function percent(a){return Math.round(a/stats.TotalCount*1e4)/1e2;} + + // Count words + var userFreq = {}; + for (w in words) { + for (user in words[w]) { + if (!userFreq[user]) { + userFreq[user] = []; + } + userFreq[user].push([w, words[w][user]]); + } + } + for (user in userFreq) { + userFreq[user].sort(); + } + + function formatwords(n){return userFreq[n]?userFreq[n].slice(0,3).map(function(i){return i[0]}).join(", "):""} + function percent(a){return Math.round(a/stats.TotalCount*1e4)/1e2} function nick(a){return users[a]?users[a]+" ("+a+")":a} - function enrich(a){return [nick(a[0]), a[1], percent(a[1])]} + function enrich(a){return [nick(a[0]), a[1], percent(a[1]), formatwords(a[0])]} function append(a){usertable.appendChild(a)} var userlist = toArray(stats.ByUserCount).sort(sortMessages); var usertable = document.getElementById("usermsg");