/ concept-collection / fastandaccurate
Sign in
concept-collection / fastandaccurate
fastandaccurate / src / app / results.ts
50 lines · 1.8 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";
12const RESULTS_RAW =
13 "https://raw.githubusercontent.com/concept-collection/fastandaccurate-results/main";
15export function isResultFile(x: unknown): x is ResultFile {
16 const r = x as ResultFile;
17 return (
18 !!r &&
19 r.format === RESULT_FORMAT &&
20 typeof r.problem === "string" &&
21 typeof r.instance === "string" &&
22 !!r.solver &&
23 typeof r.solver.id === "string" &&
24 Array.isArray(r.points)
25 );
28export async function fetchCommittedResults(): Promise<ResultFile[]> {
29 const idxResp = await fetch(`${RESULTS_RAW}/index.json`, { cache: "no-cache" });
30 if (!idxResp.ok) throw new Error(`index.json: HTTP ${idxResp.status}`);
31 const idx = (await idxResp.json()) as { files?: string[] };
32 const files = idx.files ?? [];
33 const results = await Promise.all(
34 files.map(async (f) => {
35 const resp = await fetch(`${RESULTS_RAW}/${f}`, { cache: "no-cache" });
36 if (!resp.ok) return null;
37 const data: unknown = await resp.json();
38 return isResultFile(data) ? data : null;
39 })
40 );
41 return results.filter((r): r is ResultFile => r !== null);
44/** Short human label for the environment a result was measured in. */
45export function environmentLabel(r: ResultFile): string {
46 const env = r.environment;
47 if (env.machineLabel) return `${env.machineLabel} (${env.kind})`;
48 if (env.kind === "node") return `${env.cpu ?? "unknown cpu"} (node)`;
49 return "browser";
moveopenescclose