From e65239e53bf7f9ce53ec0157fe41fad94beea682 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 18 May 2021 23:51:32 +0200 Subject: server: Add a /stats page to show game result statistics. --- views/stats.ejs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 views/stats.ejs (limited to 'views/stats.ejs') diff --git a/views/stats.ejs b/views/stats.ejs new file mode 100644 index 0000000..db497e8 --- /dev/null +++ b/views/stats.ejs @@ -0,0 +1,36 @@ +<%- include('header', { title: "Game Statistics" }) -%> + + +<% + 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); + } + 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) { + %><% + } + %>
<%= 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