Updated observers and Kalman Filter, added running average

This commit is contained in:
dario
2024-04-19 10:52:34 +02:00
parent 8b80a6d9d5
commit 475270e1a1
21 changed files with 20865 additions and 3544 deletions

View File

@@ -106,19 +106,27 @@ class Simulation:
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.
def add_observer(self, observer_or_attributes: List[str] | Observer) -> Observer:
"""Register a new observer for this simulation.
Args:
attributes (List[str]): A list of strings describing the attributes to observe.
observer_or_attributes (List[str] | Observer): A list of strings describing the attributes to observe
or a custom observer class.
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."
assert isinstance(observer_or_attributes, list) or issubclass(observer_or_attributes, Observer)
self.__sensors.append(Observer(self.__dataset, self.__logger, attributes))
if isinstance(observer_or_attributes, list):
attributes = observer_or_attributes
assert len(attributes) != 0, "Observed attributes list must be nonempty."
self.__sensors.append(Observer(self.__dataset, self.__logger, attributes))
else:
observer = observer_or_attributes
self.__sensors.append(observer(self.__dataset, self.__logger))
return self.__sensors[-1]