Implemented initial DLPak design
Implemented DLPak design with zip storage, DLPak consists of two files, a manifest.json which provides details on the signals, time of recording and currently blank comment field and data.csv which stores all the signals as csv with the nanosecond timestamp and indexed against the signal id
This commit is contained in:
1 parent
ffcea13c0b
commit
1cd6bb695c
4 files changed
+113
-17
No files matched your search
+24
-16
@@ -4,6 +4,7 @@
|
||||
|
||||
from collections import defaultdict
|
||||
import csv
|
||||
import io
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
from uuid import UUID
|
||||
@@ -22,11 +23,15 @@ class ValueBuffer:
|
||||
with self._lock:
|
||||
self._samples.clear()
|
||||
|
||||
def get_signal_ids(self) -> list[UUID]:
|
||||
with self._lock:
|
||||
return list({signal_id for _, signal_id, _ in self._samples})
|
||||
|
||||
def __len__(self) -> int:
|
||||
with self._lock:
|
||||
return len(self._samples)
|
||||
|
||||
def export_csv(self, path: str | Path) -> None:
|
||||
def export_csv(self) -> str:
|
||||
with self._lock:
|
||||
samples = list(self._samples)
|
||||
|
||||
@@ -39,22 +44,25 @@ class ValueBuffer:
|
||||
|
||||
ordered_signal_ids = sorted(signal_ids, key=str)
|
||||
|
||||
with Path(path).open(mode="w", newline="", encoding="utf-8") as file:
|
||||
writer = csv.writer(file)
|
||||
output = io.StringIO(newline="")
|
||||
|
||||
writer = csv.writer(output)
|
||||
|
||||
writer.writerow(
|
||||
["timestamp_ns", *(str(signal_id) for signal_id in ordered_signal_ids)]
|
||||
)
|
||||
|
||||
for timestamp_ns in sorted(rows):
|
||||
timestamp_values = rows[timestamp_ns]
|
||||
|
||||
writer.writerow(
|
||||
["timestamp_ns", *(str(signal_id) for signal_id in ordered_signal_ids)]
|
||||
[
|
||||
timestamp_ns,
|
||||
*(
|
||||
timestamp_values.get(signal_id, "")
|
||||
for signal_id in ordered_signal_ids
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
for timestamp_ns in sorted(rows):
|
||||
timestamp_values = rows[timestamp_ns]
|
||||
|
||||
writer.writerow(
|
||||
[
|
||||
timestamp_ns,
|
||||
*(
|
||||
timestamp_values.get(signal_id, "")
|
||||
for signal_id in ordered_signal_ids
|
||||
),
|
||||
]
|
||||
)
|
||||
return output.getvalue()
|
||||
Reference in new issue
Block a user