/ concept-collection / fastandaccurate
Sign in
concept-collection / fastandaccurate
fastandaccurate / src / app / results.ts
57 lines · 2.2 KBBlameHistoryRaw
1// Committed results live in the fastandaccurate-results repository and are
2// fetched statically: index.json lists the result files, each of which is
3// one work-precision sweep in the format of src/harness/resultSchema.ts.
5import {
6 RESULT_FORMAT,
7 type ResultFile,
8} from "../harness/resultSchema";
10export const RESULTS_REPO_URL =
11 "https://github.com/concept-collection/fastandaccurate-results";
12// The results repo is served by its own GitHub Pages (branch-based, main
13// at /), which is CDN-backed and CORS-open. raw.githubusercontent.com
14// would also work but rate-limits hard enough to break page loads.
15// In dev the vite server serves the sibling checkout instead (see
16// localResultsPlugin in vite.config.ts), so local work sees local
17// results and makes no network requests for them.
18const RESULTS_BASE = import.meta.env.DEV
19 ? "/local-results"
20 : "https://concept-collection.github.io/fastandaccurate-results";
22export function isResultFile(x: unknown): x is ResultFile {
23 const r = x as ResultFile;
24 return (
25 !!r &&
26 r.format === RESULT_FORMAT &&
27 typeof r.problem === "string" &&
28 typeof r.instance === "string" &&
29 !!r.solver &&
30 typeof r.solver.id === "string" &&
31 Array.isArray(r.points)
32 );
35export async function fetchCommittedResults(): Promise<ResultFile[]> {
36 const idxResp = await fetch(`${RESULTS_BASE}/index.json`, { cache: "no-cache" });
37 if (!idxResp.ok) throw new Error(`index.json: HTTP ${idxResp.status}`);
38 const idx = (await idxResp.json()) as { files?: string[] };
39 const files = idx.files ?? [];
40 const results = await Promise.all(
41 files.map(async (f) => {
42 const resp = await fetch(`${RESULTS_BASE}/${f}`, { cache: "no-cache" });
43 if (!resp.ok) return null;
44 const data: unknown = await resp.json();
45 return isResultFile(data) ? data : null;
46 })
47 );
48 return results.filter((r): r is ResultFile => r !== null);
51/** Short human label for the environment a result was measured in. */
52export function environmentLabel(r: ResultFile): string {
53 const env = r.environment;
54 if (env.machineLabel) return `${env.machineLabel} (${env.kind})`;
55 if (env.kind === "browser") return "browser";
56 return `${env.cpu ?? "unknown cpu"} (${env.kind})`;
moveopenescclose