Abstract Rule class — GramophoneTools 0.7.0-beta documentation

# Abstract Rule class

class `Rule.` `Rule`(level, event)

  Generic Rule all specific Rules intherit from.

  Parameters

    - level (Level) – The Level this Rule is active on.

    - event (Event.Event) – The event the rule triggers.

  abstract `check`(*arg)

    Check whether the rules’s event should be triggered.

  `trigger`()

    Triggers the associated event and prints out a message about it.

# Specific Rules

## Zone Rule

class `Rule.` `ZoneRule`(level, event, zone_type, delay)

  Bases: `Rule.Rule`

  A Rule that triggers if the animal is in a given type of zone.

  Parameters

    - level (Level) – The Level this Rule is active on.

    - event (Event.Event) – The event the rule triggers.

    - zone_type (str) – The type of Zone this Rule is active in.

    - delay (float) – How many seconds should be spent in the Zone before triggering.

  `check`(current_zone_type)

    Check whether the Zone rule should be triggered.

    Parameters

      current_zone_type (str) – Type of the curren zone.

## Velocity Rule

class `Rule.` `VelocityRule`(level, event, vel_rule_type, threshold, delay)

  Bases: `Rule.Rule`

  A Rule that triggers if the velocity is above or below a certain threshold.

  Parameters

    - level (Level) – The Level this Rule is active on.

    - event (Event.Event) – The event the rule triggers.

    - vel_rule_type (str) – Type of comparison. Can be ‘above’ or ‘below’.

    - threshold (float) – Absolute velocity should be above or below this value.

    - delay (float) – How long should the absolute velocity be above or below the threshold.

  `check`(vel)

    Check whether the Velocity rule should be triggered.

    Parameters

      vel (int) – The current velocity.

## Smooth Velocity Rule

class `Rule.` `SmoothVelocityRule`(level, event, bin_size, vel_rule_type, threshold, delay)

  Bases: `Rule.VelocityRule`

  A Rule that triggers if the moveing average of velocity is above or below a certain threshold.

  Parameters

    - level (Level) – The Level this Rule is active on.

    - event (Event.Event) – The event the rule triggers.

    - bin_size (int) – How many velocities should be used for calculating the moving average.

    - vel_rule_type (str) – Type of comparison. Can be ‘above’ or ‘below’.

    - threshold (float) – Smoothed absolute velocity should be above or below this value.

    - delay (float) – How long should the smoothed absolute velocity be above or below the threshold.

  `check`(vel)

    Check whether the Smooth velocity rule should be triggered.

    Parameters

      vel (int) – The current velocity.

## Speed Rule

class `Rule.` `SpeedRule`(level, event, speed_rule_type, threshold, bin_size)

  Bases: `Rule.Rule`

  A Rule that triggers if the absolute integral of the velocity on a given range is above or below a given threshold.

  Parameters

    - level (Level) – The Level this Rule is active on.

    - event (Event.Event) – The event the rule triggers.

    - speed_rule_type (str) – Type of comparison. Can be ‘above’ or ‘below’.

    - threshold (float) – The calculated integral should be above or below this value.

    - bin_size (int) – How many velocities should be used for the integral.

  `check`(vel)

    Check whether the Speed rule should be triggered.

    Parameters

      vel (int) – The current velocity.

## Keypress Rule

class `Rule.` `KeyPressRule`(level, event, key)

  Bases: `Rule.Rule`

  A Rule that triggers when a selected key on the keyboard is pressed.

  Parameters

    key (str) – The key that triggers the rule.

  `check`(key)

    Check whether the rules’s event should be triggered.

## Input Rule

class `Rule.` `InputRule`(level, event, input_id, trigger_type)

  Bases: `Rule.Rule`

  A Rule that triggers when the given digital output rises, falls or changes.

  Parameters

    - input_id (int) – The number of the input (1 or 2)

    - trigger_type (str) – ‘rise’, ‘fall’ or ‘change’

  `check`(input_id, state)

    Check whether the rules’s event should be triggered.