Stats: one-time import of StreamElements watch time

seimport.js reads the SE channel from SE_JWT, fetches /kappa/v2/points/<ch>/watchtime
(all pages) into watch_import (login, minutes), replacing any previous import.
Imported minutes count as watch time and watch points (5 per 5 min, merged by
login) on the Stats page, leaderboards and viewer pages. Button on Stats warns that
importing again after our own tracking started double-counts those streams.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-22 17:50:04 +02:00
parent c364e7079b
commit dd0e92c0bb
6 changed files with 95 additions and 5 deletions

View file

@ -29,6 +29,7 @@
.search input, .search button { margin:0; }
.search button { width:auto; }
.empty { color:var(--pico-muted-color); font-size:.85rem; font-style:italic; }
.warn { color:#e6b800; }
</style>
<div style="display:flex; align-items:center; gap:1rem; flex-wrap:wrap;">
@ -44,6 +45,16 @@
· <%= hiddenCount %> hidden bot<%= hiddenCount === 1 ? '' : 's' %> left out ⓘ
</p>
<% if (msg) { %><p class="<%= /failed/i.test(msg) ? 'warn' : '' %>" style="font-weight:600;"><%= msg %></p><% } %>
<% if (se.configured) { %>
<form method="POST" action="/stats/import-se" style="display:flex; gap:.6rem; align-items:center; flex-wrap:wrap; margin:.2rem 0 .8rem;">
<button type="submit" class="outline" style="width:auto; margin:0; padding:.3rem .9rem; font-size:.85rem;"
title="Copies StreamElements' watch time (per viewer) into HeyStreamer once. It counts like our own watch time (5 points per 5 minutes). Importing again replaces the previous import.<%= se.ownTicks ? ' HeyStreamer is already counting watch time itself: StreamElements has counted those streams too, so importing again now counts them twice.' : '' %>">
<%= se.n ? 'Import again from StreamElements' : 'Import watch time from StreamElements' %></button>
<span class="meta"><%= se.n ? `Imported ${se.n} viewers · ${Math.round(se.m / 60)} h on ${String(se.at).slice(0, 10)}` : 'Not imported yet: best done before the first stream HeyStreamer counts.' %>
<% if (se.n && se.ownTicks) { %><span class="warn"> · importing again would double-count streams since then</span><% } %></span>
</form>
<% } %>
<div class="tiles">
<div class="tile"><div class="v"><%= overview.viewers.toLocaleString() %></div><div class="k">viewers seen</div></div>
<div class="tile"><div class="v"><%= overview.messages.toLocaleString() %></div><div class="k">chat messages</div></div>

View file

@ -20,7 +20,7 @@
<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; %>
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><% } %>
@ -30,7 +30,7 @@
<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" 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"><%= viewer.checkins %></div><div class="k">check-ins</div></div>
</div>