mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
revert explore query
This commit is contained in:
parent
fa6fda4295
commit
6bfee9993e
@ -11,7 +11,7 @@ import cv2
|
|||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request
|
||||||
from fastapi.params import Depends
|
from fastapi.params import Depends
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
from peewee import JOIN, DoesNotExist, Window, fn, operator
|
from peewee import JOIN, DoesNotExist, fn, operator
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
|
|
||||||
from frigate.api.defs.events_body import (
|
from frigate.api.defs.events_body import (
|
||||||
@ -259,7 +259,7 @@ def events(params: EventsQueryParams = Depends()):
|
|||||||
|
|
||||||
@router.get("/events/explore")
|
@router.get("/events/explore")
|
||||||
def events_explore(limit: int = 10):
|
def events_explore(limit: int = 10):
|
||||||
ranked_events = Event.select(
|
subquery = Event.select(
|
||||||
Event.id,
|
Event.id,
|
||||||
Event.camera,
|
Event.camera,
|
||||||
Event.label,
|
Event.label,
|
||||||
@ -275,37 +275,38 @@ def events_explore(limit: int = 10):
|
|||||||
Event.false_positive,
|
Event.false_positive,
|
||||||
Event.box,
|
Event.box,
|
||||||
Event.data,
|
Event.data,
|
||||||
fn.COUNT(Event.id).over(partition_by=[Event.label]).alias("event_count"),
|
fn.rank()
|
||||||
Window.row_number()
|
|
||||||
.over(partition_by=[Event.label], order_by=[Event.start_time.desc()])
|
.over(partition_by=[Event.label], order_by=[Event.start_time.desc()])
|
||||||
.alias("rank"),
|
.alias("rank"),
|
||||||
).alias("ranked_events")
|
fn.COUNT(Event.id).over(partition_by=[Event.label]).alias("event_count"),
|
||||||
|
).alias("subquery")
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
ranked_events.select(
|
Event.select(
|
||||||
ranked_events.c.id,
|
subquery.c.id,
|
||||||
ranked_events.c.camera,
|
subquery.c.camera,
|
||||||
ranked_events.c.label,
|
subquery.c.label,
|
||||||
ranked_events.c.zones,
|
subquery.c.zones,
|
||||||
ranked_events.c.start_time,
|
subquery.c.start_time,
|
||||||
ranked_events.c.end_time,
|
subquery.c.end_time,
|
||||||
ranked_events.c.has_clip,
|
subquery.c.has_clip,
|
||||||
ranked_events.c.has_snapshot,
|
subquery.c.has_snapshot,
|
||||||
ranked_events.c.plus_id,
|
subquery.c.plus_id,
|
||||||
ranked_events.c.retain_indefinitely,
|
subquery.c.retain_indefinitely,
|
||||||
ranked_events.c.sub_label,
|
subquery.c.sub_label,
|
||||||
ranked_events.c.top_score,
|
subquery.c.top_score,
|
||||||
ranked_events.c.false_positive,
|
subquery.c.false_positive,
|
||||||
ranked_events.c.box,
|
subquery.c.box,
|
||||||
ranked_events.c.data,
|
subquery.c.data,
|
||||||
ranked_events.c.event_count,
|
subquery.c.event_count,
|
||||||
)
|
)
|
||||||
.where(ranked_events.c.rank <= limit)
|
.from_(subquery)
|
||||||
.order_by(ranked_events.c.event_count.desc(), ranked_events.c.start_time.desc())
|
.where(subquery.c.rank <= limit)
|
||||||
|
.order_by(subquery.c.event_count.desc(), subquery.c.start_time.desc())
|
||||||
.dicts()
|
.dicts()
|
||||||
)
|
)
|
||||||
|
|
||||||
events = list(query)
|
events = list(query.iterator())
|
||||||
|
|
||||||
processed_events = [
|
processed_events = [
|
||||||
{k: v for k, v in event.items() if k != "data"}
|
{k: v for k, v in event.items() if k != "data"}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user