diff --git a/app/app_config.py b/app/app_config.py index ff397af..b1e3cfb 100644 --- a/app/app_config.py +++ b/app/app_config.py @@ -17,15 +17,17 @@ def mapper(self): mapper = ConfigMapper() mapper.register_bool('enabled', defval=True) mapper.register_int( - 'calculate_notification_every_seconds', minval=1, maxval=1440, defval=60) + 'calculate_notification_every_seconds', minval=1, maxval=86400, defval=60) mapper.register_time('activate_from_hour', defval='09:00') mapper.register_time('activate_until_hour', defval='17:00') mapper.register_int( - 'check_presence_every_seconds', minval=1, maxval=1440, defval=60) - mapper.register_int('max_work_time_seconds', minval=1, maxval=1440, defval=3600) - mapper.register_int('min_break_time_seconds', minval=1, maxval=1440, defval=300) + 'check_presence_every_seconds', minval=1, maxval=86400, defval=60) mapper.register_int( - 'break_notification_cooldown_seconds', minval=1, maxval=1440, defval=120) + 'max_work_time_seconds', minval=1, maxval=86400, defval=3600) + mapper.register_int( + 'min_break_time_seconds', minval=1, maxval=86400, defval=300) + mapper.register_int( + 'break_notification_cooldown_seconds', minval=1, maxval=86400, defval=120) mapper.register_bool('notify_when_camera_occupied', defval=False) mapper.register_int('camera', minval=0, maxval=10, defval=0) mapper.register_int('num_of_snapshots', minval=1, maxval=10, defval=1) diff --git a/app/event_processor.py b/app/event_processor.py index 809c521..737a279 100644 --- a/app/event_processor.py +++ b/app/event_processor.py @@ -46,14 +46,17 @@ def _should_do_break(self, current_time): max_work_time_seconds = self._kwargs.get('max_work_time_seconds') min_break_time_seconds = self._kwargs.get('min_break_time_seconds') - start_from = current_time - max_work_time_seconds - min_break_time_seconds + start_from = current_time - max_work_time_seconds events = self._queue.iterate_from(start_from) - while len(events) > 0 and events[0]['event'] == PresenceEvent.NOT_PRESENT: - events.pop(0) + if len(events) == 0: + log.debug('No events yet') + return False - if len(events) == 0 or events[0]['at'] > current_time - max_work_time_seconds: - # it hasn't passed enough time + if events[0]['at'] > start_from: + log.debug('Oldest event at {} is more recent than {}'.format( + datetime.datetime.fromtimestamp(events[0]['at']), + datetime.datetime.fromtimestamp(start_from))) return False breaks = self._find_all_breaks(events) @@ -115,8 +118,14 @@ def _calculate_break_periods(self, breaks): 'max_work_time_seconds': 6, 'min_break_time_seconds': 2 }) - print(event_processor._calculate_break_periods([ - {'start_at': 10, 'end_at': 20}, - {'start_at': 23, 'end_at': 30}, - {'start_at': 33, 'end_at': 33} - ])) + print( + event_processor._calculate_break_periods([{ + 'start_at': 10, + 'end_at': 20 + }, { + 'start_at': 23, + 'end_at': 30 + }, { + 'start_at': 33, + 'end_at': 33 + }]))