Reduce grouped up image refreshes

This commit is contained in:
Nick Mowen 2024-01-11 18:59:27 -07:00
parent 8b95052768
commit f02ef78d03
2 changed files with 12 additions and 7 deletions

View File

@ -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)

View File

@ -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<string[]>([]);
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 (
<AspectRatio