diff --git a/fdsreader/devc/device.py b/fdsreader/devc/device.py index 85e5bf0..c01c22e 100644 --- a/fdsreader/devc/device.py +++ b/fdsreader/devc/device.py @@ -1,4 +1,4 @@ -from typing import Tuple, Union +from typing import Tuple, Union, List from fdsreader.utils import Quantity @@ -19,6 +19,7 @@ def __init__(self, device_id: str, quantity: Quantity, position: Tuple[float, fl self.position = position self.orientation = orientation self._data_callback = lambda: None + self._activation_times: List[Tuple[float, bool]]= [] @property def data(self): @@ -47,6 +48,21 @@ def xyz(self): """Alias for :class:`Device`.position. """ return self.position + + @property + def activation_times(self): + """Alias for :class:`Device`._activation_times. + """ + return self._activation_times + + def add_activation_time(self, activation: Tuple[float, bool]): + """Adds an activation time to the list of activation times + + Args: + activation (Tuple[float, bool]): The activation time to track. Tuple should contain the time of activation (float) and the activation state (bool) + """ + self._activation_times.append(activation) + self._activation_times.sort(key=lambda activation: activation[0]) # Sort the list of times by time def clear_cache(self): """Remove all data from the internal cache that has been loaded so far to free memory. diff --git a/fdsreader/simulation.py b/fdsreader/simulation.py index e0692b2..4deced1 100644 --- a/fdsreader/simulation.py +++ b/fdsreader/simulation.py @@ -23,7 +23,6 @@ from fdsreader import settings from fdsreader._version import __version__ - class Simulation: """Master class managing all data for a given simulation. @@ -249,6 +248,17 @@ def parse_smv_file(self): self._devices[device_id] = [self._devices[device_id], device] else: self._devices[device_id] = device + elif keyword.startswith("DEVICE_ACT"): + device_id = line.replace("DEVICE_ACT", "").strip() + # Device should always be defined, as DEVICE_ACT appears after all DEVICE lines in smv + device = self._devices[device_id] + + data_line = smv_file.readline().strip() + data = list(filter(None, data_line.split(" "))) + + _, time, value = data + value = bool(int(value)) + device.add_activation_time((time, value)) elif keyword.startswith("SLC"): self._load_slice(smv_file, keyword) elif keyword.startswith("BNDS"):