alarm

Main Alarm Module

Classes

AlarmSeverity(value)

An enumeration.

AlarmType(value)

An enumeration.

class pvp.alarm.AlarmType(value)[source]

An enumeration.

Attributes

LOW_PRESSURE

int([x]) -> integer

HIGH_PRESSURE

int([x]) -> integer

LOW_VTE

int([x]) -> integer

HIGH_VTE

int([x]) -> integer

LOW_PEEP

int([x]) -> integer

HIGH_PEEP

int([x]) -> integer

LOW_O2

int([x]) -> integer

HIGH_O2

int([x]) -> integer

OBSTRUCTION

int([x]) -> integer

LEAK

int([x]) -> integer

SENSORS_STUCK

int([x]) -> integer

BAD_SENSOR_READINGS

int([x]) -> integer

MISSED_HEARTBEAT

int([x]) -> integer

human_name

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
SENSORS_STUCK = 11
BAD_SENSOR_READINGS = 12
MISSED_HEARTBEAT = 13
property human_name
class pvp.alarm.AlarmSeverity(value)[source]

An enumeration.

Attributes

HIGH

int([x]) -> integer

MEDIUM

int([x]) -> integer

LOW

int([x]) -> integer

OFF

int([x]) -> integer

TECHNICAL

int([x]) -> integer

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

Alarm Manager

Classes

Alarm_Manager()

pvp.alarm.alarm_manager.active_alarms

class pvp.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

depends_callbacks

When we update_dependencies(), we send back a ControlSetting with the new min/max

logged_alarms

Built-in mutable sequence.

logger

Instances of the Logger class represent a single logging channel.

pending_clears

Built-in mutable sequence.

rules

dict() -> new empty dictionary

snoozed_alarms

dict() -> new empty dictionary

Methods

add_callback(callback)

add_dependency_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[pvp.alarm.AlarmType, pvp.alarm.alarm.Alarm] = {}
logged_alarms: List[pvp.alarm.alarm.Alarm] = []
dependencies = {}
pending_clears = []
cleared_alarms = []
snoozed_alarms = {}
callbacks = []
depends_callbacks = []

When we update_dependencies(), we send back a ControlSetting with the new min/max

rules = {}
logger = <Logger pvp.alarm.alarm_manager (WARNING)>
load_rules()[source]
load_rule(alarm_rule: pvp.alarm.rule.Alarm_Rule)[source]
update(sensor_values: pvp.common.message.SensorValues)[source]
check_rule(rule: pvp.alarm.rule.Alarm_Rule, sensor_values: pvp.common.message.SensorValues)[source]
emit_alarm(alarm_type: pvp.alarm.AlarmType, severity: pvp.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 'pvp.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: pvp.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: pvp.alarm.AlarmType)[source]
register_alarm(alarm: pvp.alarm.alarm.Alarm)[source]

Add alarm to registry.

Parameters

alarm (Alarm) –

register_dependency(condition: pvp.alarm.condition.Condition, dependency: dict, severity: pvp.alarm.AlarmSeverity)[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

  • severity (AlarmSeverity) – severity of dependency

update_dependencies(control_setting: pvp.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]
add_dependency_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 pvp.alarm.alarm.Alarm(alarm_type: pvp.alarm.AlarmType, severity: pvp.alarm.AlarmSeverity, start_time: float = None, latch: bool = True, persistent: bool = True, cause: list = None, value=None, message=None)[source]

Class used by the program to control and coordinate alarms.

Parameterized by a Alarm_Rule and managed by Alarm_Manager

Methods

__init__(alarm_type, severity, start_time, …)

pvp.alarm.alarm.id

deactivate()

Attributes

alarm_type

id_counter

itertools.count: used to generate unique IDs for each alarm

severity

id

unique alarm ID

Type

int

Parameters
  • alarm_type

  • severity

  • start_time

  • cause (ValueName) – The value that caused the alarm to be fired

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

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

id_counter = count(0)

used to generate unique IDs for each alarm

Type

itertools.count

__init__(alarm_type: pvp.alarm.AlarmType, severity: pvp.alarm.AlarmSeverity, start_time: float = None, latch: bool = True, persistent: bool = True, cause: list = None, value=None, message=None)[source]
id

unique alarm ID

Type

int

Parameters
  • alarm_type

  • severity

  • start_time

  • cause (ValueName) – The value that caused the alarm to be fired

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

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

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()

pvp.alarm.condition.get_alarm_manager()[source]
class pvp.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

pvp.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 pvp.alarm.condition.ValueCondition(value_name: pvp.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: pvp.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 pvp.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 pvp.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 pvp.alarm.condition.AlarmSeverityCondition(alarm_type: pvp.alarm.AlarmType, severity: pvp.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: pvp.alarm.AlarmType, severity: pvp.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 pvp.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 pvp.alarm.rule.Alarm_Rule(name: pvp.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

depends

Get all ValueNames whose alarm limits depend on this alarm rule

severity

Last Alarm Severity from .check()

value_names

Get all ValueNames specified as value_names in alarm conditions

check(sensor_values)[source]

Check all of our conditions .

Parameters

sensor_values

Returns:

property severity

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

reset()[source]
property depends

Get all ValueNames whose alarm limits depend on this alarm rule :returns: list[ValueName]

property value_names

Get all ValueNames specified as value_names in alarm conditions

Returns

list[ValueName]