Stats page: overview, activity per day, leaderboards, top emotes/commands, viewer lookup

/stats (dashboard nav): totals, chat messages and watch hours per day (30 days,
single-series bar charts with hover), leaderboards for points (with level), watch
time, chat, bits, channel points spent; top emotes (with images) and commands.
/stats/viewer?q=: one viewer's points breakdown, watch time, messages, check-ins,
emotes, commands, actions, and 'Forget this viewer' (removal requests: stats, watch
time, raw chat, activity log). Bots (Hidden chatters) left out of everything shown.
src/points.js: the agreed point values in one place, calculated from the stats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-22 17:40:05 +02:00
parent 1c36e80f66
commit c364e7079b
6 changed files with 383 additions and 0 deletions

77
views/stats_viewer.ejs Normal file
View file

@ -0,0 +1,77 @@
<style>
.meta { color:var(--pico-muted-color); font-size:.85rem; }
.card { border:1px solid var(--pico-muted-border-color); border-radius:12px; padding:.8rem 1rem; margin-bottom:1rem; }
.tiles { display:grid; grid-template-columns:repeat(auto-fit, minmax(140px, 1fr)); gap:.6rem; }
.tile { border:1px solid var(--pico-muted-border-color); border-radius:12px; padding:.6rem .8rem; }
.tile .v { font-size:1.5rem; font-weight:700; line-height:1.1; }
.tile .k { font-size:.8rem; color:var(--pico-muted-color); }
.parts { display:flex; flex-wrap:wrap; gap:.4rem; margin-top:.6rem; }
.part { border:1px solid var(--pico-muted-border-color); border-radius:99px; padding:.1rem .6rem; font-size:.8rem; }
.emotes { display:flex; flex-wrap:wrap; gap:.4rem; }
.emote { display:flex; align-items:center; gap:.3rem; border:1px solid var(--pico-muted-border-color); border-radius:99px; padding:.1rem .55rem .1rem .25rem; font-size:.8rem; }
.emote img { width:24px; height:24px; object-fit:contain; }
table { font-size:.85rem; }
.btn-sm { margin:0; padding:.25rem .7rem; font-size:.8rem; width:auto; }
</style>
<p><a href="/stats">← Stats</a></p>
<% if (!viewer) { %>
<h2><%= q %></h2>
<p class="meta">No statistics for this viewer (yet). Names are Twitch logins, e.g. <code>channel</code>.</p>
<% } else {
const hm = m => m >= 60 ? `${Math.floor(m / 60)} h ${m % 60} m` : `${m} m`;
const minutes = (viewer.watch.ticks || 0) * 5; %>
<h2 style="margin-bottom:.2rem;"><%= viewer.name %> <span class="meta">@<%= viewer.login %></span></h2>
<p class="meta"><%= viewer.level.name %>
<% if (viewer.hidden) { %> · <span class="badge badge-grey" title="In Settings → Hidden chatters: counted, but not shown in leaderboards">hidden bot</span><% } %>
<% if (viewer.chat.first_seen) { %> · first chat <%= viewer.chat.first_seen.slice(0, 10) %>, last <%= viewer.chat.last_seen.slice(0, 10) %><% } %>
</p>
<div class="card">
<div class="tiles">
<div class="tile"><div class="v"><%= viewer.total.toLocaleString() %></div><div class="k">points</div></div>
<div class="tile"><div class="v"><%= hm(minutes) %></div><div class="k">watched</div></div>
<div class="tile"><div class="v"><%= (viewer.chat.messages || 0).toLocaleString() %></div><div class="k">chat messages</div></div>
<div class="tile"><div class="v"><%= viewer.checkins %></div><div class="k">check-ins</div></div>
</div>
<div class="parts" title="Where the points come from (values in docs/PLANS.md)">
<% for (const [k, v] of Object.entries(viewer.parts).sort((a, b) => b[1] - a[1])) { %><span class="part"><%= k %>: <strong><%= v.toLocaleString() %></strong></span><% } %>
</div>
</div>
<% if (viewer.emotes.length) { %>
<h4>Emotes</h4>
<div class="emotes" style="margin-bottom:1rem;">
<% for (const e of viewer.emotes) {
const src = e.source === 'twitch' && e.emote_id ? `https://static-cdn.jtvnw.net/emoticons/v2/${e.emote_id}/default/dark/1.0`
: e.source === '7tv' && e.emote_id ? `https://cdn.7tv.app/emote/${e.emote_id}/1x.webp` : null; %>
<span class="emote"><% if (src) { %><img src="<%= src %>" alt="" loading="lazy"><% } %><%= e.emote %> <strong><%= e.uses %></strong></span>
<% } %>
</div>
<% } %>
<% if (viewer.commands.length) { %>
<h4>Commands</h4>
<div class="emotes" style="margin-bottom:1rem;"><% for (const c of viewer.commands) { %><span class="emote" style="padding-left:.55rem;"><code><%= c.command %></code> <strong><%= c.uses %></strong></span><% } %></div>
<% } %>
<% if (viewer.actions.length) { %>
<h4>Actions</h4>
<table>
<thead><tr><th>Action</th><th>What</th><th>Times</th><th>Total</th><th>Last</th></tr></thead>
<tbody>
<% for (const a of viewer.actions) { %>
<tr><td><%= a.action.replace(/_/g, ' ') %></td><td><%= a.item %></td><td><%= a.uses %></td>
<td><%= a.unit ? `${(+a.amount).toLocaleString()} ${a.unit}` : '' %></td><td><small><%= (a.last_at || '').slice(0, 10) %></small></td></tr>
<% } %>
</tbody>
</table>
<% } %>
<form method="POST" action="/stats/viewer/forget" style="margin-top:1.5rem;">
<input type="hidden" name="login" value="<%= viewer.login %>">
<input type="hidden" name="user_id" value="<%= viewer.user_id || '' %>">
<button type="button" data-confirm class="outline btn-sm" style="color:#f88; border-color:#f88;"
title="For removal requests: deletes all of this viewer's statistics, watch time, stored chat and activity-log entries. Cannot be undone.">Forget this viewer</button>
</form>
<% } %>