mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-09 04:35:25 +03:00
Add api for filtering and show correct number when filtering
This commit is contained in:
parent
16434a5e41
commit
c6800d6538
@ -77,6 +77,29 @@ def review_summary():
|
||||
hour_modifier, minute_modifier, seconds_offset = get_tz_modifiers(tz_name)
|
||||
month_ago = (datetime.now() - timedelta(days=30)).timestamp()
|
||||
|
||||
cameras = request.args.get("cameras", "all")
|
||||
labels = request.args.get("labels", "all")
|
||||
|
||||
clauses = [(ReviewSegment.start_time > month_ago)]
|
||||
|
||||
if cameras != "all":
|
||||
camera_list = cameras.split(",")
|
||||
clauses.append((ReviewSegment.camera << camera_list))
|
||||
|
||||
if labels != "all":
|
||||
# use matching so segments with multiple labels
|
||||
# still match on a search where any label matches
|
||||
label_clauses = []
|
||||
filtered_labels = labels.split(",")
|
||||
|
||||
for label in filtered_labels:
|
||||
label_clauses.append(
|
||||
(ReviewSegment.data["objects"].cast("text") % f'*"{label}"*')
|
||||
)
|
||||
|
||||
label_clause = reduce(operator.or_, label_clauses)
|
||||
clauses.append((label_clause))
|
||||
|
||||
groups = (
|
||||
ReviewSegment.select(
|
||||
fn.strftime(
|
||||
@ -161,7 +184,7 @@ def review_summary():
|
||||
)
|
||||
).alias("total_motion"),
|
||||
)
|
||||
.where(ReviewSegment.start_time > month_ago)
|
||||
.where(reduce(operator.and_, clauses))
|
||||
.group_by(
|
||||
(ReviewSegment.start_time + seconds_offset).cast("int") / (3600 * 24),
|
||||
)
|
||||
|
||||
@ -115,7 +115,15 @@ export default function Events() {
|
||||
|
||||
const { data: reviewSummary, mutate: updateSummary } = useSWR<
|
||||
ReviewSummary[]
|
||||
>(["review/summary", { timezone: timezone }, { revalidateOnFocus: false }]);
|
||||
>([
|
||||
"review/summary",
|
||||
{
|
||||
timezone: timezone,
|
||||
cameras: reviewSearchParams["cameras"] ?? null,
|
||||
labels: reviewSearchParams["labels"] ?? null,
|
||||
},
|
||||
{ revalidateOnFocus: false },
|
||||
]);
|
||||
|
||||
// preview videos
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ export default function EventView({
|
||||
// review counts
|
||||
|
||||
const reviewCounts = useMemo(() => {
|
||||
if (!reviewSummary) {
|
||||
if (!reviewSummary || reviewSummary.length == 0) {
|
||||
return { alert: 0, detection: 0, significant_motion: 0 };
|
||||
}
|
||||
|
||||
@ -80,7 +80,13 @@ export default function EventView({
|
||||
if (filter?.before == undefined) {
|
||||
summary = reviewSummary[0];
|
||||
} else {
|
||||
summary = reviewSummary[0];
|
||||
const day = new Date(filter.before * 1000);
|
||||
const key = `${day.getFullYear()}-${("0" + (day.getMonth() + 1)).slice(-2)}-${("0" + day.getDate()).slice(-2)}`;
|
||||
summary = reviewSummary.find((check) => check.day == key);
|
||||
}
|
||||
|
||||
if (!summary) {
|
||||
return { alert: 0, detection: 0, significant_motion: 0 };
|
||||
}
|
||||
|
||||
if (filter?.showReviewed == 1) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user