From 0621a9c145fd86adde2637bfe52b23f14e4e9223 Mon Sep 17 00:00:00 2001 From: nrage Date: Fri, 21 Nov 2025 00:45:15 -0500 Subject: [PATCH 1/3] Add parsing for Device Activation times --- fdsreader/devc/device.py | 15 ++++++++++++++- fdsreader/simulation.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/fdsreader/devc/device.py b/fdsreader/devc/device.py index 85e5bf0..4d7e714 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]] | None = None @property def data(self): @@ -47,6 +48,18 @@ 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]): + if self._activation_times == None: + self._activation_times = [] + 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"): From a3548b98c6cffeb9c357cf63a55d50b1a7d8f1a9 Mon Sep 17 00:00:00 2001 From: nrage Date: Fri, 21 Nov 2025 00:48:54 -0500 Subject: [PATCH 2/3] Add docstring --- fdsreader/devc/device.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fdsreader/devc/device.py b/fdsreader/devc/device.py index 4d7e714..08c4509 100644 --- a/fdsreader/devc/device.py +++ b/fdsreader/devc/device.py @@ -56,6 +56,11 @@ def activation_times(self): 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) + """ if self._activation_times == None: self._activation_times = [] self._activation_times.append(activation) From d6767f0b9bd79c375692b4e7ae068f4d40cf84ad Mon Sep 17 00:00:00 2001 From: nrage Date: Fri, 21 Nov 2025 00:58:15 -0500 Subject: [PATCH 3/3] Add null safety to activation times property --- fdsreader/devc/device.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fdsreader/devc/device.py b/fdsreader/devc/device.py index 08c4509..c01c22e 100644 --- a/fdsreader/devc/device.py +++ b/fdsreader/devc/device.py @@ -19,7 +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]] | None = None + self._activation_times: List[Tuple[float, bool]]= [] @property def data(self): @@ -61,8 +61,6 @@ def add_activation_time(self, activation: Tuple[float, bool]): Args: activation (Tuple[float, bool]): The activation time to track. Tuple should contain the time of activation (float) and the activation state (bool) """ - if self._activation_times == None: - self._activation_times = [] self._activation_times.append(activation) self._activation_times.sort(key=lambda activation: activation[0]) # Sort the list of times by time