Stats per stream and period, public stats page, dashboard settings, Card alert style
Statistics - Per day and per stream statistics (src/periodstats.js, one generic stat_day table), backfilled once from the older tables; Stream / Week / Month / Year / All time views, Community and Streams tabs. - Viewer count every 5 minutes and title / category history per stream (EventSub channel.update): viewer graph, games played (donut), games in the streams list. - Twitch sync (src/twitchsync.js): followers with follow dates, current subs, mods, VIPs, all-time bits, channel emotes, past streams from VODs. Twitch analytics CSV import (src/twitchcsv.js). - Public stats page on its own host (Settings -> Stats and data): no message text, no bots, !hideme / !showme opt-out. Viewer page: roles, follow age, sub status, bits, a menu for rarely used actions. - StreamElements watch-time importer removed (already imported minutes stay as a baseline). Dashboard - Settings and Actions with a left sidebar; each settings page saves only its own fields. Connections (Twitch, StreamElements token now set here, HUDFX), OBS links (hidden behind an eye toggle) with a link builder, Chat (sound picked from the media library), TTS, Stats and data, Backup (export / import the whole setup), Advanced. Time zone setting for the stats pages. - Actions -> Alerts: alert style, pictures, sounds, bits tiers and card colours, stored in the database (src/theme.js); an old file-based theme is imported once. Alert preview page (/actions/alerts/preview, tools/preview/export.js for a static copy). - Old /actions page removed; Actions = Redeems / Alerts / TTS voices / Media. Alerts - New plain Card style for everyone (public/alerts/card.js); Polaroid, Cassette and the TTS letter stay as optional looks. Redeem variations can be Card, Cassette, Sound only or Video. Repo - No channel data in git: the channel's art, stickers and sounds stay on disk (gitignored) and are picked in the dashboard; examples for the server config (apache.example.sh, .env.example). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5bf4bffaa0
commit
c481ca92cb
57 changed files with 3080 additions and 774 deletions
|
|
@ -1,9 +1,9 @@
|
|||
<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; }
|
||||
.tiles { display:grid; grid-template-columns:repeat(auto-fit, minmax(175px, 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 .v { font-size:1.2rem; font-weight:700; line-height:1.2; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
|
||||
.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; }
|
||||
|
|
@ -12,31 +12,119 @@
|
|||
.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; }
|
||||
.head { display:flex; align-items:flex-start; gap:1rem; }
|
||||
.head h2 { margin:0 0 .2rem; }
|
||||
.roles { display:flex; flex-wrap:wrap; gap:.35rem; margin:.3rem 0 .8rem; align-items:center; }
|
||||
.role { font-size:.72rem; font-weight:700; padding:.12rem .55rem; border-radius:99px; border:1px solid var(--pico-muted-border-color); }
|
||||
.role.broadcaster { background:#7a1a1a; border-color:#7a1a1a; color:#f6c8c8; }
|
||||
.role.moderator { background:#0d5d22; border-color:#0d5d22; color:#b9f0c6; }
|
||||
.role.vip { background:#7a1a6e; border-color:#7a1a6e; color:#f3c4ec; }
|
||||
.role.subscriber, .role.founder { background:#3b2a7a; border-color:#3b2a7a; color:#d6ccff; }
|
||||
/* ⋯ menu: rarely used things (public page, rename, forget) */
|
||||
.more { position:relative; margin-left:auto; }
|
||||
.more > summary { list-style:none; cursor:pointer; padding:.1rem .7rem; border:1px solid var(--pico-muted-border-color); border-radius:8px; font-size:1.2rem; line-height:1.3; }
|
||||
.more > summary::-webkit-details-marker { display:none; }
|
||||
.more > summary::after { display:none !important; }
|
||||
.more .menu { position:absolute; right:0; top:calc(100% + .3rem); z-index:10; width:320px; background:var(--pico-card-background-color);
|
||||
border:1px solid var(--pico-muted-border-color); border-radius:12px; box-shadow:0 10px 24px rgba(0,0,0,.4); padding:.4rem; }
|
||||
.menu form { margin:0; padding:.5rem .55rem; border-bottom:1px solid var(--pico-muted-border-color); }
|
||||
.menu form:last-child { border-bottom:0; }
|
||||
.menu .lbl { display:block; font-size:.78rem; color:var(--pico-muted-color); margin-bottom:.35rem; }
|
||||
.menu .row { display:flex; gap:.4rem; align-items:center; }
|
||||
.menu input { margin:0; padding:.25rem .5rem; font-size:.85rem; height: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>
|
||||
<p class="meta">No statistics for this viewer (yet). Names are Twitch logins, e.g. <code>some_viewer</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 + (viewer.importedMinutes || 0); %>
|
||||
<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>
|
||||
const num = n => Number(n || 0).toLocaleString('en-US');
|
||||
const minutes = (viewer.watch.ticks || 0) * 5 + (viewer.importedMinutes || 0);
|
||||
const tw = viewer.twitch, b = viewer.badges;
|
||||
// how long ago, in words: "2 years 3 months", "5 months", "12 days"
|
||||
const ago = iso => {
|
||||
const a = new Date(iso), n = new Date();
|
||||
let months = (n.getUTCFullYear() - a.getUTCFullYear()) * 12 + n.getUTCMonth() - a.getUTCMonth() - (n.getUTCDate() < a.getUTCDate() ? 1 : 0);
|
||||
if (months < 1) { const d = Math.floor((n - a) / 864e5); return `${d} day${d === 1 ? '' : 's'}`; }
|
||||
const y = Math.floor(months / 12), m = months % 12;
|
||||
return [y ? `${y} y` : '', m ? `${m} mo` : ''].filter(Boolean).join(' ');
|
||||
};
|
||||
const TIER = { 1000: 'Tier 1', 2000: 'Tier 2', 3000: 'Tier 3' };
|
||||
// roles: synced from Twitch (mods / VIPs / subs) + chat badges from their last message (founder, artist, ...)
|
||||
const roles = new Map();
|
||||
const BADGE = { broadcaster: 'Broadcaster', moderator: 'Moderator', vip: 'VIP', founder: 'Founder', 'artist-badge': 'Artist', subscriber: 'Subscriber', 'lead_moderator': 'Lead moderator' };
|
||||
for (const x of b.list) if (BADGE[x.set]) roles.set(x.set, `${BADGE[x.set]} (chat badge${b.at ? `, ${b.at.slice(0, 10)}` : ''})`);
|
||||
for (const r of tw.roles) roles.set(r, `${BADGE[r] || r} (from Twitch)`);
|
||||
if (tw.sub) roles.set('subscriber', `${TIER[tw.sub.tier] || 'Subscriber'}${tw.sub.is_gift ? ` · gifted by ${tw.sub.gifter_name || tw.sub.gifter_login}` : ''} (from Twitch)`);
|
||||
const subMonths = b.subMonths || viewer.given.subMonths || null; %>
|
||||
|
||||
<div class="head">
|
||||
<div>
|
||||
<h2><%= viewer.name %> <span class="meta">@<%= viewer.login %></span></h2>
|
||||
<div class="roles">
|
||||
<a href="https://twitch.tv/<%= encodeURIComponent(viewer.login) %>" target="_blank" rel="noopener" class="meta">twitch.tv/<%= viewer.login %> ↗</a>
|
||||
<span class="role" title="Level by watch time"><%= viewer.level.name %></span>
|
||||
<% for (const [set, tip] of roles) { %><span class="role <%= set %>" title="<%= tip %>"><%= set === 'subscriber' && tw.sub ? (TIER[tw.sub.tier] || 'Sub') + ' sub' : BADGE[set] || set %></span><% } %>
|
||||
<% if (viewer.hidden) { %><span class="role" title="In Settings → Hidden chatters: counted, but not shown in leaderboards">hidden bot</span><% } %>
|
||||
<% if (viewer.publicHidden) { %><span class="role" title="Opted out of the public stats page (!hideme)">not on public page</span><% } %>
|
||||
</div>
|
||||
</div>
|
||||
<details class="more">
|
||||
<summary title="More">⋯</summary>
|
||||
<div class="menu">
|
||||
<form method="POST" action="/stats/viewer/public"
|
||||
title="The public stats page never names viewers who opted out (they typed !hideme in chat, or you set it here). They still count in the totals. !showme brings them back.">
|
||||
<input type="hidden" name="login" value="<%= viewer.login %>">
|
||||
<input type="hidden" name="user_id" value="<%= viewer.user_id || '' %>">
|
||||
<input type="hidden" name="hide" value="<%= viewer.publicHidden ? '0' : '1' %>">
|
||||
<span class="lbl">Public page: <strong><%= viewer.publicHidden ? 'not named (opted out)' : viewer.hidden ? 'not shown (hidden bot)' : 'shown' %></strong> ⓘ</span>
|
||||
<button type="submit" class="outline btn-sm"><%= viewer.publicHidden ? 'Show again' : 'Leave out of the public page' %></button>
|
||||
</form>
|
||||
<% if (viewer.importedMinutes && !viewer.user_id) { %>
|
||||
<form method="POST" action="/stats/viewer/rename"
|
||||
title="This viewer is only known from StreamElements' watch time (by name, from before HeyStreamer counted). If they renamed on Twitch, those minutes move to the new name.">
|
||||
<input type="hidden" name="from" value="<%= viewer.login %>">
|
||||
<span class="lbl">Renamed on Twitch? ⓘ</span>
|
||||
<div class="row"><input name="to" required pattern="@?\w{2,25}" placeholder="new Twitch login"><button type="submit" class="outline btn-sm">Move</button></div>
|
||||
</form>
|
||||
<% } %>
|
||||
<form method="POST" action="/stats/viewer/forget">
|
||||
<input type="hidden" name="login" value="<%= viewer.login %>">
|
||||
<input type="hidden" name="user_id" value="<%= viewer.user_id || '' %>">
|
||||
<span class="lbl" title="For removal requests: deletes all of this viewer's statistics, watch time, stored chat and activity-log entries. Cannot be undone.">Removal request ⓘ</span>
|
||||
<button type="button" data-confirm class="outline btn-sm" style="color:#f88; border-color:#f88;">Forget this viewer</button>
|
||||
</form>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<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" title="<%= viewer.importedMinutes ? `includes ${hm(viewer.importedMinutes)} imported from StreamElements` : '' %>"><div class="v"><%= hm(minutes) %></div><div class="k">watched<%= viewer.importedMinutes ? ' · incl. StreamElements' : '' %></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"><%= num(viewer.total) %></div><div class="k">points</div></div>
|
||||
<div class="tile" title="<%= viewer.importedMinutes ? `includes ${hm(viewer.importedMinutes)} counted by StreamElements before HeyStreamer counted` : '' %>"><div class="v"><%= hm(minutes) %></div><div class="k">watched<%= viewer.importedMinutes ? ' · incl. StreamElements ⓘ' : '' %></div></div>
|
||||
<div class="tile"><div class="v"><%= num(viewer.chat.messages) %></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 class="tile" title="<%= tw.follower ? `Following since ${tw.follower.followed_at.slice(0, 10)}${tw.follower.unfollowed_at ? `; unfollowed around ${tw.follower.unfollowed_at.slice(0, 10)}` : ''}` : 'Not in the follower list from the last sync with Twitch' %>">
|
||||
<div class="v"><%= tw.follower && !tw.follower.unfollowed_at ? ago(tw.follower.followed_at) : tw.follower ? 'unfollowed' : '—' %></div>
|
||||
<div class="k"><%= tw.follower && !tw.follower.unfollowed_at ? `following since ${tw.follower.followed_at.slice(0, 10)}` : 'not following' %> ⓘ</div>
|
||||
</div>
|
||||
<div class="tile" title="<%= tw.sub ? `Subscribed now (${TIER[tw.sub.tier] || tw.sub.tier}${tw.sub.is_gift ? `, gift from ${tw.sub.gifter_name || tw.sub.gifter_login}` : ''})` : 'Not subscribed at the last sync with Twitch' %>. Months come from their sub badge in chat or their resub messages; Twitch has no sub history for other viewers.">
|
||||
<div class="v"><%= tw.sub ? (TIER[tw.sub.tier] || 'Sub') : 'no sub' %><%= subMonths ? ` · ${subMonths} mo` : '' %></div>
|
||||
<div class="k"><%= tw.sub ? (tw.sub.is_gift ? 'gifted sub' : 'subscribed now') : subMonths ? 'subscribed before' : 'subscription' %> ⓘ</div>
|
||||
</div>
|
||||
<div class="tile" title="<%= tw.bits ? `Twitch all-time leaderboard: rank ${tw.bits.rank}` : 'Not in Twitch\'s top 100 all-time cheerers' %>. Counted by HeyStreamer: <%= num(viewer.given.bits) %> bits.">
|
||||
<div class="v"><%= num(Math.max(tw.bits?.score || 0, viewer.given.bits)) %></div><div class="k">bits given<%= tw.bits ? ` · #${tw.bits.rank}` : '' %> ⓘ</div>
|
||||
</div>
|
||||
<div class="tile"><div class="v"><%= num(viewer.given.gifts) %></div><div class="k">subs gifted</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><% } %>
|
||||
<% for (const [k, v] of Object.entries(viewer.parts).sort((a, b) => b[1] - a[1])) { %><span class="part"><%= k %>: <strong><%= num(v) %></strong></span><% } %>
|
||||
</div>
|
||||
<p class="meta" style="margin:.6rem 0 0;">
|
||||
<% if (viewer.chat.first_seen) { %>First chat <%= viewer.chat.first_seen.slice(0, 10) %>, last <%= viewer.chat.last_seen.slice(0, 10) %>.<% } %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<% if (viewer.emotes.length) { %>
|
||||
|
|
@ -67,20 +155,4 @@
|
|||
</tbody>
|
||||
</table>
|
||||
<% } %>
|
||||
|
||||
<% if (viewer.importedMinutes && !viewer.user_id) { %>
|
||||
<form method="POST" action="/stats/viewer/rename" style="display:flex; gap:.5rem; align-items:center; flex-wrap:wrap; margin-top:1.5rem;"
|
||||
title="This viewer is only known from the StreamElements import (by name). If they renamed on Twitch, their imported watch time moves to the new name, and importing again later applies the rename too.">
|
||||
<input type="hidden" name="from" value="<%= viewer.login %>">
|
||||
<span class="meta">Renamed on Twitch? New name:</span>
|
||||
<input name="to" required pattern="@?\w{2,25}" placeholder="new Twitch login" style="width:14rem; margin:0; padding:.25rem .5rem; font-size:.85rem; height:auto;">
|
||||
<button type="submit" class="outline btn-sm">Move</button>
|
||||
</form>
|
||||
<% } %>
|
||||
<form method="POST" action="/stats/viewer/forget" style="margin-top:1rem;">
|
||||
<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>
|
||||
<% } %>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue