Source code for vent.common.message

from enum import Enum, auto
from vent.common import values
from itertools import count
from copy import copy


[docs]class SensorValueNew: def __init__(self, name, value, timestamp, loop_counter): self.name = name self.value = value self.timestamp = timestamp self.loop_counter = loop_counter
[docs]class SensorValues:
[docs] def __init__(self, timestamp=None, loop_counter=None, **kwargs): """ Args: **kwargs: sensor readings, must be in :data:`vent.values.SENSOR.keys` """ # init self.timestamp = timestamp self.loop_counter = loop_counter # init all sensor values to none # use __members__ as the keys are strings rather than enums for key in values.ValueName.__members__.keys(): setattr(self, key, None) # assign kwargs as attributes, # check that all the kwargs are in values.SENSOR for key, value in kwargs.items(): if (key in values.ValueName.__members__.keys()): setattr(self, key, copy(value)) else: raise KeyError(f'value {key} not declared in vent.values!!!')
[docs] def to_dict(self): return { valname: getattr(self,valname.name) for valname in values.ValueName }
[docs]class ControlSetting:
[docs] def __init__(self, name, value, min_value, max_value, timestamp): """ TODO: if enum is hard to use, we may just use a predefined set, e.g. {'PIP', 'PEEP', ...} :param name: enum belong to ValueName :param value: :param min_value: :param max_value: :param timestamp: """ self.name = name self.value = value self.min_value = min_value self.max_value = max_value self.timestamp = timestamp
[docs]class AlarmSeverity(Enum): RED = 3 ORANGE = 2 YELLOW = 1 OFF = 0
[docs]class Alarm: id_counter = count() """ :class:`itertools.count`: used to generate unique IDs for each alarm """
[docs] def __init__(self, alarm_name, is_active, severity, alarm_start_time, alarm_end_time,value=None, message=None): """ Args: alarm_name : is_active: severity: alarm_start_time: alarm_end_time: value (int, float): optional - numerical value that generated the alarm message (str): optional - override default text generated by :class:`~vent.gui.alarm_manager.AlarmManager` """ self.id = next(Alarm.id_counter) self.alarm_name = alarm_name self.is_active = is_active self.severity = severity self.alarm_start_time = alarm_start_time self.alarm_end_time = alarm_end_time self.value = value self.message = message
[docs]class Error: def __init__(self, errnum, err_str, timestamp): self.errnum = errnum self.err_str = err_str self.timestamp = timestamp