diff --git a/pyleco/directors/data_logger_director.py b/pyleco/directors/data_logger_director.py index 2917f0fa..9ad56139 100644 --- a/pyleco/directors/data_logger_director.py +++ b/pyleco/directors/data_logger_director.py @@ -44,6 +44,7 @@ def __init__(self, actor: str = "dataLogger", **kwargs) -> None: def start_collecting(self, *, variables: Optional[list[str]] = None, + units: Optional[dict[str, Any]] = None, trigger_type: Optional[TriggerTypes] = None, trigger_timeout: Optional[float] = None, trigger_variable: Optional[str] = None, diff --git a/pyleco/management/data_logger.py b/pyleco/management/data_logger.py index 303f4be2..5021339e 100644 --- a/pyleco/management/data_logger.py +++ b/pyleco/management/data_logger.py @@ -99,7 +99,7 @@ class DataLogger(ExtendedMessageHandler): # TODO names tmp: dict[str, list[Any]] = {} # contains all values since last datapoint lists: dict[str, list[Any]] = {} # contains datapoints. - # units: dict[str, Quantity] + units: dict[str, Any] = {} # contains the units of the variables TODO TBD what the value is. last_datapoint: dict[str, Any] = {} last_save_name: str = "" @@ -114,7 +114,6 @@ class DataLogger(ExtendedMessageHandler): def __init__(self, name: str = "DataLoggerN", directory: str = ".", **kwargs) -> None: super().__init__(name=name, **kwargs) self.directory = directory - self.units: dict = {} # TODO later self.publisher = DataPublisher(full_name=name) self.valuing = average # TODO add auto_save functionality? @@ -219,6 +218,7 @@ def last(data: list[Any]) -> Any: # Control def start_collecting(self, *, variables: Optional[list[str]] = None, + units: Optional[dict[str, Any]] = None, trigger_type: Optional[TriggerTypes] = None, trigger_timeout: Optional[float] = None, trigger_variable: Optional[str] = None, @@ -242,6 +242,7 @@ def start_collecting(self, *, self.today = datetime.datetime.now(datetime.timezone.utc).date() self.set_valuing_mode(valuing_mode=valuing_mode) self.setup_variables(self.lists.keys() if variables is None else variables) + self.units = units if units else {} def setup_variables(self, variables: Iterable[str]) -> None: """Subscribe to the variables.""" @@ -346,7 +347,7 @@ def get_configuration(self) -> dict[str, Any]: config['value_repeating'] = self.value_repeating # Header and Variables. config['variables'] = list(self.lists.keys()) - # config['unitsText'] = self.leUnits.text() + config['units'] = self.units # config['autoSave'] = self.actionAutoSave.isChecked() return config diff --git a/tests/management/test_data_logger.py b/tests/management/test_data_logger.py index ebb55c86..40b06feb 100644 --- a/tests/management/test_data_logger.py +++ b/tests/management/test_data_logger.py @@ -342,7 +342,9 @@ def test_json_content(self, saved_file: str): "configuration": {"trigger_type": "variable", "trigger_timeout": 10, "trigger_variable": "test", "valuing_mode": "average", "value_repeating": False, - "variables": ["time", "test", "2", "N1.sender.var"]}, + "variables": ["time", "test", "2", "N1.sender.var"], + "units": {}, + }, }, ] @@ -356,6 +358,7 @@ def test_get_configuration(data_logger: DataLogger): "valuing_mode": "average", "value_repeating": False, "variables": ["time", "test", "2", "N1.sender.var"], + "units": {}, }