Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions site/scripts/build-history.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ const TRACKED = "site/public/v1/index.json";
const OUT = resolve(SITE_DIR, "public/v1/history.json");
const REPO_URL = "https://github.com/GetTechAPI/TechAPI";

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

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

Expand Down
16 changes: 11 additions & 5 deletions site/src/scripts/techapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ async function loadList(resource) {
(function stats() {
const el = document.getElementById("stats");
if (!el) return;
const order = ["games", "software", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "socs", "gpus", "cpus", "brands"];
const order = ["games", "software", "websites", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "device-catalog", "socs", "gpus", "cpus", "brands"];
const label = {
games: "games",
software: "software",
websites: "websites",
"device-catalog": "device catalog",
smartphones: "phones",
laptops: "laptops",
tablets: "tablets",
Expand Down Expand Up @@ -244,10 +246,12 @@ function countUp(node, target, opts = {}) {
const listEl = document.getElementById("history-list");
if (!totalEl || !countsEl || !chartEl || !listEl) return;

const order = ["games", "software", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "socs", "gpus", "cpus", "brands"];
const order = ["games", "software", "websites", "smartphones", "laptops", "tablets", "monitors", "watches", "pdas", "device-catalog", "socs", "gpus", "cpus", "brands"];
const label = {
games: "Games",
software: "Software",
websites: "Websites",
"device-catalog": "Device catalog",
smartphones: "Phones",
laptops: "Laptops",
tablets: "Tablets",
Expand All @@ -263,6 +267,8 @@ function countUp(node, target, opts = {}) {
const shortLabel = {
games: "games",
software: "software",
websites: "websites",
"device-catalog": "device catalog",
smartphones: "phones",
laptops: "laptops",
tablets: "tablets",
Expand Down Expand Up @@ -295,7 +301,7 @@ function countUp(node, target, opts = {}) {
const total = rows.reduce((sum, row) => sum + row.count, 0);
totalEl.textContent = total.toLocaleString() + " records";
countsEl.innerHTML = rows.map((row) =>
`<div class="history-count"><span>${label[row.key]}</span><b>${row.count.toLocaleString()}</b></div>`
`<div class="history-count"><span>${label[row.key] || row.key}</span><b>${row.count.toLocaleString()}</b></div>`
).join("");
}

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