Skip to content

Commit

Permalink
Merge pull request #3 from AlexCovizzi/dev
Browse files Browse the repository at this point in the history
Fix settings bug
  • Loading branch information
AlexCovizzi authored May 18, 2021
2 parents 978192b + 5154da3 commit b3b73fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
12 changes: 7 additions & 5 deletions app/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 19 additions & 10 deletions app/event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}]))

0 comments on commit b3b73fb

Please sign in to comment.