127 lines
7.4 KiB
TypeScript
127 lines
7.4 KiB
TypeScript
import { Asset } from "expo-asset";
|
|
|
|
export type V4CommandResult = "ACCEPTED" | "REJECTED";
|
|
|
|
type RequiredPlane = Readonly<{
|
|
semanticID: number;
|
|
valueClass: "SCALAR" | "VELOCITY_COMPONENT" | "DIRECTION_ANGLE" | "VALIDITY";
|
|
unitID: number;
|
|
groupID: number;
|
|
component: "NONE" | "U_EAST" | "V_NORTH" | "W_UP";
|
|
requiredFlag: boolean;
|
|
}>;
|
|
|
|
export type V4Dataset = Readonly<{
|
|
id: "wind" | "wave" | "current" | "rain";
|
|
title: string;
|
|
fieldKey: string;
|
|
profileContract: Readonly<{
|
|
contractSchemaVersion: 1;
|
|
profileID: string;
|
|
profileVersion: 1;
|
|
allowAdditionalPlanes: boolean;
|
|
sharedValidityRequired: boolean;
|
|
timeRelation: "VALID_GTE_REFERENCE";
|
|
requiredPlanes: readonly RequiredPlane[];
|
|
}>;
|
|
frames: readonly V4Frame[];
|
|
midpointMs: number;
|
|
colorBinding: Readonly<{
|
|
fieldKey: string;
|
|
semanticID: number;
|
|
groupID: number;
|
|
expectedValueClass: "SCALAR" | "VELOCITY_COMPONENT" | "DIRECTION_ANGLE";
|
|
expectedUnitID: number;
|
|
}>;
|
|
particleBinding?: Readonly<{
|
|
fieldKey: string;
|
|
mode: "VECTOR_COMPONENTS" | "DIRECTION_ANGLE";
|
|
uPlane?: Readonly<{ semanticID: number; groupID: number }>;
|
|
vPlane?: Readonly<{ semanticID: number; groupID: number }>;
|
|
directionPlane?: Readonly<{ semanticID: number; groupID: number }>;
|
|
expectedUnitID: number;
|
|
}>;
|
|
particleNote: string;
|
|
}>;
|
|
|
|
export type V4Frame = Readonly<{
|
|
label: "T0" | "T1";
|
|
validTimeMs: number;
|
|
metadata: Readonly<{ fieldID: string; generation: number; dataVersion: number }>;
|
|
assetModule: number;
|
|
sourceRelativePath: string;
|
|
bytes: number;
|
|
sha256: string;
|
|
}>;
|
|
|
|
const sharedValidity: RequiredPlane = {
|
|
semanticID: 3, valueClass: "VALIDITY", unitID: 0, groupID: 0, component: "NONE", requiredFlag: true,
|
|
};
|
|
const vectorPlanes: readonly RequiredPlane[] = [
|
|
{ semanticID: 1, valueClass: "VELOCITY_COMPONENT", unitID: 1, groupID: 1, component: "U_EAST", requiredFlag: true },
|
|
{ semanticID: 2, valueClass: "VELOCITY_COMPONENT", unitID: 1, groupID: 1, component: "V_NORTH", requiredFlag: true },
|
|
sharedValidity,
|
|
];
|
|
const wavePlanes: readonly RequiredPlane[] = [
|
|
{ semanticID: 10, valueClass: "DIRECTION_ANGLE", unitID: 4, groupID: 0, component: "NONE", requiredFlag: true },
|
|
{ semanticID: 20, valueClass: "SCALAR", unitID: 2, groupID: 0, component: "NONE", requiredFlag: true },
|
|
{ semanticID: 21, valueClass: "SCALAR", unitID: 3, groupID: 0, component: "NONE", requiredFlag: true },
|
|
sharedValidity,
|
|
];
|
|
const rainPlanes: readonly RequiredPlane[] = [
|
|
{ semanticID: 30, valueClass: "SCALAR", unitID: 5, groupID: 0, component: "NONE", requiredFlag: true },
|
|
sharedValidity,
|
|
];
|
|
|
|
function contract(profileID: string, requiredPlanes: readonly RequiredPlane[]) {
|
|
return {
|
|
contractSchemaVersion: 1 as const,
|
|
profileID,
|
|
profileVersion: 1 as const,
|
|
allowAdditionalPlanes: true,
|
|
sharedValidityRequired: true,
|
|
timeRelation: "VALID_GTE_REFERENCE" as const,
|
|
requiredPlanes,
|
|
};
|
|
}
|
|
|
|
function frame(label: "T0" | "T1", fieldID: string, validTimeMs: number, assetModule: number, sourceRelativePath: string, bytes: number, sha256: string): V4Frame {
|
|
const revision = label === "T0" ? 1 : 2;
|
|
return { label, validTimeMs, metadata: { fieldID, generation: revision, dataVersion: revision }, assetModule, sourceRelativePath, bytes, sha256 };
|
|
}
|
|
|
|
const windFrames = [
|
|
frame("T0", "fixture-wind", 1789239600000, require("../assets/qbin-golden/wind/T0.qbin"), "wind/frames/2026091219.qbin", 1627552, "aca8408cc8f723fe8e92ae6ce7695edcb3482167d1eb00d516812f97a70f6371"),
|
|
frame("T1", "fixture-wind", 1789243200000, require("../assets/qbin-golden/wind/T1.qbin"), "wind/frames/2026091220.qbin", 1627552, "cb3b46c5857ba258a7e0804c9fed5c76f481e567b88131c2d98cfe9c5e7d5adb"),
|
|
] as const;
|
|
const waveFrames = [
|
|
frame("T0", "fixture-wave", 1789239600000, require("../assets/qbin-golden/wave/T0.qbin"), "wave/frames/2026091219.qbin", 2416592, "ffe43ce36529602bbfbabc0c15742502aadf4277fa0201cfa93d90327fb3bad3"),
|
|
frame("T1", "fixture-wave", 1789243200000, require("../assets/qbin-golden/wave/T1.qbin"), "wave/frames/2026091220.qbin", 2416592, "28463578cab1dbf9b30949ae9ea1780441c9b396e63a8a1ebd0a13090c222a8d"),
|
|
] as const;
|
|
const currentFrames = [
|
|
frame("T0", "fixture-current", 1789174800000, require("../assets/qbin-golden/current/T0.qbin"), "tide/frames/2026091201.qbin", 1085824, "20bf1f261550ce160b533e6929db66b95d287e8f93b10b3ce9cedb6d8cd37b9f"),
|
|
frame("T1", "fixture-current", 1789178400000, require("../assets/qbin-golden/current/T1.qbin"), "tide/frames/2026091202.qbin", 1085824, "849c3c451dd6b6b810aa519e2c5dedead6ce2804b84c05b0fb6fd03c737eb30a"),
|
|
] as const;
|
|
const rainFrames = [
|
|
frame("T0", "fixture-rain", 1789239600000, require("../assets/qbin-golden/rain/T0.qbin"), "rain/frames/2026091219.qbin", 559440, "c25b6a967af030f7cef9ea790d692a7cf298be4cb5691aaa453dc753c5f2e237"),
|
|
frame("T1", "fixture-rain", 1789243200000, require("../assets/qbin-golden/rain/T1.qbin"), "rain/frames/2026091220.qbin", 559440, "bc030558e9304cd3a883cedbb15fbbe036508669491a7894c8b6f8aef7a35793"),
|
|
] as const;
|
|
|
|
const vectorColor = (fieldKey: string) => ({ fieldKey, semanticID: 1, groupID: 1, expectedValueClass: "VELOCITY_COMPONENT" as const, expectedUnitID: 1 });
|
|
const vectorParticle = (fieldKey: string) => ({ fieldKey, mode: "VECTOR_COMPONENTS" as const, uPlane: { semanticID: 1, groupID: 1 }, vPlane: { semanticID: 2, groupID: 1 }, expectedUnitID: 1 });
|
|
|
|
/** Frozen WeatherV2 QBIN V2 manifest projected into the frozen V4 public contract. */
|
|
export const qbinGoldenDatasets: readonly V4Dataset[] = [
|
|
{ id: "wind", title: "Wind QBIN Golden (wind/1)", fieldKey: "fixture.wind", profileContract: contract("wind", vectorPlanes), frames: windFrames, midpointMs: 1789241400000, colorBinding: vectorColor("fixture.wind"), particleBinding: vectorParticle("fixture.wind"), particleNote: "U ColorBinding (VELOCITY_COMPONENT); U/V particle vectors." },
|
|
{ id: "wave", title: "Wave QBIN Golden (wave/1)", fieldKey: "fixture.wave", profileContract: contract("wave", wavePlanes), frames: waveFrames, midpointMs: 1789241400000, colorBinding: { fieldKey: "fixture.wave", semanticID: 20, groupID: 0, expectedValueClass: "SCALAR", expectedUnitID: 2 }, particleBinding: { fieldKey: "fixture.wave", mode: "DIRECTION_ANGLE", directionPlane: { semanticID: 10, groupID: 0 }, expectedUnitID: 4 }, particleNote: "WAVE_HEIGHT color; DIRECTION angle particle (no direction conversion)." },
|
|
{ id: "current", title: "Current QBIN Golden (current/1)", fieldKey: "fixture.current", profileContract: contract("current", vectorPlanes), frames: currentFrames, midpointMs: 1789176600000, colorBinding: vectorColor("fixture.current"), particleBinding: vectorParticle("fixture.current"), particleNote: "U ColorBinding (VELOCITY_COMPONENT); U/V particle vectors." },
|
|
{ id: "rain", title: "Rain QBIN Golden (rain/1)", fieldKey: "fixture.rain", profileContract: contract("rain", rainPlanes), frames: rainFrames, midpointMs: 1789241400000, colorBinding: { fieldKey: "fixture.rain", semanticID: 30, groupID: 0, expectedValueClass: "SCALAR", expectedUnitID: 5 }, particleNote: "Particle N/A: fixture has no particle-compatible plane." },
|
|
] as const;
|
|
|
|
export async function materializeV4Frame(input: V4Frame): Promise<V4Frame & { qbinFileUri: string }> {
|
|
const asset = Asset.fromModule(input.assetModule);
|
|
await asset.downloadAsync();
|
|
if (!asset.localUri?.startsWith("file://")) throw new Error(`${input.label} QBIN asset did not materialize a local file:// URI`);
|
|
return { ...input, qbinFileUri: asset.localUri };
|
|
}
|