X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=camera_trigger.py;h=3ca7a3cb43f42996324e14a927f9c6e01b622d36;hb=addd4980077f6e3857c5c035b49784dc3ceca49a;hp=8582889d285ab49750299facf60ab242a793effd;hpb=da3a11e9fcea80a7700eb54605512d331a9ec612;p=kiosk.git diff --git a/camera_trigger.py b/camera_trigger.py index 8582889..3ca7a3c 100644 --- a/camera_trigger.py +++ b/camera_trigger.py @@ -58,38 +58,42 @@ class any_camera_trigger(trigger.trigger): filename = f"/timestamps/last_camera_motion_{camera}" ts = os.stat(filename).st_ctime age = now - ts - if ts != self.last_trigger_timestamp[camera] and age < 10: - logger.info(f'{camera} is triggered; {filename} touched {age}s ago (@{ts}') + print(f'{camera} => {age}') + if ts != self.last_trigger_timestamp[camera]: self.last_trigger_timestamp[camera] = ts - num_cameras_with_recent_triggers += 1 + if age < 15: + logger.info(f'{camera} is triggered; {filename} touched {age}s ago (@{ts}') + num_cameras_with_recent_triggers += 1 - self.triggers_in_the_past_seven_min[camera] = 0 - filename = f"/timestamps/camera_motion_history_{camera}" - with open(filename, "r") as f: - contents = f.readlines() - for x in contents: - x = x.strip() - age = now - int(x) - if age < (60 * 7): - self.triggers_in_the_past_seven_min[camera] += 1 + self.triggers_in_the_past_seven_min[camera] = 0 + filename = f"/timestamps/camera_motion_history_{camera}" + with open(filename, "r") as f: + contents = f.readlines() + for x in contents: + x = x.strip() + age = now - int(x) + if age < (60 * 7): + self.triggers_in_the_past_seven_min[camera] += 1 + print(f'{camera} past 7m: {self.triggers_in_the_past_seven_min[camera]}') # Second pass, see whether we want to trigger due to # camera activity we found. All cameras timestamps were # just considered and should be up-to-date. Some logic to # squelch spammy cameras unless more than one is triggered # at the same time. + print(f'{num_cameras_with_recent_triggers}') for camera in camera_list: - if (now - self.last_trigger_timestamp[camera]) < 10: + if (now - self.last_trigger_timestamp[camera]) < 15: if ( self.triggers_in_the_past_seven_min[camera] <= 4 or num_cameras_with_recent_triggers > 1 ): - logger.info(f'{camera} has {self.triggers_in_the_past_seven_min[camera]} triggers in the past 7d.') - logger.info(f'{num_cameras_with_recent_triggers} cameras are triggered right now.') + print(f'{camera} has {self.triggers_in_the_past_seven_min[camera]} triggers in the past 7d.') + print(f'{num_cameras_with_recent_triggers} cameras are triggered right now.') age = now - self.last_trigger_timestamp[camera] priority = self.choose_priority(camera, int(age)) - logger.info(f'*** CAMERA TRIGGER (hidden/{camera}.html @ {priority}) ***') + print(f'*** CAMERA TRIGGER (hidden/{camera}.html @ {priority}) ***') triggers.append( ( f"hidden/unwrapped_{camera}.html",