File size: 2,298 Bytes
e3714c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { buildSeriesFromSensorFrames, detectEvents } from "../eventDetection";
import {
SOTAC_PROFILE,
SOTAC_SCREEN_REFERENCE_PATH,
withScreenReference,
} from "../rigProfile";
import { SCREEN_DIMS, type ScreenReference } from "../signalScreen";
// B1 of Jingyi's PR B list: "move the corpus out of src and load it from the
// per dataset profile". The profile names the file; the resolvers attach it.
function loadShipped(): ScreenReference {
return JSON.parse(
readFileSync(
join(
import.meta.dir,
"..",
"..",
"..",
"public",
SOTAC_SCREEN_REFERENCE_PATH.slice(1),
),
"utf-8",
),
) as ScreenReference;
}
describe("reference corpus by path", () => {
test("the shipped corpus is where the sotac profile says, in the screen's feature space", () => {
const ref = loadShipped();
expect(ref.vectors.length).toBeGreaterThan(50);
expect(ref.scaler.mean.length).toBe(SCREEN_DIMS);
expect(ref.vectors[0].v.length).toBe(SCREEN_DIMS);
});
test("withScreenReference attaches without mutating the profile", () => {
const ref = loadShipped();
const p = withScreenReference(SOTAC_PROFILE, ref);
expect(p.calibration.screenReference).toBe(ref);
expect(SOTAC_PROFILE.calibration.screenReference).toBeNull();
expect(p.calibration.weakAttemptMaxN).toBe(
SOTAC_PROFILE.calibration.weakAttemptMaxN,
);
});
test("a profile that names a corpus it did not get flags no_screen_reference", () => {
const frames: unknown[] = [];
const ts: number[] = [];
for (let i = 0; i < 8; i++) {
frames.push([[[0, 0, 0]], [[0, 0, 0]]]);
ts.push(i / 30);
}
const series = buildSeriesFromSensorFrames(
frames,
ts,
null,
null,
SOTAC_PROFILE,
);
const bare = detectEvents(series!, null, {}, null, {
profile: SOTAC_PROFILE,
});
expect(bare.flags).toContain("no_screen_reference");
const loaded = detectEvents(series!, null, {}, null, {
profile: withScreenReference(SOTAC_PROFILE, loadShipped()),
});
expect(loaded.flags).not.toContain("no_screen_reference");
});
});
|