6 from datetime import datetime
8 class any_camera_trigger(trigger.trigger):
10 self.triggers_in_the_past_seven_min = {
23 def choose_priority(self, camera, age):
24 base_priority_by_camera = {
30 priority = base_priority_by_camera[camera]
32 priority += trigger.trigger.PRIORITY_HIGH
34 priority += trigger.trigger.PRIORITY_NORMAL + age
36 priority += trigger.trigger.PRIORITY_LOW
39 def get_triggered_page_list(self):
41 cameras_with_recent_triggers = 0
42 camera_list = [ "driveway",
49 # First pass, just see whether each camera is triggered and,
50 # if so, count how many times in the past 7m it has triggered.
51 for camera in camera_list:
52 file = "/timestamps/last_camera_motion_%s" % camera
53 ts = os.stat(file).st_ctime
55 # print "Camera: %s, age %s" % (camera, age)
57 cameras_with_recent_triggers += 1
58 time_since_last_trigger = now - self.last_trigger[camera]
59 self.last_trigger[camera] = now
60 if time_since_last_trigger < (60 * 7):
61 self.triggers_in_the_past_seven_min[camera] += 1
63 self.triggers_in_the_past_seven_min[camera] = 1
65 # Second pass, see whether we want to trigger due to
66 # camera activity we found. All cameras timestamps were
67 # just considered and should be up-to-date. Some logic to
68 # squelch spammy cameras unless more than one is
69 # triggered at the same time.
70 for camera in camera_list:
71 if self.last_trigger[camera] == now:
72 ts = utils.timestamp()
73 if (self.triggers_in_the_past_seven_min[camera] <= 4 or
74 cameras_with_recent_triggers > 1):
75 p = self.choose_priority(camera, age)
76 print(("%s: ****** %s[%d] CAMERA TRIGGER ******" % (
78 triggers.append( ( "hidden/%s.html" % camera,
79 self.choose_priority(camera, age)) )
81 print(("%s: Camera %s too spammy, squelching it" % (
83 except Exception as e:
87 if len(triggers) == 0:
92 #x = any_camera_trigger()
93 #print(x.get_triggered_page_list())