Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event cleanup #11225

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions frigate/events/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,43 +184,6 @@ def expire(self, media_type: EventCleanupType) -> list[str]:
Event.update(update_params).where(Event.id << events_to_update).execute()
return events_to_update

def purge_duplicates(self) -> None:
duplicate_query = """with grouped_events as (
select id,
label,
camera,
has_snapshot,
has_clip,
end_time,
row_number() over (
partition by label, camera, round(start_time/5,0)*5
order by end_time-start_time desc
) as copy_number
from event
)

select distinct id, camera, has_snapshot, has_clip from grouped_events
where copy_number > 1 and end_time not null;"""

duplicate_events: list[Event] = Event.raw(duplicate_query)
for event in duplicate_events:
logger.debug(f"Removing duplicate: {event.id}")

try:
media_name = f"{event.camera}-{event.id}"
media_path = Path(f"{os.path.join(CLIPS_DIR, media_name)}.jpg")
media_path.unlink(missing_ok=True)
media_path = Path(f"{os.path.join(CLIPS_DIR, media_name)}-clean.png")
media_path.unlink(missing_ok=True)
except OSError as e:
logger.warning(f"Unable to delete event images: {e}")

(
Event.delete()
.where(Event.id << [event.id for event in duplicate_events])
.execute()
)

def run(self) -> None:
# only expire events every 5 minutes
while not self.stop_event.wait(300):
Expand All @@ -232,7 +195,6 @@ def run(self) -> None:
).execute()

self.expire(EventCleanupType.snapshots)
self.purge_duplicates()

# drop events from db where has_clip and has_snapshot are false
delete_query = Event.delete().where(
Expand Down
4 changes: 2 additions & 2 deletions frigate/track/norfair_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
logger = logging.getLogger(__name__)


THRESHOLD_ACTIVE_IOU = 0.2
THRESHOLD_STATIONARY_IOU = 0.6
THRESHOLD_ACTIVE_IOU = 0.35
THRESHOLD_STATIONARY_IOU = 0.7
MAX_STATIONARY_HISTORY = 10


Expand Down
4 changes: 2 additions & 2 deletions web/src/components/player/HlsVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ export default function HlsVideoPlayer({
const resp = await onUploadFrame(videoRef.current.currentTime);

if (resp && resp.status == 200) {
toast.success("Successfully submitted frame to Frigate Plus", {
toast.success("Successfully submitted frame to Frigate+", {
position: "top-center",
});
} else {
toast.success("Failed to submit frame to Frigate Plus", {
toast.success("Failed to submit frame to Frigate+", {
position: "top-center",
});
}
Expand Down
32 changes: 28 additions & 4 deletions web/src/views/events/EventView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import { useCameraMotionNextTimestamp } from "@/hooks/use-camera-activity";
import useOptimisticState from "@/hooks/use-optimistic-state";
import { Skeleton } from "@/components/ui/skeleton";
import scrollIntoView from "scroll-into-view-if-needed";
import { Toaster } from "@/components/ui/sonner";
import { toast } from "sonner";

type EventViewProps = {
reviews?: ReviewSegment[];
Expand Down Expand Up @@ -194,10 +196,31 @@ export default function EventView({
return;
}

axios.post(
`export/${review.camera}/start/${review.start_time}/end/${review.end_time}`,
{ playback: "realtime" },
);
axios
.post(
`export/${review.camera}/start/${review.start_time}/end/${review.end_time}`,
{ playback: "realtime" },
)
.then((response) => {
if (response.status == 200) {
toast.success(
"Successfully started export. View the file in the /exports folder.",
{ position: "top-center" },
);
}
})
.catch((error) => {
if (error.response?.data?.message) {
toast.error(
`Failed to start export: ${error.response.data.message}`,
{ position: "top-center" },
);
} else {
toast.error(`Failed to start export: ${error.message}`, {
position: "top-center",
});
}
});
},
[reviewItems],
);
Expand All @@ -215,6 +238,7 @@ export default function EventView({

return (
<div className="py-2 flex flex-col size-full">
<Toaster />
<div className="h-11 mb-2 pl-3 pr-2 relative flex justify-between items-center">
{isMobile && (
<Logo className="absolute inset-x-1/2 -translate-x-1/2 h-8" />
Expand Down
Loading