mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-03 06:50:58 +00:00
refactor: add friendly zone names to timeline entries and clean up unused code
This commit is contained in:
parent
06e2fc0aa0
commit
91b267a2b6
@ -131,6 +131,19 @@ class TimelineProcessor(threading.Thread):
|
||||
):
|
||||
timeline_entry[Timeline.class_type] = "entered_zone"
|
||||
timeline_entry[Timeline.data]["zones"] = event_data["current_zones"]
|
||||
|
||||
zones_friendly = []
|
||||
for z in event_data["current_zones"]:
|
||||
zone_cfg = camera_config.zones.get(z)
|
||||
if zone_cfg is not None and getattr(
|
||||
zone_cfg, "friendly_name", None
|
||||
):
|
||||
zones_friendly.append(zone_cfg.friendly_name)
|
||||
else:
|
||||
zones_friendly.append(z)
|
||||
|
||||
timeline_entry[Timeline.data]["zones_friendly_names"] = zones_friendly
|
||||
|
||||
save = True
|
||||
elif prev_event_data["stationary"] != event_data["stationary"]:
|
||||
timeline_entry[Timeline.class_type] = (
|
||||
|
||||
@ -8,9 +8,6 @@ import {
|
||||
import { TooltipPortal } from "@radix-ui/react-tooltip";
|
||||
import { getLifecycleItemDescription } from "@/utils/lifecycleUtil";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { resolveZoneName } from "@/hooks/use-zone-friendly-name";
|
||||
import { FrigateConfig } from "@/types/frigateConfig";
|
||||
import useSWR from "swr";
|
||||
|
||||
type ObjectPathProps = {
|
||||
positions?: Position[];
|
||||
@ -45,30 +42,16 @@ export function ObjectPath({
|
||||
visible = true,
|
||||
}: ObjectPathProps) {
|
||||
const { t } = useTranslation(["views/explore"]);
|
||||
const { data: config } = useSWR<FrigateConfig>("config");
|
||||
const getAbsolutePositions = useCallback(() => {
|
||||
if (!imgRef.current || !positions) return [];
|
||||
const imgRect = imgRef.current.getBoundingClientRect();
|
||||
return positions.map((pos) => {
|
||||
if (config && pos.lifecycle_item?.data?.zones) {
|
||||
pos.lifecycle_item = {
|
||||
...pos.lifecycle_item,
|
||||
data: {
|
||||
...pos.lifecycle_item.data,
|
||||
zones_friendly_names: pos.lifecycle_item.data.zones.map((zone) => {
|
||||
return resolveZoneName(config, zone);
|
||||
}),
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
x: pos.x * imgRect.width,
|
||||
y: pos.y * imgRect.height,
|
||||
timestamp: pos.timestamp,
|
||||
lifecycle_item: pos.lifecycle_item,
|
||||
};
|
||||
});
|
||||
}, [imgRef, positions, config]);
|
||||
return positions.map((pos) => ({
|
||||
x: pos.x * imgRect.width,
|
||||
y: pos.y * imgRect.height,
|
||||
timestamp: pos.timestamp,
|
||||
lifecycle_item: pos.lifecycle_item,
|
||||
}));
|
||||
}, [positions, imgRef]);
|
||||
|
||||
const generateStraightPath = useCallback((points: Position[]) => {
|
||||
if (!points || points.length < 2) return "";
|
||||
|
||||
@ -269,6 +269,10 @@ export function PolygonCanvas({
|
||||
const updatedPolygons = [...polygons];
|
||||
const activePolygon = updatedPolygons[activePolygonIndex];
|
||||
|
||||
if (!activePolygon) {
|
||||
return;
|
||||
}
|
||||
|
||||
// add default points order for already completed polygons
|
||||
if (!activePolygon.pointsOrder && activePolygon.isFinished) {
|
||||
updatedPolygons[activePolygonIndex] = {
|
||||
|
||||
@ -31,7 +31,6 @@ import { Link } from "react-router-dom";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { usePersistence } from "@/hooks/use-persistence";
|
||||
import { isDesktop } from "react-device-detect";
|
||||
import { resolveZoneName } from "@/hooks/use-zone-friendly-name";
|
||||
|
||||
type DetailStreamProps = {
|
||||
reviewItems?: ReviewSegment[];
|
||||
@ -655,16 +654,6 @@ function LifecycleItem({
|
||||
const { t } = useTranslation("views/events");
|
||||
const { data: config } = useSWR<FrigateConfig>("config");
|
||||
|
||||
item = {
|
||||
...item,
|
||||
data: {
|
||||
...item.data,
|
||||
zones_friendly_names: item?.data?.zones?.map((zone) => {
|
||||
return resolveZoneName(config, zone);
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
const aspectRatio = useMemo(() => {
|
||||
if (!config || !item?.camera) {
|
||||
return 16 / 9;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user