diff --git a/web/src/components/timeline/DetailStream.tsx b/web/src/components/timeline/DetailStream.tsx index d133aa05a..be01eb16e 100644 --- a/web/src/components/timeline/DetailStream.tsx +++ b/web/src/components/timeline/DetailStream.tsx @@ -681,22 +681,62 @@ function LifecycleItem({ }) : ""; - const ratio = - Array.isArray(item?.data.box) && item?.data.box.length >= 4 - ? (aspectRatio * (item?.data.box[2] / item?.data.box[3])).toFixed(2) - : "N/A"; - const areaPx = - Array.isArray(item?.data.box) && item?.data.box.length >= 4 - ? Math.round( - (config?.cameras[item?.camera]?.detect?.width ?? 0) * - (config?.cameras[item?.camera]?.detect?.height ?? 0) * - (item?.data.box[2] * item?.data.box[3]), - ) - : undefined; - const areaPct = - Array.isArray(item?.data.box) && item?.data.box.length >= 4 - ? (item?.data.box[2] * item?.data.box[3]).toFixed(4) - : undefined; + const ratio = useMemo( + () => + Array.isArray(item?.data.box) && item?.data.box.length >= 4 + ? (aspectRatio * (item?.data.box[2] / item?.data.box[3])).toFixed(2) + : "N/A", + [aspectRatio, item], + ); + + const areaPx = useMemo( + () => + Array.isArray(item?.data.box) && item?.data.box.length >= 4 + ? Math.round( + (config?.cameras[item?.camera]?.detect?.width ?? 0) * + (config?.cameras[item?.camera]?.detect?.height ?? 0) * + (item?.data.box[2] * item?.data.box[3]), + ) + : undefined, + [config, item], + ); + + const areaPct = useMemo( + () => + Array.isArray(item?.data.box) && item?.data.box.length >= 4 + ? (item?.data.box[2] * item?.data.box[3]).toFixed(4) + : undefined, + [item], + ); + + const attributeAreaPx = useMemo( + () => + Array.isArray(item?.data.attribute_box) && + item?.data.attribute_box.length >= 4 + ? Math.round( + (config?.cameras[item?.camera]?.detect?.width ?? 0) * + (config?.cameras[item?.camera]?.detect?.height ?? 0) * + (item?.data.attribute_box[2] * item?.data.attribute_box[3]), + ) + : undefined, + [config, item], + ); + + const attributeAreaPct = useMemo( + () => + Array.isArray(item?.data.attribute_box) && + item?.data.attribute_box.length >= 4 + ? (item?.data.attribute_box[2] * item?.data.attribute_box[3]).toFixed(4) + : undefined, + [item], + ); + + const score = useMemo(() => { + if (item?.data?.score !== undefined) { + return (item.data.score * 100).toFixed(0) + "%"; + } + return "N/A"; + }, [item?.data?.score]); return (