diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-05-18 23:51:32 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2021-05-19 01:16:00 +0200 |
commit | e65239e53bf7f9ce53ec0157fe41fad94beea682 (patch) | |
tree | d40016a5d41a7e88bb47163c05aa3d07e0645f89 /views/stats.ejs | |
parent | 216c4053f4e27d98958151e7dd9bd2894166889b (diff) | |
download | server-e65239e53bf7f9ce53ec0157fe41fad94beea682.tar.gz |
server: Add a /stats page to show game result statistics.
Diffstat (limited to 'views/stats.ejs')
-rw-r--r-- | views/stats.ejs | 36 |
1 files changed, 36 insertions, 0 deletions
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" }) -%> +<style>tr.blank{height:2rem;border:none;}</style> +<table class="wide"> +<% + 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) { + %><tr class="blank"><% + } + %><tr><th><%= title_name %><% + results[title_name].forEach(item => { %><th><%= item %><% }); + } + if (scenario != last_scenario) { + %><tr><td><%= scenario %> (<%= total[title_name][scenario] %>)<% + } + %><td><%= Math.round(count * 100 / total[title_name][scenario]) %>%<% + last_title = title_name; + last_scenario = scenario; + } +%> +</table> |