alarm

Main Alarm Module

Classes

AlarmSeverity

An enumeration.

AlarmType

An enumeration.

class vent.alarm.AlarmType[source]

An enumeration.

Attributes

HIGH_O2

int([x]) -> integer

HIGH_PEEP

int([x]) -> integer

HIGH_PRESSURE

int([x]) -> integer

HIGH_VTE

int([x]) -> integer

LEAK

int([x]) -> integer

LOW_O2

int([x]) -> integer

LOW_PEEP

int([x]) -> integer

LOW_PRESSURE

int([x]) -> integer

LOW_VTE

int([x]) -> integer

OBSTRUCTION

int([x]) -> integer

LOW_PRESSURE = 1
HIGH_PRESSURE = 2
LOW_VTE = 3
HIGH_VTE = 4
LOW_PEEP = 5
HIGH_PEEP = 6
LOW_O2 = 7
HIGH_O2 = 8
OBSTRUCTION = 9
LEAK = 10
class vent.alarm.AlarmSeverity[source]

An enumeration.

Attributes

HIGH

int([x]) -> integer

LOW

int([x]) -> integer

MEDIUM

int([x]) -> integer

OFF

int([x]) -> integer

HIGH = 3
MEDIUM = 2
LOW = 1
OFF = 0

Alarm Manager

Classes

Alarm_Manager()

vent.alarm.alarm_manager.active_alarms

class vent.alarm.alarm_manager.Alarm_Manager[source]

Attributes

active_alarms

dict() -> new empty dictionary

callbacks

Built-in mutable sequence.

cleared_alarms

Built-in mutable sequence.

dependencies

dict() -> new empty dictionary

logged_alarms

Built-in mutable sequence.

pending_clears

Built-in mutable sequence.

rules

dict() -> new empty dictionary

snoozed_alarms

dict() -> new empty dictionary

Methods

add_callback(callback)

check_rule(rule, sensor_values)

clear_all_alarms()

deactivate_alarm(alarm)

Mark an alarm’s internal active flags and remove from active_alarms

dismiss_alarm(alarm_type, duration)

GUI or other object requests an alarm to be dismissed & deactivated

emit_alarm(alarm_type, severity)

Emit alarm (by calling all callbacks with it).

get_alarm_severity(alarm_type)

load_rule(alarm_rule)

load_rules()

register_alarm(alarm)

Add alarm to registry.

register_dependency(condition, dependency)

Add dependency in a Condition object to be updated when values are changed

reset()

reset all conditions, callbacks, and other stateful attributes and clear alarms

update(sensor_values)

update_dependencies(control_setting)

Update Condition objects that update their value according to some control parameter

active_alarms

{AlarmType: Alarm}

Type

dict

pending_clears

[AlarmType] list of alarms that have been requested to be cleared

Type

list

callbacks

list of callables that accept Alarm s when they are raised/altered.

Type

list

cleared_alarms

of AlarmType s, alarms that have been cleared but have not dropped back into the ‘off’ range to enable re-raising

Type

list

snoozed_alarms

of AlarmType s : times, alarms that should not be raised because they have been silenced for a period of time

Type

dict

If an Alarm_Manager already exists, when initing just return that one

_instance = None
active_alarms: Dict[vent.alarm.AlarmType, vent.alarm.alarm.Alarm] = {}
logged_alarms: List[vent.alarm.alarm.Alarm] = []
dependencies = {}
pending_clears = []
cleared_alarms = []
snoozed_alarms = {}
callbacks = []
rules = {}
load_rules()[source]
load_rule(alarm_rule: vent.alarm.rule.Alarm_Rule)[source]
update(sensor_values: vent.common.message.SensorValues)[source]
check_rule(rule: vent.alarm.rule.Alarm_Rule, sensor_values: vent.common.message.SensorValues)[source]
emit_alarm(alarm_type: vent.alarm.AlarmType, severity: vent.alarm.AlarmSeverity)[source]

Emit alarm (by calling all callbacks with it).

Note

This method emits and clears alarms – a cleared alarm is emitted with AlarmSeverity.OFF

Parameters
deactivate_alarm(alarm: (<enum 'AlarmType'>, <class 'vent.alarm.alarm.Alarm'>))[source]

Mark an alarm’s internal active flags and remove from active_alarms

Note

This does not alert listeners that an alarm has been cleared, for that emit an alarm with AlarmSeverity.OFF

Parameters

alarm

Returns:

dismiss_alarm(alarm_type: vent.alarm.AlarmType, duration: float = None)[source]

GUI or other object requests an alarm to be dismissed & deactivated

GUI will wait until it receives an emit_alarm of severity == OFF to remove alarm widgets. If the alarm is not latched

If the alarm is latched, alarm_manager will not decrement alarm severity or emit OFF until a) the condition returns to OFF, and b) the user dismisses the alarm

Parameters
  • alarm_type (AlarmType) – Alarm to dismiss

  • duration (float) – seconds - amount of time to wait before alarm can be re-raised If a duration is provided, the alarm will not be able to be re-raised

get_alarm_severity(alarm_type: vent.alarm.AlarmType)[source]
register_alarm(alarm: vent.alarm.alarm.Alarm)[source]

Add alarm to registry.

Parameters

alarm (Alarm) –

register_dependency(condition: vent.alarm.condition.Condition, dependency: dict)[source]

Add dependency in a Condition object to be updated when values are changed

Parameters
  • condition

  • dependency (dict) – either a (ValueName, attribute_name) or optionally also + transformation callable

update_dependencies(control_setting: vent.common.message.ControlSetting)[source]

Update Condition objects that update their value according to some control parameter

Parameters

control_setting (ControlSetting) –

Returns:

add_callback(callback: Callable)[source]
clear_all_alarms()[source]
reset()[source]

reset all conditions, callbacks, and other stateful attributes and clear alarms

Alarm

Classes

Alarm(alarm_type, severity, start_time[, …])

Class used by the program to control and coordinate alarms.

class vent.alarm.alarm.Alarm(alarm_type: vent.alarm.AlarmType, severity: vent.alarm.AlarmSeverity, start_time: float = None, latch=True, persistent=True, value=None, message=None, managed=False)[source]

Class used by the program to control and coordinate alarms.

Parameterized by a Alarm_Rule and managed by Alarm_Manager

Parameters
  • alarm_type

  • severity

  • start_time

  • value (int, float) – optional - numerical value that generated the alarm

  • message (str) – optional - override default text generated by AlarmManager

  • managed (bool) – if created by the alarm_manager, don’t register

Methods

__init__(alarm_type, severity, start_time[, …])

param alarm_type

deactivate()

Attributes

alarm_type

id_counter

used to generate unique IDs for each alarm

manager

have ta do it this janky way to avoid circular imports

severity

id_counter = count(0)

used to generate unique IDs for each alarm

Type

itertools.count

__init__(alarm_type: vent.alarm.AlarmType, severity: vent.alarm.AlarmSeverity, start_time: float = None, latch=True, persistent=True, value=None, message=None, managed=False)[source]
Parameters
  • alarm_type

  • severity

  • start_time

  • value (int, float) – optional - numerical value that generated the alarm

  • message (str) – optional - override default text generated by AlarmManager

  • managed (bool) – if created by the alarm_manager, don’t register

property manager

have ta do it this janky way to avoid circular imports

property severity
property alarm_type
deactivate()[source]

Condition

Classes

AlarmSeverityCondition(alarm_type, severity, …)

param alarm_type

Condition(depends, *args, **kwargs)

Base class for specifying alarm test conditions

CycleAlarmSeverityCondition(n_cycles, *args, …)

alarm goes out of range for a specific number of breath cycles

CycleValueCondition(n_cycles, *args, **kwargs)

value goes out of range for a specific number of breath cycles

TimeValueCondition(time, *args, **kwargs)

value goes out of range for specific amount of time

ValueCondition(value_name, limit, mode, …)

value is greater or lesser than some max/min

Functions

get_alarm_manager()

vent.alarm.condition.get_alarm_manager()[source]
class vent.alarm.condition.Condition(depends: dict = None, *args, **kwargs)[source]

Base class for specifying alarm test conditions

Need to be able to condition alarms based on * value ranges * value ranges & durations * levels of other alarms

Methods

__init__(depends, *args, **kwargs)

param depends

check(sensor_values)

reset()

If a condition is stateful, need to provide some method of resetting the state

Attributes

manager

manager

alarm manager, used to get status of alarms

Type

vent.alarm.alarm_manager.Alarm_Manager

_child

if another condition is added to this one, store a reference to it

Type

Condition

Parameters
  • depends (list, dict) –

    a list of, or a single dict:

    {'value_name':ValueName,
    'value_attr': attr in ControlMessage,
     'condition_attr',
     optional: transformation: callable)
    that declare what values are needed to update
    

  • *args

  • **kwargs

__init__(depends: dict = None, *args, **kwargs)[source]
Parameters
  • depends (list, dict) –

    a list of, or a single dict:

    {'value_name':ValueName,
    'value_attr': attr in ControlMessage,
     'condition_attr',
     optional: transformation: callable)
    that declare what values are needed to update
    

  • *args

  • **kwargs

property manager
check(sensor_values)[source]
reset()[source]

If a condition is stateful, need to provide some method of resetting the state

class vent.alarm.condition.ValueCondition(value_name: vent.common.values.ValueName, limit: (<class 'int'>, <class 'float'>), mode: str, *args, **kwargs)[source]

value is greater or lesser than some max/min

Parameters
  • value_name (ValueName) – Which value to check

  • limit (int, float) – value to check against

  • mode ('min', 'max') – whether the limit is a minimum or maximum

  • *args

  • **kwargs

Methods

__init__(value_name, limit, mode, *args, …)

param value_name

Which value to check

check(sensor_values)

reset()

not stateful, do nothing.

Attributes

mode

__init__(value_name: vent.common.values.ValueName, limit: (<class 'int'>, <class 'float'>), mode: str, *args, **kwargs)[source]
Parameters
  • value_name (ValueName) – Which value to check

  • limit (int, float) – value to check against

  • mode ('min', 'max') – whether the limit is a minimum or maximum

  • *args

  • **kwargs

property mode
check(sensor_values)[source]
reset()[source]

not stateful, do nothing.

class vent.alarm.condition.CycleValueCondition(n_cycles, *args, **kwargs)[source]

value goes out of range for a specific number of breath cycles

Methods

check(sensor_values)

reset()

not stateful, do nothing.

Attributes

n_cycles

_start_cycle

The breath cycle where the

Type

int

_mid_check

whether a value has left the acceptable range and we are counting consecutive breath cycles

Type

bool

Args: value_name (ValueName): Which value to check limit (int, float): value to check against mode (‘min’, ‘max’): whether the limit is a minimum or maximum *args: **kwargs:

property n_cycles
check(sensor_values)[source]
reset()[source]

not stateful, do nothing.

class vent.alarm.condition.TimeValueCondition(time, *args, **kwargs)[source]

value goes out of range for specific amount of time

Parameters
  • time (float) – number of seconds value must be out of range

  • *args

  • **kwargs

Methods

__init__(time, *args, **kwargs)

param time

number of seconds value must be out of range

check(sensor_values)

reset()

not stateful, do nothing.

__init__(time, *args, **kwargs)[source]
Parameters
  • time (float) – number of seconds value must be out of range

  • *args

  • **kwargs

check(sensor_values)[source]
reset()[source]

not stateful, do nothing.

class vent.alarm.condition.AlarmSeverityCondition(alarm_type: vent.alarm.AlarmType, severity: vent.alarm.AlarmSeverity, mode: str = 'min', *args, **kwargs)[source]
Parameters
  • alarm_type

  • severity

  • mode (str) –

    one of ‘min’, ‘equals’, or ‘max’. ‘min’ returns true if the alarm is at least this value (note the difference from ValueCondition which returns true if the alarm is less than..) and vice versa for ‘max’.

    Note

    ’min’ and ‘max’ use >= and <= rather than > and <

  • *args

  • **kwargs

Methods

__init__(alarm_type, severity, mode, *args, …)

param alarm_type

check(sensor_values)

reset()

If a condition is stateful, need to provide some method of resetting the state

Attributes

mode

__init__(alarm_type: vent.alarm.AlarmType, severity: vent.alarm.AlarmSeverity, mode: str = 'min', *args, **kwargs)[source]
Parameters
  • alarm_type

  • severity

  • mode (str) –

    one of ‘min’, ‘equals’, or ‘max’. ‘min’ returns true if the alarm is at least this value (note the difference from ValueCondition which returns true if the alarm is less than..) and vice versa for ‘max’.

    Note

    ’min’ and ‘max’ use >= and <= rather than > and <

  • *args

  • **kwargs

property mode
check(sensor_values)[source]
reset()[source]

If a condition is stateful, need to provide some method of resetting the state

class vent.alarm.condition.CycleAlarmSeverityCondition(n_cycles, *args, **kwargs)[source]

alarm goes out of range for a specific number of breath cycles

Todo

note that this is exactly the same as CycleValueCondition. Need to do the multiple inheritance thing

Methods

check(sensor_values)

reset()

If a condition is stateful, need to provide some method of resetting the state

Attributes

n_cycles

_start_cycle

The breath cycle where the

Type

int

_mid_check

whether a value has left the acceptable range and we are counting consecutive breath cycles

Type

bool

Args: alarm_type: severity: mode (str): one of ‘min’, ‘equals’, or ‘max’.

‘min’ returns true if the alarm is at least this value (note the difference from ValueCondition which returns true if the alarm is less than..) and vice versa for ‘max’.

Note

‘min’ and ‘max’ use >= and <= rather than > and <

*args: **kwargs:

property n_cycles
check(sensor_values)[source]
reset()[source]

If a condition is stateful, need to provide some method of resetting the state

Alarm Rule

Class to declare alarm rules

Classes

Alarm_Rule(name, conditions[, latch, …])

  • name of rule

class vent.alarm.rule.Alarm_Rule(name: vent.alarm.AlarmType, conditions, latch=True, persistent=True, technical=False)[source]
  • name of rule

  • conditions: ((alarm_type, (condition_1, condition_2)), …)

  • persistent (bool): if True, alarm will not be visually dismissed until alarm conditions are no longer true

  • latch (bool): if True, alarm severity cannot be decremented until user manually dismisses

  • silencing/overriding rules

Methods

check(sensor_values)

Check all of our conditions .

reset()

Attributes

severity

Last Alarm Severity from .check()

check(sensor_values)[source]

Check all of our conditions .

Parameters

sensor_values

Returns:

property severity

Last Alarm Severity from .check() :returns: AlarmSeverity

reset()[source]