Skip to content

Commit

Permalink
Issue #92 - Small refactoring of enable_monitoring function
Browse files Browse the repository at this point in the history
  • Loading branch information
aywaldron committed Nov 30, 2018
1 parent 276319f commit 2fc1161
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ait/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ def telem_handler(session):
for k, v in tlm.getDefaultDict().iteritems():
packet_dict[v.uid] = v

notif_thrshld = cfg.AitConfig().get('notifications.options.threshold')
if cfg.AitConfig().get('notifications.options.frequency'):
notif_freq = cfg.AitConfig().get('notifications.options.frequency')
notif_thrshld = ait.config.get('notifications.options.threshold')
if ait.config.get('notifications.options.frequency'):
notif_freq = ait.config.get('notifications.options.frequency')
else:
notif_freq = float('inf')

Expand Down Expand Up @@ -419,21 +419,23 @@ def telem_handler(session):
log.error(msg)

limit_trip_repeats[packet.name][field] += 1
repeats = limit_trip_repeats[packet.name][field]

if (limit_trip_repeats[packet.name][field] == notif_thrshld or
(limit_trip_repeats[packet.name][field] - notif_thrshld)
% notif_freq == 0):
if (repeats == notif_thrshld or
(repeats > notif_thrshld and
(repeats - notif_thrshld) % notif_freq == 0)):
notify.trigger_notification('limit-error', msg)

elif defn.warn(v):
msg = 'Field {} warning out of limit with value {}'.format(field, v)
log.warn(msg)

limit_trip_repeats[packet.name][field] += 1
repeats = limit_trip_repeats[packet.name][field]

if (limit_trip_repeats[packet.name][field] == notif_thrshld or
(limit_trip_repeats[packet.name][field] - notif_thrshld)
% notif_freq == 0):
if (repeats == notif_thrshld or
(repeats > notif_thrshld and
(repeats - notif_thrshld) % notif_freq == 0)):
notify.trigger_notification('limit-warn', msg)

else:
Expand Down

0 comments on commit 2fc1161

Please sign in to comment.