This contains the initial DeriveUnit implementation, including signature validation, this initial implentation only supports ValueDescriptors in the signature alongside the SignalDescriptor and returns a single ValueDescriptor The worker thread still needs to be defined and started but the offline processing has already been validate to work as a first prototype
42 lines
924 B
Python
42 lines
924 B
Python
from uuid import uuid4
|
|
from dynalab_core.derive import DeriveUnit
|
|
from dynalab_core.protocols.packets.data import ValueDescriptor
|
|
from dynalab_core.protocols.packets.handshake import SignalDescriptor
|
|
|
|
|
|
def process(
|
|
a: ValueDescriptor,
|
|
b: ValueDescriptor,
|
|
r: SignalDescriptor,
|
|
) -> ValueDescriptor:
|
|
val = ValueDescriptor(
|
|
signal_id=r.id, value=a.value + b.value, timestamp=a.timestamp
|
|
)
|
|
return val
|
|
|
|
|
|
sig_a = SignalDescriptor(
|
|
id=uuid4(),
|
|
name="Signal A",
|
|
type="number",
|
|
)
|
|
|
|
sig_b = SignalDescriptor(
|
|
id=uuid4(),
|
|
name="Signal A",
|
|
type="number",
|
|
)
|
|
|
|
sig_r = SignalDescriptor(
|
|
id=uuid4(),
|
|
name="Signal R",
|
|
type="number",
|
|
)
|
|
|
|
unit = DeriveUnit(uuid4(), process, [sig_a, sig_b], sig_r)
|
|
|
|
val_a = ValueDescriptor(signal_id=sig_a.id, value=1, timestamp=0)
|
|
val_b = ValueDescriptor(signal_id=sig_a.id, value=2, timestamp=10)
|
|
|
|
print(unit.process_offline([val_a, val_b]))
|