Don't spam notifications

This commit is contained in:
slashtechno 2023-10-05 19:12:42 -05:00
parent ea4009c898
commit 9fb5818322
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
1 changed files with 18 additions and 12 deletions

View File

@ -132,6 +132,7 @@ def main():
"last_detection_time": None,
"detection_duration": None,
# "first_detection_time": None,
"last_notification_time": None,
}
for box in r.boxes:
# Get the name of the object
@ -158,7 +159,7 @@ def main():
or time.time() - object_names[class_id]["last_detection_time"] > 15
or object_names[class_id]["detection_duration"] is None
):
print(f"First detection of {class_id}")
print(f"First detection of {class_id} in session")
# time.time() returns the number of seconds since the epoch
object_names[class_id]["last_detection_time"] = time.time()
# object_names[class_id]["first_detection_time"] = time.time()
@ -184,15 +185,20 @@ def main():
and time.time() - object_names[class_id]["last_detection_time"]
<= 15
):
print(f"Detected {class_id} for 2 seconds")
headers = notify.construct_ntfy_headers(
title=f"{class_id} Detected",
tag="rotating_light",
priority="default",
)
notify.send_notification(
data=f"{class_id} Detected", headers=headers, url=args.ntfy_url
)
# If the last notification was more than 15 seconds ago, then send a notification
if object_names[class_id]["last_notification_time"] is None or time.time() - object_names[class_id]["last_notification_time"] > 15:
object_names[class_id]["last_notification_time"] = time.time()
print(f"Detected {class_id} for 2 seconds")
headers = notify.construct_ntfy_headers(
title=f"{class_id} Detected",
tag="rotating_light",
priority="default",
)
notify.send_notification(
data=f"{class_id} Detected", headers=headers, url=args.ntfy_url
)
# Reset the detection duration
object_names[class_id]["detection_duration"] = 0
im_array = r.plot()
# Scale back up the coordinates of the locations of detected objects.
# im_array = np.multiply(im_array, 1/args.run_scale)