From f02ef78d035c127f7d19d09ff14bc7ca563eaa03 Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Thu, 11 Jan 2024 18:59:27 -0700 Subject: [PATCH] Reduce grouped up image refreshes --- frigate/http.py | 6 +++--- web/src/components/camera/DynamicCameraImage.tsx | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/frigate/http.py b/frigate/http.py index 1d9875405..d7ee87d2f 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -784,14 +784,14 @@ def hourly_timeline_activity(camera_name: str): df.set_index(["date"], inplace=True) # normalize data - df["count"] = np.log10(df["count"], where=df["count"] > 0) + df["count"] = np.clip(np.log10(df["count"], where=df["count"] > 0), None, 10) df = df.resample("T").mean().fillna(0) # change types for output - df.index = (df.index.astype(int) // (10 ** 9)) + df.index = df.index.astype(int) // (10**9) df["count"] = df["count"].astype(int) df["hasObjects"] = df["hasObjects"].astype(bool) - hours[key] = df.reset_index().to_dict('records') + hours[key] = df.reset_index().to_dict("records") return jsonify(hours) diff --git a/web/src/components/camera/DynamicCameraImage.tsx b/web/src/components/camera/DynamicCameraImage.tsx index 091fcda2e..3f84ec90d 100644 --- a/web/src/components/camera/DynamicCameraImage.tsx +++ b/web/src/components/camera/DynamicCameraImage.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useMemo, useState } from "react"; import { AspectRatio } from "../ui/aspect-ratio"; import CameraImage from "./CameraImage"; import { LuEar } from "react-icons/lu"; @@ -21,6 +21,10 @@ export default function DynamicCameraImage({ }: DynamicCameraImageProps) { const [key, setKey] = useState(Date.now()); const [activeObjects, setActiveObjects] = useState([]); + const hasActiveObjects = useMemo( + () => activeObjects.length > 0, + [activeObjects] + ); const { payload: detectingMotion } = useMotionActivity(camera.name); const { payload: event } = useFrigateEvents(); @@ -58,8 +62,9 @@ export default function DynamicCameraImage({ const handleLoad = useCallback(() => { const loadTime = Date.now() - key; - const loadInterval = - activeObjects.length > 0 ? INTERVAL_ACTIVE_MS : INTERVAL_INACTIVE_MS; + const loadInterval = hasActiveObjects + ? INTERVAL_ACTIVE_MS + : INTERVAL_INACTIVE_MS; setTimeout( () => { @@ -67,7 +72,7 @@ export default function DynamicCameraImage({ }, loadTime > loadInterval ? 1 : loadInterval ); - }, [activeObjects, key]); + }, [hasActiveObjects, key]); return (