feat(history): align units and history data

This commit is contained in:
2026-09-14 12:30:57 +08:00
parent 35b6819459
commit 08ddb4453d
21 changed files with 1849 additions and 3618 deletions
+35
View File
@@ -0,0 +1,35 @@
import { toTimeSeriesPoints, type ElementHistorySeries } from "./elementHistory";
describe("element history display conversion", () => {
it("converts every series through the shared unit utility", () => {
const series: ElementHistorySeries[] = [
{
element_id: "P-1",
element_type: "pipe",
device_id: null,
metric: "flow",
source: "realtime_simulation",
source_unit: "MLD",
display_unit: "m³/h",
unit_inferred: false,
points: [{ time: "2026-09-01T00:00:00Z", value: 2 }],
},
{
element_id: "J-1",
element_type: "junction",
device_id: "pressure-1",
metric: "pressure",
source: "scada_cleaned",
source_unit: "KPA",
display_unit: "m",
unit_inferred: false,
points: [{ time: "2026-09-01T00:00:00Z", value: 10 }],
},
];
const points = toTimeSeriesPoints(series);
expect(points[0].timestamp).toBe("2026-09-01T00:00:00Z");
expect(points[0].values["P-1_sim"]).toBeCloseTo(83.3333333334);
expect(points[0].values["pressure-1_clean"]).toBeCloseTo(1.019716213);
});
});