meshviz-studio-decentralize.../meshviz/interop.py

30 lines
972 B
Python

from typing import Dict, List, Tuple, Any
class CatOptInterop:
"""Lightweight interoperability bridge to map MeshViz primitives to a
canonical intermediate representation (CatOpt-like).
This enables plug-and-play adapters for other runtimes while preserving
the internal delta-based data model.
"""
@staticmethod
def delta_state_to_intermediate(
state: Dict[str, List[Tuple[float, float, str]]]
) -> Dict[str, List[Dict[str, Any]]]:
"""Convert internal delta state into a serializable intermediate form.
Example output:
{
"dev1": [ {"ts": 1.0, "value": 5.5, "delta_id": "<uuid>"}, ... ],
...
}
"""
result: Dict[str, List[Dict[str, Any]]] = {}
for device, entries in state.items():
result[device] = [
{"ts": ts, "value": val, "delta_id": did}
for (ts, val, did) in entries
]
return result