From 974834ff11b5420920cb9727a201878dc748ee4f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 18 Jul 2021 16:22:56 +0200 Subject: Improve stats page. --- views/stats.ejs | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'views/stats.ejs') diff --git a/views/stats.ejs b/views/stats.ejs index db497e8..64a6303 100644 --- a/views/stats.ejs +++ b/views/stats.ejs @@ -2,35 +2,36 @@ <% - let total = {}; - let results = {}; - for (let { title_name, scenario, result, count } of stats) { - if (total[title_name] == undefined) - total[title_name] = {}; - if (total[title_name][scenario] == undefined) - total[title_name][scenario] = 0; - total[title_name][scenario] += count; - if (results[title_name] == undefined) - results[title_name] = []; - if (!results[title_name].includes(result)) - results[title_name].push(result); + function total(t, s) { + return stats + .filter(entry => entry.title_id === t && entry.scenario === s) + .reduce((acc, entry) => acc + entry.count, 0); } - let last_title = null; - let last_scenario = null; - for (let { title_name, scenario, result, count } of stats) { - if (title_name != last_title) { - if (last_title != null) { - %><% + function result(t, s, r) { + let info = stats.find(entry => { + return entry.title_id === t && + entry.scenario === s && + entry.result === r}); + return info ? info.count : 0; + } + for (let title_id in title_name_map) { + let scenarios = title_rule_map[title_id].scenarios; + let roles = title_role_map[title_id].concat(['Draw']); + %><% } %>
<%= title_name_map[title_id] %><% + roles.forEach(role => { + %><%= role %><% + }); + scenarios.forEach(scenario => { + let t = total(title_id, scenario); + if (t > 0) { + %>
<%= scenario %> (<%= t %>)<% + roles.forEach(role => { + let r = result(title_id, scenario, role); + %><%= Math.round(r * 100 / t) %>%<% + }); } - %>
<%= title_name %><% - results[title_name].forEach(item => { %><%= item %><% }); - } - if (scenario != last_scenario) { - %>
<%= scenario %> (<%= total[title_name][scenario] %>)<% - } - %><%= Math.round(count * 100 / total[title_name][scenario]) %>%<% - last_title = title_name; - last_scenario = scenario; + }); + %>
-- cgit v1.2.3