Index: leahi_dialin/td/modules/events.py =================================================================== diff -u -r862daa5b6357ddaba02aa7d1fb9d0952e4a16e6f -r6caa49d072aceb2655d605de5d2eea52ab1a8911 --- leahi_dialin/td/modules/events.py (.../events.py) (revision 862daa5b6357ddaba02aa7d1fb9d0952e4a16e6f) +++ leahi_dialin/td/modules/events.py (.../events.py) (revision 6caa49d072aceb2655d605de5d2eea52ab1a8911) @@ -17,8 +17,10 @@ # Module imports from logging import Logger from datetime import datetime -from typing import Tuple +import time +from typing import Tuple, Union + # Project imports from leahi_dialin.common import td_enum_repository from leahi_dialin.common.generic_defs import DataTypes @@ -72,9 +74,8 @@ td_enum_repository.TDTreatmentStates.TREATMENT_PAUSED_STATE.name:td_enum_repository.TDTreaPausedStates, td_enum_repository.TDTreatmentStates.TREATMENT_RINSEBACK_STATE.name:td_enum_repository.TDTreaRinsebackStates, td_enum_repository.TDTreatmentStates.TREATMENT_RECIRC_STATE.name:td_enum_repository.TDTreaRecircStates, - td_enum_repository.TDTreatmentStates.TREATMENT_SALINE_BOLUS_STATE.name:td_enum_repository.TDTreaBolusStates, - td_enum_repository.TDTreatmentStates.TREATMENT_HEPARIN_STATE.name:td_enum_repository.TDTreaHeparinStates, - td_enum_repository.TDTreatmentStates.TREATMENT_END_STATE.name:td_enum_repository.TDTreaEndStates } + td_enum_repository.TDTreatmentStates.TREATMENT_END_STATE.name:td_enum_repository.TDTreaEndStates, + td_enum_repository.TDTreatmentStates.TREATMENT_SALINE_BOLUS_STATE.name:td_enum_repository.TDTreaBolusStates } # Dictionary of the state as key and the sub state enum class as the value self._state_2_sub_states = {td_enum_repository.TDPreTreaSampleWaterStates.SAMPLE_WATER_STATE.name: td_enum_repository.TDPreTreaSamplWaterUserActionStates, @@ -89,6 +90,7 @@ self._event_dictionary = dict() for event in td_enum_repository.TDEventList: self._event_dictionary[td_enum_repository.TDEventList(event).name] = [] + self.handler_execution_times = [] @@ -104,6 +106,7 @@ @param message: published TD events data message @returns none """ + start = time.perf_counter() event_id = LocalVars('event_id') data_typ_1 = LocalVars('data_typ_1') data_1 = LocalVars('data_1') @@ -236,6 +239,7 @@ # Update event dictionary self._event_dictionary[event_enum.name].append(event_tuple) self.events_timestamp = timestamp + self.handler_execution_times.append((timestamp, message, time.perf_counter() - start)) @@ -299,25 +303,34 @@ return list_of_events - def _operation_status_match(self, op_mode: int, sub_mode: int=None, state:int=None, sub_state: int=None) -> Tuple[DialinEnum, DialinEnum, DialinEnum, DialinEnum]: + def _operation_status_match(self, op_mode: int, sub_mode: int=None, state:int=None, sub_state: int=None) -> Tuple[DialinEnum, Union[DialinEnum, int], Union[DialinEnum, int], Union[DialinEnum, int]]: """ Convert operation status values to enums. :param op_mode: (Integer) The operation mode value :param sub_mode: (Integer) The operation sub mode value :param state: (Integer) The operation state value :param sub_state: (Integer) The operation sub state value - :return: Returns the DialinEnum for each provied mode/state + :return: Returns the DialinEnum for each provied mode/state, or the original integer value if no enum is found """ op_mode_enum = td_enum_repository.TDOpModes(op_mode) sub_mode_enum = None state_enum = None sub_state_enum = None if sub_mode is not None: - sub_mode_enum = self._op_mode_2_sub_mode[op_mode_enum.name](sub_mode) + if op_mode_enum.name not in self._op_mode_2_sub_mode: + sub_mode_enum = sub_mode + else: + sub_mode_enum = self._op_mode_2_sub_mode[op_mode_enum.name](sub_mode) if state is not None: - state_enum = self._sub_mode_2_states[sub_mode_enum.name](state) + if sub_mode_enum.name not in self._sub_mode_2_states: + state_enum = state + else: + state_enum = self._sub_mode_2_states[sub_mode_enum.name](state) if sub_state is not None: - sub_state_enum = self._state_2_sub_states[state_enum.name](sub_state) + if state_enum.name not in self._state_2_sub_states: + sub_state_enum = sub_state + else: + sub_state_enum = self._state_2_sub_states[state_enum.name](sub_state) return op_mode_enum, sub_mode_enum, state_enum, sub_state_enum