Revised error codes and functional PlaybackEngine

All internal and public errors have been revised (GPT 5.6 Sol) to return
more detail without horrendously long error classes, this has reduced
the number of error types but each now carries a reason and a code for
differentiation if needed

PlaybackEngine has been implemented and is functional, core mode changes
what signal descriptors are returned to avoid duplicates, the playback
engine currently discards the derived signals that would be recorded in
the DLPak and derived signals are reprocessed live

Future will require the behavior listed above to be selectable so one of
two options are possible:
A - Derived signals are reprocessed live by the relevant derive units
(current behavior
B - Derived signals are played back directly from the PlaybackEngine,
this requires turning off the routing to the live derive units to avoid
duplicate values

This will also require the option to perform offline processing with
derive units to be able to create derived signals after the fact, this
will likely incur a new 'offline' mode in the core to gate things
correctly, this will likely be useful for heavier processing that cannot
be done live, filters that require a lookahead, or more precise derived
signals using interpolated signals for higher acurracy which also brings
the ability to offline process on a fixed timebase instead of following
either input signal to the derived signal
This commit is contained in:
h3cx committed 2026-09-13 12:26:12 +02:00
1 parent bbc5aac891
commit 9407bfeb79
18 files changed
+1160 -178

No files matched your search

+66
View File
@@ -2,6 +2,7 @@
# Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
# SPDX-License-Identifier: GPL-3.0-or-later
from bisect import bisect_right
from collections import defaultdict
import csv
import io
@@ -46,6 +47,62 @@ class ValueBuffer:
with self._lock:
self._samples.sort(key=lambda sample: sample[0])
def import_csv(self, input: str) -> None:
reader = csv.reader(io.StringIO(input, newline=""))
header = next(reader, None)
if header is None:
raise ValueError("CSV input is empty")
if not header or header[0] != "timestamp_ns":
raise ValueError("The first CSV column must be 'timestamp_ns'")
try:
signal_ids = [UUID(column) for column in header[1:]]
except ValueError as error:
raise ValueError(
"CSV contains an invalid signal UUID in its header"
) from error
if len(signal_ids) != len(set(signal_ids)):
raise ValueError("CSV contains duplicate signal UUID columns")
imported_samples: list[tuple[int, UUID, float]] = []
for line_number, row in enumerate(reader, start=2):
if not row or all(cell == "" for cell in row):
continue
if len(row) != len(header):
raise ValueError(
f"Line {line_number} has {len(row)} columns; expected {len(header)}"
)
try:
timestamp_ns = int(row[0])
except ValueError as error:
raise ValueError(
f"Line {line_number} has an invalid timestamp: {row[0]!r}"
) from error
for signal_id, cell in zip(signal_ids, row[1:]):
if cell == "":
continue
try:
value = float(cell)
except ValueError as error:
raise ValueError(
f"Line {line_number} has an invalid value: {cell!r}"
) from error
imported_samples.append((timestamp_ns, signal_id, value))
imported_samples.sort(key=lambda sample: sample[0])
with self._lock:
self._samples = imported_samples
def export_csv(self) -> str:
with self._lock:
samples = list(self._samples)
@@ -81,3 +138,12 @@ class ValueBuffer:
)
return output.getvalue()
def get_samples_from(self, timestamp: int) -> list[tuple[int, UUID, float]]:
with self._lock:
index = bisect_right(
self._samples,
timestamp,
key=lambda sample: sample[0],
)
return self._samples[index:].copy()