Skip to content

Commit c8f555a

Browse files
committed
fix(site): count every collection in the growth chart
build-history.mjs summed only the 8 collections the dump had in June, so the chart's latest point said 108,509 records while the API serves 213,487. It now counts all 13 manifest collections, including laptops, monitors, software, websites and the device catalog, and no longer prints git's "fatal:" for the commit that stopped tracking the manifest. The homepage also had no label for websites or device-catalog, so their history rows read "undefined". Both are labelled now, and any future collection falls back to its key. Refs #19
1 parent b3f438a commit c8f555a

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

‎site/scripts/build-history.mjs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ const TRACKED = "site/public/v1/index.json";
2626
const OUT = resolve(SITE_DIR, "public/v1/history.json");
2727
const REPO_URL = "https://github.com/GetTechAPI/TechAPI";
2828

29-
// Categories we sum into the record total (matches the public dump manifest).
30-
const ORDER = ["smartphones", "tablets", "watches", "pdas", "socs", "gpus", "cpus", "brands"];
29+
// Categories we sum into the record total: every collection in the public dump
30+
// manifest (v1/index.json). Old manifests that predate a collection just lack it.
31+
const ORDER = [
32+
"smartphones", "tablets", "laptops", "monitors", "watches", "pdas", "socs", "gpus", "cpus",
33+
"brands", "software", "websites", "device-catalog",
34+
];
3135
// The data/ folder behind each of those collections.
3236
const DATA_DIR = {
33-
smartphones: "smartphone", tablets: "tablet", watches: "watch", pdas: "pda",
34-
socs: "soc", gpus: "gpu", cpus: "cpu", brands: "brand",
37+
smartphones: "smartphone", tablets: "tablet", laptops: "laptop", monitors: "monitor",
38+
watches: "watch", pdas: "pda", socs: "soc", gpus: "gpu", cpus: "cpu", brands: "brand",
39+
software: "software", websites: "website", "device-catalog": "device_catalog",
3540
};
3641
// Keep the chart legible if the history ever grows large: downsample to at most
3742
// MAX points, always preserving the first (baseline) and last (latest) commits.
@@ -41,9 +46,12 @@ const MAX = 40;
4146
const DATA_MAX = 20;
4247

4348
function git(args) {
49+
// stderr is captured, not printed: a commit without the manifest (such as the
50+
// one that stopped committing it) is skipped, not a "fatal:" line in the log.
4451
return execFileSync("git", ["-C", REPO_ROOT, ...args], {
4552
encoding: "utf8",
4653
maxBuffer: 64 * 1024 * 1024,
54+
stdio: ["ignore", "pipe", "pipe"],
4755
});
4856
}
4957

‎site/src/scripts/techapi.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@ async function loadList(resource) {
179179
(function stats() {
180180
const el = document.getElementById("stats");
181181
if (!el) return;
182-
const order = ["games", "software", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "socs", "gpus", "cpus", "brands"];
182+
const order = ["games", "software", "websites", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "device-catalog", "socs", "gpus", "cpus", "brands"];
183183
const label = {
184184
games: "games",
185185
software: "software",
186+
websites: "websites",
187+
"device-catalog": "device catalog",
186188
smartphones: "phones",
187189
laptops: "laptops",
188190
tablets: "tablets",
@@ -244,10 +246,12 @@ function countUp(node, target, opts = {}) {
244246
const listEl = document.getElementById("history-list");
245247
if (!totalEl || !countsEl || !chartEl || !listEl) return;
246248

247-
const order = ["games", "software", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "socs", "gpus", "cpus", "brands"];
249+
const order = ["games", "software", "websites", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "device-catalog", "socs", "gpus", "cpus", "brands"];
248250
const label = {
249251
games: "Games",
250252
software: "Software",
253+
websites: "Websites",
254+
"device-catalog": "Device catalog",
251255
smartphones: "Phones",
252256
laptops: "Laptops",
253257
tablets: "Tablets",
@@ -263,6 +267,8 @@ function countUp(node, target, opts = {}) {
263267
const shortLabel = {
264268
games: "games",
265269
software: "software",
270+
websites: "websites",
271+
"device-catalog": "device catalog",
266272
smartphones: "phones",
267273
laptops: "laptops",
268274
tablets: "tablets",
@@ -295,7 +301,7 @@ function countUp(node, target, opts = {}) {
295301
const total = rows.reduce((sum, row) => sum + row.count, 0);
296302
totalEl.textContent = total.toLocaleString() + " records";
297303
countsEl.innerHTML = rows.map((row) =>
298-
`<div class="history-count"><span>${label[row.key]}</span><b>${row.count.toLocaleString()}</b></div>`
304+
`<div class="history-count"><span>${label[row.key] || row.key}</span><b>${row.count.toLocaleString()}</b></div>`
299305
).join("");
300306
}
301307

@@ -355,7 +361,7 @@ function countUp(node, target, opts = {}) {
355361
// max-height) so the full history stays reachable without a giant section.
356362
listEl.innerHTML = points.slice().reverse().map((point) => {
357363
const changes = point.changes.length
358-
? point.changes.map((row) => `${shortLabel[row.key]} ${formatDelta(row.delta)}`).join(", ")
364+
? point.changes.map((row) => `${shortLabel[row.key] || row.key} ${formatDelta(row.delta)}`).join(", ")
359365
: (point.baseline ? "baseline snapshot" : `total ${formatDelta(point.delta)}`);
360366
const tag = shortTitle(point.title);
361367
const delta = point.baseline ? "baseline" : formatDelta(point.delta);
@@ -392,7 +398,7 @@ function countUp(node, target, opts = {}) {
392398
hDot.style.left = px + "px";
393399
hDot.style.top = py + "px";
394400
const chg = p.changes && p.changes.length
395-
? p.changes.map((row) => `${shortLabel[row.key]} ${formatDelta(row.delta)}`).join(", ")
401+
? p.changes.map((row) => `${shortLabel[row.key] || row.key} ${formatDelta(row.delta)}`).join(", ")
396402
: "";
397403
hTip.innerHTML = `<b>${esc(p.when)}</b>` +
398404
`<span>${p.total.toLocaleString()} records</span>` +

0 commit comments

Comments
 (0)