Make gkeep understand list indentation, tweaks to the countdown bar in
[kiosk.git] / camera_trigger.py
index 74829e32d8b54cd9612e3b9259f515f596be848d..64cb6383f375c6fdd58e067abc7e308311d3333c 100644 (file)
@@ -51,16 +51,21 @@ class any_camera_trigger(trigger.trigger):
             for camera in camera_list:
                 file = "/timestamps/last_camera_motion_%s" % camera
                 ts = os.stat(file).st_ctime
-                age = now - ts
-                # print "Camera: %s, age %s" % (camera, age)
-                if age < 60:
+                if (ts != self.last_trigger[camera] and
+                    (now - ts) < 10):
+                    print("Camera: %s, age %s" % (camera, (now - ts)))
+                    self.last_trigger[camera] = ts
                     cameras_with_recent_triggers += 1
-                    time_since_last_trigger = now - self.last_trigger[camera]
-                    self.last_trigger[camera] = now
-                    if time_since_last_trigger < (60 * 7):
-                        self.triggers_in_the_past_seven_min[camera] += 1
-                    else:
-                        self.triggers_in_the_past_seven_min[camera] = 1
+                    self.triggers_in_the_past_seven_min[camera] = 0
+                    file = "/timestamps/camera_motion_history_%s" % camera
+                    f = open(file, "r")
+                    contents = f.readlines()
+                    f.close()
+                    for x in contents:
+                        x.strip()
+                        age = now - int(x)
+                        if age < (60 * 7):
+                            self.triggers_in_the_past_seven_min[camera] += 1
 
             # Second pass, see whether we want to trigger due to
             # camera activity we found.  All cameras timestamps were
@@ -68,10 +73,10 @@ class any_camera_trigger(trigger.trigger):
             # squelch spammy cameras unless more than one is
             # triggered at the same time.
             for camera in camera_list:
-                if self.last_trigger[camera] == now:
-                    ts = utils.timestamp()
+                if (now - self.last_trigger[camera]) < 10:
                     if (self.triggers_in_the_past_seven_min[camera] <= 4 or
                         cameras_with_recent_triggers > 1):
+                        ts = utils.timestamp()
                         p = self.choose_priority(camera, age)
                         print(("%s: ****** %s[%d] CAMERA TRIGGER ******" % (
                             ts, camera, p)))