Alarm Condition

Condition objects define conditions that can raise alarms. They are used by Alarm_Rule s.

Each has to define a Condition.check() method that accepts SensorValues . The method should return True if the alarm condition is met, and False otherwise.

Conditions can be added (+) together to make compound conditions, and a single call to check will only return true if both conditions return true. If any condition in the chain returns false, evaluation is stopped and the alarm is not raised.

Conditions can

Inheritance diagram of pvp.alarm.condition

Classes

AlarmSeverityCondition(alarm_type, severity, …)

Alarm is above or below a certain severity.

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]

Bases: object

Base class for specifying alarm test conditions

Subclasses must define Condition.check() and Conditino.reset()

Condition objects can be added together to create compound conditions.

Methods

__init__(depends, *args, **kwargs)

param depends

check(sensor_values)

Every Condition subclass needs to define this method that accepts SensorValues and returns a boolean

reset()

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

Attributes

manager

The active alarm manager, used to get status of alarms

_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

The active alarm manager, used to get status of alarms

Returns

pvp.alarm.alarm_manager.Alarm_Manager

check(sensor_values)bool[source]

Every Condition subclass needs to define this method that accepts SensorValues and returns a boolean

Parameters

sensor_values (SensorValues) – SensorValues used to compute alarm status

Returns

bool

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]

Bases: pvp.alarm.condition.Condition

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)

Check that the relevant value in SensorValues is either greater or lesser than the limit

reset()

not stateful, do nothing.

Attributes

mode

One of ‘min’ or ‘max’, defines how the incoming sensor values are compared to the set value

operator

Either the less than or greater than operators, depending on whether mode is 'min' or 'max'

Type

callable

__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

operator

Either the less than or greater than operators, depending on whether mode is 'min' or 'max'

Type

callable

property mode

One of ‘min’ or ‘max’, defines how the incoming sensor values are compared to the set value

Returns:

check(sensor_values)[source]

Check that the relevant value in SensorValues is either greater or lesser than the limit

Parameters

sensor_values (SensorValues) –

Returns

bool

reset()[source]

not stateful, do nothing.

class pvp.alarm.condition.CycleValueCondition(n_cycles: int, *args, **kwargs)[source]

Bases: pvp.alarm.condition.ValueCondition

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

Parameters

n_cycles (int) – number of cycles required

Methods

check(sensor_values)

Check if outside of range, and then check if number of breath cycles have elapsed

reset()

Reset check status and start cycle

Attributes

n_cycles

Number of cycles required

_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

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

operator

Either the less than or greater than operators, depending on whether mode is 'min' or 'max'

Type

callable

property n_cycles

Number of cycles required

check(sensor_values)bool[source]

Check if outside of range, and then check if number of breath cycles have elapsed

Parameters

() (sensor_values) –

Returns

bool

reset()[source]

Reset check status and start cycle

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

Bases: pvp.alarm.condition.ValueCondition

value goes out of range for specific amount of time

Warning

Not implemented!

Methods

__init__(time, *args, **kwargs)

param time

number of seconds value must be out of range

check(sensor_values)

Check that the relevant value in SensorValues is either greater or lesser than the limit

reset()

not stateful, do nothing.

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

  • *args

  • **kwargs

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

  • *args

  • **kwargs

check(sensor_values)[source]

Check that the relevant value in SensorValues is either greater or lesser than the limit

Parameters

sensor_values (SensorValues) –

Returns

bool

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]

Bases: pvp.alarm.condition.Condition

Alarm is above or below a certain severity.

Get alarm severity status from Alarm_Manager.get_alarm_severity() .

Parameters
  • alarm_type (AlarmType) – Alarm type to check

  • severity (AlarmSeverity) – Alarm severity to check against

  • 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, …)

Alarm is above or below a certain severity.

check(sensor_values)

Every Condition subclass needs to define this method that accepts SensorValues and returns a boolean

reset()

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

Attributes

mode

‘min’ returns true if the alarm is at least this value

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

Alarm is above or below a certain severity.

Get alarm severity status from Alarm_Manager.get_alarm_severity() .

Parameters
  • alarm_type (AlarmType) – Alarm type to check

  • severity (AlarmSeverity) – Alarm severity to check against

  • 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

‘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 <

Returns

one of ‘min’, ‘equals’, or ‘max’.

Return type

str

check(sensor_values)[source]

Every Condition subclass needs to define this method that accepts SensorValues and returns a boolean

Parameters

sensor_values (SensorValues) – SensorValues used to compute alarm status

Returns

bool

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]

Bases: pvp.alarm.condition.AlarmSeverityCondition

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)

Every Condition subclass needs to define this method that accepts SensorValues and returns a boolean

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

Alarm is above or below a certain severity.

Get alarm severity status from Alarm_Manager.get_alarm_severity() .

Parameters
  • alarm_type (AlarmType) – Alarm type to check

  • severity (AlarmSeverity) – Alarm severity to check against

  • 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]

Every Condition subclass needs to define this method that accepts SensorValues and returns a boolean

Parameters

sensor_values (SensorValues) – SensorValues used to compute alarm status

Returns

bool

reset()[source]

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