From 86848b6cae751439be2946eae563d3fa8caa434c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 25 Nov 2021 19:39:21 +0100 Subject: Update stat views. --- views/stats.pug | 46 +++++++++++++++++----------------------------- views/user_stats.pug | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 29 deletions(-) create mode 100644 views/user_stats.pug (limited to 'views') diff --git a/views/stats.pug b/views/stats.pug index 7634048..b6c8673 100644 --- a/views/stats.pug +++ b/views/stats.pug @@ -6,40 +6,28 @@ html title Game Statistics style. table { table-layout: fixed; min-width: auto; } + td:not(:nth-child(1)) { text-align: right; } td:nth-child(1) { width: 240px; } td { width: 100px; } - tr.blank { height: 2rem; border: none; } + tr+tr.blank { height: 2rem; border: none; } body include header article h1 Game Statistics table - - - function total(t,s) { - return stats - .filter(entry => entry.title_id === t && entry.scenario === s) - .reduce((acc, entry) => acc + entry.count, 0); - } - function result(t,s,r) { - let info = stats.find(entry => entry.title_id === t && entry.scenario === s && entry.result === r); - return info ? info.count : 0; - } - each title_name, title_id in title_name_map - unless title_name_map[title_id].hidden - - let scenarios = title_rule_map[title_id].scenarios; - - let roles = title_role_map[title_id].concat(["Draw"]); - tr - th= title_name_map[title_id].title_name - each role in roles - th= role - each scenario in scenarios - - let t = total(title_id, scenario); - tr - td #{scenario} (#{t}) - each role in roles - if t > 0 - -let r = result(title_id, scenario, role); - td= Math.round(r * 100 / t) + "%" - else - td - + - function p(t,r) { return r > 0 ? Math.round(r*100/t) + "%" : "" } + - function drawn(x) { return x.total-(x.r1+x.r2+x.r3+x.r4+x.r5+x.r6+x.r7) } + each row in stats + unless row.scenario tr.blank + tr + th= row.title_name + th= row.r1 + th= row.r2 + th Draw + else + tr + td #{row.scenario} (#{row.total}) + td= p(row.total, row.r1) + td= p(row.total, row.r2) + td= p(row.total, drawn(row)) diff --git a/views/user_stats.pug b/views/user_stats.pug new file mode 100644 index 0000000..70211ef --- /dev/null +++ b/views/user_stats.pug @@ -0,0 +1,38 @@ +//- vim:ts=4:sw=4: +- let all_won = 0 +- let all_total = 0 +doctype html +html + head + include head + title Stats for #{who.name} + style td:nth-child(3),td:nth-child(4){text-align:right} + body + include header + article + h1 Stats for #{who.name} + + table(style="min-width:auto") + tr + th Title + th Scenario + th Won + th Total + each row in stats + tr + - all_won += row.won + - all_total += row.total + td= row.title_name + td= row.scenario + td= row.won + td= row.total + tr + th + th + th + th + tr + td + td + td= Math.round(all_won * 100 / all_total) + "%" + td= all_total -- cgit v1.2.3