cfahlgren1 HF Staff commited on
Commit
8afd64c
·
verified ·
1 Parent(s): 0ef846f

compare modalities over rolling 90-day windows

Browse files
Files changed (4) hide show
  1. build/build.py +9 -3
  2. index.html +0 -0
  3. site/template.html +16 -15
  4. stats.json +0 -0
build/build.py CHANGED
@@ -154,11 +154,17 @@ def compute(con: duckdb.DuckDBPyConnection) -> dict:
154
  GROUP BY ALL ORDER BY month, modality
155
  """,
156
  )
 
157
  data["modalityTotals"] = rows(
158
  con,
159
- """
160
- SELECT substr(t, 10) AS name, count(*) AS value
161
- FROM (SELECT unnest(tags) AS t FROM datasets)
 
 
 
 
 
162
  WHERE t LIKE 'modality:%' GROUP BY 1 ORDER BY 2 DESC
163
  """,
164
  )
 
154
  GROUP BY ALL ORDER BY month, modality
155
  """,
156
  )
157
+ # Rolling 90-day windows ending at the data date, so the comparison is always current.
158
  data["modalityTotals"] = rows(
159
  con,
160
+ f"""
161
+ SELECT substr(t, 10) AS name, count(*) AS value,
162
+ count(*) FILTER (WHERE createdAt > TIMESTAMP '{now}' - INTERVAL 90 DAY) AS last90,
163
+ count(*) FILTER (WHERE createdAt > TIMESTAMP '{now}' - INTERVAL 180 DAY
164
+ AND createdAt <= TIMESTAMP '{now}' - INTERVAL 90 DAY) AS prev90,
165
+ count(*) FILTER (WHERE createdAt > TIMESTAMP '{now}' - INTERVAL 455 DAY
166
+ AND createdAt <= TIMESTAMP '{now}' - INTERVAL 365 DAY) AS ago90
167
+ FROM (SELECT createdAt, unnest(tags) AS t FROM datasets)
168
  WHERE t LIKE 'modality:%' GROUP BY 1 ORDER BY 2 DESC
169
  """,
170
  )
index.html CHANGED
The diff for this file is too large to render. See raw diff
 
site/template.html CHANGED
@@ -703,13 +703,16 @@ const MODALITY_COLORS = {
703
  };
704
  const modColor = (name) => MODALITY_COLORS[name] || "var(--other)";
705
  const modality = pivot(D.modalityMonthly, "month", "modality", D.modalityTotals.map((d) => d.name));
706
- const modalityGrowth = (name) => {
707
- const v = modality.values[name], n = v.length;
708
- 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);
709
- return ago3 ? last3 / ago3 : 0;
710
- };
711
  // Start with the three fastest growers, since the big modalities would flatten them on a shared scale.
712
- const modalityPicked = new Set(D.modalityTotals.map((d) => d.name).sort((a, b) => modalityGrowth(b) - modalityGrowth(a)).slice(0, 3));
 
 
 
 
 
 
713
 
714
  function renderModalityChips() {
715
  const box = document.getElementById("modality-chips");
@@ -739,17 +742,15 @@ function renderModalityChart() {
739
  // Ranked by growth vs a year ago, so small fast-growing modalities aren't buried under text and tabular.
740
  function renderModality() {
741
  const mod = modality;
742
- const n = mod.xs.length;
743
- const sum = (v, a, b) => v.slice(a, b).reduce((x, y) => x + y, 0);
744
  const rows = D.modalityTotals.map((d) => {
745
  const v = mod.values[d.name];
746
- 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) };
747
  }).filter((r) => r.last3 > 0).sort((a, b) => (b.ago3 ? b.last3 / b.ago3 : Infinity) - (a.ago3 ? a.last3 / a.ago3 : Infinity));
748
 
749
  document.getElementById("modality-sub").textContent =
750
- `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`;
751
  const tb = table(document.getElementById("modality"), [
752
- { t: "Modality" }, { t: "Last 3 mo", cls: "n" }, { t: "vs prior 3 mo", cls: "n" }, { t: "vs year ago", cls: "n" },
753
  { t: "All time", cls: "n opt" }, { t: "Per month, last 24 months · own scale", cls: "opt" },
754
  ]);
755
  const trends = [];
@@ -762,9 +763,9 @@ function renderModality() {
762
  el("td", { class: "n opt dim", text: fmtC.format(r.total) }, tr);
763
  trends.push([el("td", { class: "trend opt" }, tr), r]);
764
  hoverRow(tr, r.name, [
765
- { label: `${monTick(mod.xs[n - 3])} – ${monTick(mod.xs[n - 1])}`, value: fmtInt.format(r.last3), color: modColor(r.name) },
766
- { label: `${monTick(mod.xs[n - 6])} – ${monTick(mod.xs[n - 4])}`, value: fmtInt.format(r.prev3) },
767
- { label: `${monTick(mod.xs[n - 15])} – ${monTick(mod.xs[n - 13])}`, value: fmtInt.format(r.ago3) },
768
  { label: "All time", value: fmtInt.format(r.total) },
769
  ]);
770
  }
@@ -775,7 +776,7 @@ function renderModality() {
775
  }
776
  const best = rows.find((r) => r.ago3);
777
  document.getElementById("modality-foot").textContent =
778
- `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.`;
779
  }
780
 
781
  // ---------- activity table ----------
 
703
  };
704
  const modColor = (name) => MODALITY_COLORS[name] || "var(--other)";
705
  const modality = pivot(D.modalityMonthly, "month", "modality", D.modalityTotals.map((d) => d.name));
706
+ // Last 90 days vs the same 90 days a year earlier; 0 when there's nothing to compare against.
707
+ const modalityGrowth = (d) => (d.ago90 ? d.last90 / d.ago90 : 0);
 
 
 
708
  // Start with the three fastest growers, since the big modalities would flatten them on a shared scale.
709
+ const modalityPicked = new Set([...D.modalityTotals].sort((a, b) => modalityGrowth(b) - modalityGrowth(a)).slice(0, 3).map((d) => d.name));
710
+ // "Aug 1 – Oct 29" for the 90 days ending `endDaysAgo` days before the data date.
711
+ function windowLabel(endDaysAgo) {
712
+ const day = 864e5, end = upd.getTime() - endDaysAgo * day;
713
+ const f = (t) => new Date(t).toLocaleDateString("en-US", { month: "short", day: "numeric", year: endDaysAgo ? "numeric" : undefined, timeZone: "UTC" });
714
+ return `${f(end - 89 * day)} – ${f(end)}`;
715
+ }
716
 
717
  function renderModalityChips() {
718
  const box = document.getElementById("modality-chips");
 
742
  // Ranked by growth vs a year ago, so small fast-growing modalities aren't buried under text and tabular.
743
  function renderModality() {
744
  const mod = modality;
 
 
745
  const rows = D.modalityTotals.map((d) => {
746
  const v = mod.values[d.name];
747
+ return { name: d.name, total: d.value, v, last3: d.last90, prev3: d.prev90, ago3: d.ago90 };
748
  }).filter((r) => r.last3 > 0).sort((a, b) => (b.ago3 ? b.last3 / b.ago3 : Infinity) - (a.ago3 ? a.last3 / a.ago3 : Infinity));
749
 
750
  document.getElementById("modality-sub").textContent =
751
+ `New datasets tagged with each modality in the last 90 days (${windowLabel(0)}), ranked by growth vs the same 90 days a year earlier`;
752
  const tb = table(document.getElementById("modality"), [
753
+ { t: "Modality" }, { t: "Last 90 days", cls: "n" }, { t: "vs prior 90", cls: "n" }, { t: "vs year ago", cls: "n" },
754
  { t: "All time", cls: "n opt" }, { t: "Per month, last 24 months · own scale", cls: "opt" },
755
  ]);
756
  const trends = [];
 
763
  el("td", { class: "n opt dim", text: fmtC.format(r.total) }, tr);
764
  trends.push([el("td", { class: "trend opt" }, tr), r]);
765
  hoverRow(tr, r.name, [
766
+ { label: windowLabel(0), value: fmtInt.format(r.last3), color: modColor(r.name) },
767
+ { label: windowLabel(90), value: fmtInt.format(r.prev3) },
768
+ { label: windowLabel(365), value: fmtInt.format(r.ago3) },
769
  { label: "All time", value: fmtInt.format(r.total) },
770
  ]);
771
  }
 
776
  }
777
  const best = rows.find((r) => r.ago3);
778
  document.getElementById("modality-foot").textContent =
779
+ `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.`;
780
  }
781
 
782
  // ---------- activity table ----------
stats.json CHANGED
The diff for this file is too large to render. See raw diff