From 90dc0ecb06dc1f0cc72206b24e3ba7e016c933d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81sgeir=20Thor=20Johnson?= Date: Thu, 18 Jun 2026 23:06:44 +0000 Subject: [PATCH] Fix misleading star-gain stat label The stargazers timestamp API caps at 40k (oldest-first), leaving a multi-week gap between the backfilled per-day curve and today's appended total. The 7-day lookback landed in that gap and labeled a 36-day delta as 'last 7d'. Now label the gain by its true span; self-heals to 7d as daily points accumulate. --- .github/scripts/accumulate-traffic.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/scripts/accumulate-traffic.py b/.github/scripts/accumulate-traffic.py index 7ccc692..3a26785 100644 --- a/.github/scripts/accumulate-traffic.py +++ b/.github/scripts/accumulate-traffic.py @@ -255,13 +255,18 @@ const dayCount = Math.round((Date.now() - sinceStart.getTime()) / 86400000); const starSeries = (DATA.stars_series||[]).slice().sort((a,b)=>a.date.localeCompare(b.date)); const curStars = starSeries.length ? starSeries[starSeries.length-1].stars : null; -// stars gained over the trailing 7 days (find the snapshot ~7 days back) -let starGain7 = null; +// stars gained over the trailing ~7 days. The backfill ends at the API's +// 40k-stargazer cap, so early on there's a multi-week gap before today's +// point — label the gain by its TRUE span so it never claims "7d" for a +// 36-day delta. Self-heals to "7d" once daily points fill in. +let starGain = null, starGainDays = 0; if (starSeries.length > 1) { - const cutoff = new Date(starSeries[starSeries.length-1].date); cutoff.setDate(cutoff.getDate()-7); + const lastDate = new Date(starSeries[starSeries.length-1].date); + const cutoff = new Date(lastDate); cutoff.setDate(cutoff.getDate()-7); let base = starSeries[0]; for (const p of starSeries) { if (new Date(p.date) <= cutoff) base = p; } - starGain7 = curStars - base.stars; + starGain = curStars - base.stars; + starGainDays = Math.round((lastDate - new Date(base.date)) / 86400000) || 1; } const statCards = [ @@ -271,7 +276,7 @@ const statCards = [ { l:'Peak Day', v:fmt(peakView.count), s:peakView.timestamp.slice(0,10) }, { l:'7-Day Trend', v:`${trend>=0?'+':''}${trend}%`, s:fmt(last7)+' vs '+fmt(prev7) }, ]; -if (curStars != null) statCards.splice(2, 0, { l:'GitHub Stars', v:'★ '+fmt(curStars), s: starGain7!=null ? `${starGain7>=0?'+':''}${fmt(starGain7)} last 7d` : ' ' }); +if (curStars != null) statCards.splice(2, 0, { l:'GitHub Stars', v:'★ '+fmt(curStars), s: starGain!=null ? `${starGain>=0?'+':''}${fmt(starGain)} last ${starGainDays}d` : ' ' }); document.getElementById('stats').innerHTML = statCards.map(s=>`
${s.l}
${s.v}
${s.s}
${s.t?`
${s.t}
`:''}
`).join('');