From c47b02d2fec668728a3cc4b6310b78180a8bb873 Mon Sep 17 00:00:00 2001 From: tpjanssen <25168870+tpjanssen@users.noreply.github.com> Date: Sat, 7 Oct 2023 16:22:14 +0200 Subject: [PATCH] Added filter option for min/max score for event to API function /events (#8079) * Update api.md * Update api.md * Added filter option for min/max score for event to API function /events * Added filter for submitted events * Update http.py --- docs/docs/integrations/api.md | 31 +++++++++++++++++-------------- frigate/http.py | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/docs/docs/integrations/api.md b/docs/docs/integrations/api.md index 515f7495a..27b760cab 100644 --- a/docs/docs/integrations/api.md +++ b/docs/docs/integrations/api.md @@ -155,20 +155,23 @@ Version info Events from the database. Accepts the following query string parameters: -| param | Type | Description | -| -------------------- | ---- | ----------------------------------------------- | -| `before` | int | Epoch time | -| `after` | int | Epoch time | -| `cameras` | str | , separated list of cameras | -| `labels` | str | , separated list of labels | -| `zones` | str | , separated list of zones | -| `limit` | int | Limit the number of events returned | -| `has_snapshot` | int | Filter to events that have snapshots (0 or 1) | -| `has_clip` | int | Filter to events that have clips (0 or 1) | -| `include_thumbnails` | int | Include thumbnails in the response (0 or 1) | -| `in_progress` | int | Limit to events in progress (0 or 1) | -| `time_range` | str | Time range in format after,before (00:00,24:00) | -| `timezone` | str | Timezone to use for time range | +| param | Type | Description | +| -------------------- | ----- | ----------------------------------------------------- | +| `before` | int | Epoch time | +| `after` | int | Epoch time | +| `cameras` | str | , separated list of cameras | +| `labels` | str | , separated list of labels | +| `zones` | str | , separated list of zones | +| `limit` | int | Limit the number of events returned | +| `has_snapshot` | int | Filter to events that have snapshots (0 or 1) | +| `has_clip` | int | Filter to events that have clips (0 or 1) | +| `include_thumbnails` | int | Include thumbnails in the response (0 or 1) | +| `in_progress` | int | Limit to events in progress (0 or 1) | +| `time_range` | str | Time range in format after,before (00:00,24:00) | +| `timezone` | str | Timezone to use for time range | +| `min_score` | float | Minimum score of the event | +| `max_score` | float | Maximum score of the event | +| `is_submitted` | int | Filter events that are submitted to Frigate+ (0 or 1) | ### `GET /api/timeline` diff --git a/frigate/http.py b/frigate/http.py index c3f39b683..3098285cc 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -802,6 +802,9 @@ def events(): in_progress = request.args.get("in_progress", type=int) include_thumbnails = request.args.get("include_thumbnails", default=1, type=int) favorites = request.args.get("favorites", type=int) + min_score = request.args.get("min_score", type=float) + max_score = request.args.get("max_score", type=float) + is_submitted = request.args.get("is_submitted", type=int) clauses = [] @@ -924,6 +927,18 @@ def events(): if favorites: clauses.append((Event.retain_indefinitely == favorites)) + if max_score is not None: + clauses.append((Event.data["score"] <= max_score)) + + if min_score is not None: + clauses.append((Event.data["score"] >= min_score)) + + if is_submitted is not None: + if is_submitted == 0: + clauses.append((Event.plus_id.is_null())) + else: + clauses.append((Event.plus_id != "")) + if len(clauses) == 0: clauses.append((True))