Added observers for tracking data

This commit is contained in:
dario
2023-12-13 11:18:23 +01:00
parent 22d6280123
commit b331e9b27a
7 changed files with 240 additions and 167 deletions

View File

@@ -8,6 +8,7 @@ from spatz.sensors import Sensor
from spatz.dataset import Dataset
from spatz.logger import Logger
from spatz.sensors import Sensor
from spatz.observer import Observer
class UniformTimeSteps:
@@ -89,11 +90,34 @@ class Simulation:
return self
def add_sensor(self, sensor, *args, **kwargs) -> Sensor:
"""Register a new sensor for this simulation. A registered sensor can be called like a function and returns
the current measurements. The class' constructor arguments have to be given aswell.
Args:
sensor (_type_): A subclass of the abstract Sensor class.
Returns:
Sensor: Returns an object of the provided sensor subclass.
"""
assert issubclass(sensor, Sensor), "Expected a subclass of Sensor."
self.__sensors.append(sensor(self.__dataset, self.__logger, *args, **kwargs))
return self.__sensors[-1]
def add_observer(self, attributes: List[str]) -> Observer:
"""Register a new observer for this simulation observing the provided attributes.
Args:
attributes (List[str]): A list of strings describing the attributes to observe.
Returns:
Observer: An observer object which can be called like a function to obtain the desired data.
"""
assert len(attributes) != 0, "Observed attributes list must be nonempty."
self.__sensors.append(Observer(self.__dataset, self.__logger, attributes))
return self.__sensors[-1]