Spaces:
Running
Running
compare modalities over rolling 90-day windows
Browse filesFiles changed (4)
153 unmodified lines154155156157158159159160161160161162163164165166167168169170153 unmodified lines GROUP BY ALL ORDER BY month, modality """, ) # Rolling 90-day windows ending at the data date, so the comparison is always current. data["modalityTotals"] = rows( con, """ SELECT substr(t, 10) AS name, count(*) AS value FROM (SELECT unnest(tags) AS t FROM datasets) f""" SELECT substr(t, 10) AS name, count(*) AS value, count(*) FILTER (WHERE createdAt > TIMESTAMP '{now}' - INTERVAL 90 DAY) AS last90, count(*) FILTER (WHERE createdAt > TIMESTAMP '{now}' - INTERVAL 180 DAY AND createdAt <= TIMESTAMP '{now}' - INTERVAL 90 DAY) AS prev90, count(*) FILTER (WHERE createdAt > TIMESTAMP '{now}' - INTERVAL 455 DAY AND createdAt <= TIMESTAMP '{now}' - INTERVAL 365 DAY) AS ago90 FROM (SELECT createdAt, unnest(tags) AS t FROM datasets) WHERE t LIKE 'modality:%' GROUP BY 1 ORDER BY 2 DESC """, )702 unmodified lines70370470570670770870971070670770871270971071171271371471571671771823 unmodified lines7427437447427437457467467477487497507507517527527537547557566 unmodified lines7637647657657667677667677687697707714 unmodified lines776777778778779780781782702 unmodified lines};const modColor = (name) => MODALITY_COLORS[name] || "var(--other)";const modality = pivot(D.modalityMonthly, "month", "modality", D.modalityTotals.map((d) => d.name));const modalityGrowth = (name) => { const v = modality.values[name], n = v.length; const last3 = v.slice(n - 3).reduce((a, b) => a + b, 0), ago3 = v.slice(n - 15, n - 12).reduce((a, b) => a + b, 0); return ago3 ? last3 / ago3 : 0;};// Last 90 days vs the same 90 days a year earlier; 0 when there's nothing to compare against.const modalityGrowth = (d) => (d.ago90 ? d.last90 / d.ago90 : 0);// Start with the three fastest growers, since the big modalities would flatten them on a shared scale.const modalityPicked = new Set(D.modalityTotals.map((d) => d.name).sort((a, b) => modalityGrowth(b) - modalityGrowth(a)).slice(0, 3));const modalityPicked = new Set([...D.modalityTotals].sort((a, b) => modalityGrowth(b) - modalityGrowth(a)).slice(0, 3).map((d) => d.name));// "Aug 1 β Oct 29" for the 90 days ending `endDaysAgo` days before the data date.function windowLabel(endDaysAgo) { const day = 864e5, end = upd.getTime() - endDaysAgo * day; const f = (t) => new Date(t).toLocaleDateString("en-US", { month: "short", day: "numeric", year: endDaysAgo ? "numeric" : undefined, timeZone: "UTC" }); return `${f(end - 89 * day)} β ${f(end)}`;}
function renderModalityChips() { const box = document.getElementById("modality-chips");23 unmodified lines// Ranked by growth vs a year ago, so small fast-growing modalities aren't buried under text and tabular.function renderModality() { const mod = modality; const n = mod.xs.length; const sum = (v, a, b) => v.slice(a, b).reduce((x, y) => x + y, 0); const rows = D.modalityTotals.map((d) => { const v = mod.values[d.name]; return { name: d.name, total: d.value, v, last3: sum(v, n - 3, n), prev3: sum(v, n - 6, n - 3), ago3: sum(v, n - 15, n - 12) }; return { name: d.name, total: d.value, v, last3: d.last90, prev3: d.prev90, ago3: d.ago90 }; }).filter((r) => r.last3 > 0).sort((a, b) => (b.ago3 ? b.last3 / b.ago3 : Infinity) - (a.ago3 ? a.last3 / a.ago3 : Infinity));
document.getElementById("modality-sub").textContent = `New datasets tagged with each modality in ${monTick(mod.xs[n - 3])} β ${monTick(mod.xs[n - 1])}, ranked by growth vs the same 3 months a year earlier`; `New datasets tagged with each modality in the last 90 days (${windowLabel(0)}), ranked by growth vs the same 90 days a year earlier`; const tb = table(document.getElementById("modality"), [ { t: "Modality" }, { t: "Last 3 mo", cls: "n" }, { t: "vs prior 3 mo", cls: "n" }, { t: "vs year ago", cls: "n" }, { t: "Modality" }, { t: "Last 90 days", cls: "n" }, { t: "vs prior 90", cls: "n" }, { t: "vs year ago", cls: "n" }, { t: "All time", cls: "n opt" }, { t: "Per month, last 24 months Β· own scale", cls: "opt" }, ]); const trends = [];6 unmodified lines el("td", { class: "n opt dim", text: fmtC.format(r.total) }, tr); trends.push([el("td", { class: "trend opt" }, tr), r]); hoverRow(tr, r.name, [ { label: `${monTick(mod.xs[n - 3])} β ${monTick(mod.xs[n - 1])}`, value: fmtInt.format(r.last3), color: modColor(r.name) }, { label: `${monTick(mod.xs[n - 6])} β ${monTick(mod.xs[n - 4])}`, value: fmtInt.format(r.prev3) }, { label: `${monTick(mod.xs[n - 15])} β ${monTick(mod.xs[n - 13])}`, value: fmtInt.format(r.ago3) }, { label: windowLabel(0), value: fmtInt.format(r.last3), color: modColor(r.name) }, { label: windowLabel(90), value: fmtInt.format(r.prev3) }, { label: windowLabel(365), value: fmtInt.format(r.ago3) }, { label: "All time", value: fmtInt.format(r.total) }, ]); }4 unmodified lines } const best = rows.find((r) => r.ago3); document.getElementById("modality-foot").textContent = `Fastest growing: ${best.name}, ${fmtInt.format(best.last3)} new datasets in the last 3 months vs ${fmtInt.format(best.ago3)} a year earlier. Untagged datasets aren't counted.`; `Fastest growing: ${best.name}, ${fmtInt.format(best.last3)} new datasets in the last 90 days vs ${fmtInt.format(best.ago3)} a year earlier. Untagged datasets aren't counted.`;}
// ---------- activity table ----------build/build.py+9-3
index.html
site/template.html+16-15
stats.json