Skip to content

Commit

Permalink
Add units to datalogger
Browse files Browse the repository at this point in the history
  • Loading branch information
BenediktBurger committed Jan 11, 2024
1 parent f3564c0 commit bb3a17a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyleco/directors/data_logger_director.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions pyleco/management/data_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""

Expand All @@ -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?
Expand Down Expand Up @@ -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,
Expand All @@ -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."""
Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion tests/management/test_data_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
},
},
]

Expand All @@ -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": {},
}


Expand Down

0 comments on commit bb3a17a

Please sign in to comment.