Compare commits

...

3 Commits

Author SHA1 Message Date
Josh Hawkins
e8b9225175
Recordings API and calendar UI performance improvements (#22352)
Some checks are pending
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
* optimize recordings/summary endpoint db query

replace strftime with integer arithmetic. increases speed by about 6x, especially noticeable for installs with long retention days

* optimize calendar rendering with Set lookups and remove unnecessary remount key

The old code built Date[] arrays with a TZDate object for every day in recording history (365+ timezone-aware date constructions). react-day-picker then did O(visible × history) date comparisons to match each of the displayed days against these arrays. Now we build Set<string> from the raw keys (zero date construction), and pass matcher functions that do O(1) Set.has() lookups. react-day-picker only calls these for visible days

* clean up
2026-03-09 17:22:01 -06:00
Nicolas Mowen
119137c4fe
Update Intel Deps (#22351)
* Update intel deps

* Cleanup install deps

* Cleanup install deps
2026-03-09 17:15:40 -06:00
Josh Hawkins
9cbd80d981
Add motion previews filter (#22347)
* add ability to filter motion previews via heatmap grid

* i18n

* use dialog on mobile
2026-03-09 14:14:13 -06:00
7 changed files with 303 additions and 84 deletions

View File

@ -105,9 +105,9 @@ if [[ "${TARGETARCH}" == "amd64" ]]; then
# install legacy and standard intel icd and level-zero-gpu
# see https://github.com/intel/compute-runtime/blob/master/LEGACY_PLATFORMS.md for more info
# needed core package
wget https://github.com/intel/compute-runtime/releases/download/24.52.32224.5/libigdgmm12_22.5.5_amd64.deb
dpkg -i libigdgmm12_22.5.5_amd64.deb
rm libigdgmm12_22.5.5_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/25.13.33276.19/libigdgmm12_22.7.0_amd64.deb
dpkg -i libigdgmm12_22.7.0_amd64.deb
rm libigdgmm12_22.7.0_amd64.deb
# legacy packages
wget https://github.com/intel/compute-runtime/releases/download/24.35.30872.36/intel-opencl-icd-legacy1_24.35.30872.36_amd64.deb
@ -115,18 +115,19 @@ if [[ "${TARGETARCH}" == "amd64" ]]; then
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17537.24/intel-igc-opencl_1.0.17537.24_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/igc-1.0.17537.24/intel-igc-core_1.0.17537.24_amd64.deb
# standard packages
wget https://github.com/intel/compute-runtime/releases/download/24.52.32224.5/intel-opencl-icd_24.52.32224.5_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/24.52.32224.5/intel-level-zero-gpu_1.6.32224.5_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/v2.5.6/intel-igc-opencl-2_2.5.6+18417_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/v2.5.6/intel-igc-core-2_2.5.6+18417_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/25.13.33276.19/intel-opencl-icd_25.13.33276.19_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/25.13.33276.19/intel-level-zero-gpu_1.6.33276.19_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/v2.10.10/intel-igc-opencl-2_2.10.10+18926_amd64.deb
wget https://github.com/intel/intel-graphics-compiler/releases/download/v2.10.10/intel-igc-core-2_2.10.10+18926_amd64.deb
# npu packages
wget https://github.com/oneapi-src/level-zero/releases/download/v1.21.9/level-zero_1.21.9+u22.04_amd64.deb
wget https://github.com/intel/linux-npu-driver/releases/download/v1.17.0/intel-driver-compiler-npu_1.17.0.20250508-14912879441_ubuntu22.04_amd64.deb
wget https://github.com/intel/linux-npu-driver/releases/download/v1.17.0/intel-fw-npu_1.17.0.20250508-14912879441_ubuntu22.04_amd64.deb
wget https://github.com/intel/linux-npu-driver/releases/download/v1.17.0/intel-level-zero-npu_1.17.0.20250508-14912879441_ubuntu22.04_amd64.deb
wget https://github.com/oneapi-src/level-zero/releases/download/v1.28.2/level-zero_1.28.2+u22.04_amd64.deb
wget https://github.com/intel/linux-npu-driver/releases/download/v1.19.0/intel-driver-compiler-npu_1.19.0.20250707-16111289554_ubuntu22.04_amd64.deb
wget https://github.com/intel/linux-npu-driver/releases/download/v1.19.0/intel-fw-npu_1.19.0.20250707-16111289554_ubuntu22.04_amd64.deb
wget https://github.com/intel/linux-npu-driver/releases/download/v1.19.0/intel-level-zero-npu_1.19.0.20250707-16111289554_ubuntu22.04_amd64.deb
dpkg -i *.deb
rm *.deb
apt-get -qq install -f -y
fi
if [[ "${TARGETARCH}" == "arm64" ]]; then

View File

@ -1,5 +1,6 @@
"""Recording APIs."""
import datetime as dt
import logging
from datetime import datetime, timedelta
from functools import reduce
@ -97,45 +98,22 @@ def all_recordings_summary(
days: dict[str, bool] = {}
for period_start, period_end, period_offset in dst_periods:
hours_offset = int(period_offset / 60 / 60)
minutes_offset = int(period_offset / 60 - hours_offset * 60)
period_hour_modifier = f"{hours_offset} hour"
period_minute_modifier = f"{minutes_offset} minute"
day_expr = ((Recordings.start_time + period_offset) / 86400).cast("int")
period_query = (
Recordings.select(
fn.strftime(
"%Y-%m-%d",
fn.datetime(
Recordings.start_time,
"unixepoch",
period_hour_modifier,
period_minute_modifier,
),
).alias("day")
)
Recordings.select(day_expr.alias("day_idx"))
.where(
(Recordings.camera << camera_list)
& (Recordings.end_time >= period_start)
& (Recordings.start_time <= period_end)
)
.group_by(
fn.strftime(
"%Y-%m-%d",
fn.datetime(
Recordings.start_time,
"unixepoch",
period_hour_modifier,
period_minute_modifier,
),
)
)
.order_by(Recordings.start_time.desc())
.distinct()
.namedtuples()
)
for g in period_query:
days[g.day] = True
day_str = (dt.date(1970, 1, 1) + dt.timedelta(days=g.day_idx)).isoformat()
days[day_str] = True
return JSONResponse(content=dict(sorted(days.items())))

View File

@ -80,6 +80,9 @@
"back": "Back",
"empty": "No previews available",
"noPreview": "Preview unavailable",
"seekAria": "Seek {{camera}} player to {{time}}"
"seekAria": "Seek {{camera}} player to {{time}}",
"filter": "Filter",
"filterDesc": "Select areas to only show clips with motion in those regions.",
"filterClear": "Clear"
}
}

View File

@ -0,0 +1,150 @@
import { baseUrl } from "@/api/baseUrl";
import { useCallback, useRef } from "react";
const GRID_SIZE = 16;
type MotionRegionFilterGridProps = {
cameraName: string;
selectedCells: Set<number>;
onCellsChange: (cells: Set<number>) => void;
};
export default function MotionRegionFilterGrid({
cameraName,
selectedCells,
onCellsChange,
}: MotionRegionFilterGridProps) {
const paintingRef = useRef<{ active: boolean; adding: boolean }>({
active: false,
adding: true,
});
const lastCellRef = useRef<number>(-1);
const gridRef = useRef<HTMLDivElement>(null);
const toggleCell = useCallback(
(index: number, forceAdd?: boolean) => {
const next = new Set(selectedCells);
if (forceAdd !== undefined) {
if (forceAdd) {
next.add(index);
} else {
next.delete(index);
}
} else if (next.has(index)) {
next.delete(index);
} else {
next.add(index);
}
onCellsChange(next);
},
[selectedCells, onCellsChange],
);
const getCellFromPoint = useCallback(
(clientX: number, clientY: number): number | null => {
const grid = gridRef.current;
if (!grid) {
return null;
}
const rect = grid.getBoundingClientRect();
const x = clientX - rect.left;
const y = clientY - rect.top;
if (x < 0 || y < 0 || x >= rect.width || y >= rect.height) {
return null;
}
const col = Math.floor((x / rect.width) * GRID_SIZE);
const row = Math.floor((y / rect.height) * GRID_SIZE);
return row * GRID_SIZE + col;
},
[],
);
const handlePointerDown = useCallback(
(e: React.PointerEvent) => {
e.preventDefault();
const index = getCellFromPoint(e.clientX, e.clientY);
if (index === null) {
return;
}
const adding = !selectedCells.has(index);
paintingRef.current = { active: true, adding };
lastCellRef.current = index;
toggleCell(index, adding);
},
[selectedCells, toggleCell, getCellFromPoint],
);
const handlePointerMove = useCallback(
(e: React.PointerEvent) => {
if (!paintingRef.current.active) {
return;
}
const index = getCellFromPoint(e.clientX, e.clientY);
if (index === null || index === lastCellRef.current) {
return;
}
lastCellRef.current = index;
toggleCell(index, paintingRef.current.adding);
},
[toggleCell, getCellFromPoint],
);
const handlePointerUp = useCallback(() => {
paintingRef.current.active = false;
lastCellRef.current = -1;
}, []);
return (
<div className="space-y-2">
<div
className="relative aspect-video w-full select-none overflow-hidden rounded-lg"
style={{ touchAction: "none" }}
onPointerUp={handlePointerUp}
onPointerLeave={handlePointerUp}
>
<img
src={`${baseUrl}api/${cameraName}/latest.jpg?h=500`}
className="absolute inset-0 size-full object-contain"
draggable={false}
alt=""
/>
<div
ref={gridRef}
className="absolute inset-0 grid"
style={{
gridTemplateColumns: `repeat(${GRID_SIZE}, 1fr)`,
gridTemplateRows: `repeat(${GRID_SIZE}, 1fr)`,
}}
onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
>
{Array.from({ length: GRID_SIZE * GRID_SIZE }, (_, index) => {
const isSelected = selectedCells.has(index);
return (
<div
key={index}
className={
isSelected
? "border border-severity_alert/60 bg-severity_alert/40"
: "border border-transparent hover:bg-white/20"
}
/>
);
})}
</div>
</div>
</div>
);
}

View File

@ -3,7 +3,7 @@ import { Calendar } from "../ui/calendar";
import { ButtonHTMLAttributes, useEffect, useMemo, useRef } from "react";
import { FaCircle } from "react-icons/fa";
import { getUTCOffset } from "@/utils/dateUtil";
import { type DayButtonProps, TZDate } from "react-day-picker";
import { type DayButtonProps } from "react-day-picker";
import { LAST_24_HOURS_KEY } from "@/types/filter";
import { useUserPersistence } from "@/hooks/use-user-persistence";
import { cn } from "@/lib/utils";
@ -38,60 +38,46 @@ export default function ReviewActivityCalendar({
}, []);
const modifiers = useMemo(() => {
const recordings: Date[] = [];
const alerts: Date[] = [];
const detections: Date[] = [];
const recordingsSet = new Set<string>();
const alertsSet = new Set<string>();
const detectionsSet = new Set<string>();
// Handle recordings
if (recordingsSummary) {
Object.keys(recordingsSummary).forEach((date) => {
if (date === LAST_24_HOURS_KEY) {
return;
for (const date of Object.keys(recordingsSummary)) {
if (date !== LAST_24_HOURS_KEY) {
recordingsSet.add(date);
}
const parts = date.split("-");
const cal = new TZDate(date + "T00:00:00", timezone);
cal.setFullYear(
parseInt(parts[0]),
parseInt(parts[1]) - 1,
parseInt(parts[2]),
);
recordings.push(cal);
});
}
}
// Handle reviews if present
if (reviewSummary) {
Object.entries(reviewSummary).forEach(([date, data]) => {
if (date === LAST_24_HOURS_KEY) {
return;
}
const parts = date.split("-");
const cal = new TZDate(date + "T00:00:00", timezone);
cal.setFullYear(
parseInt(parts[0]),
parseInt(parts[1]) - 1,
parseInt(parts[2]),
);
for (const [date, data] of Object.entries(reviewSummary)) {
if (date === LAST_24_HOURS_KEY) continue;
if (data.total_alert > data.reviewed_alert) {
alerts.push(cal);
alertsSet.add(date);
} else if (data.total_detection > data.reviewed_detection) {
detections.push(cal);
detectionsSet.add(date);
}
});
}
}
return { alerts, detections, recordings };
}, [reviewSummary, recordingsSummary, timezone]);
const formatDay = (day: Date) => {
const y = day.getFullYear();
const m = String(day.getMonth() + 1).padStart(2, "0");
const d = String(day.getDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
};
return {
recordings: (day: Date) => recordingsSet.has(formatDay(day)),
alerts: (day: Date) => alertsSet.has(formatDay(day)),
detections: (day: Date) => detectionsSet.has(formatDay(day)),
};
}, [reviewSummary, recordingsSummary]);
return (
<Calendar
key={selectedDay ? selectedDay.toISOString() : "reset"}
mode="single"
disabled={disabledDates}
showOutsideDays={false}
@ -223,7 +209,6 @@ export function TimezoneAwareCalendar({
return (
<Calendar
key={selectedDay ? selectedDay.toISOString() : "reset"}
mode="single"
disabled={disabledDates}
showOutsideDays={false}

View File

@ -79,7 +79,17 @@ import { GiSoundWaves } from "react-icons/gi";
import useKeyboardListener from "@/hooks/use-keyboard-listener";
import { useTimelineZoom } from "@/hooks/use-timeline-zoom";
import { useTranslation } from "react-i18next";
import { FaCog } from "react-icons/fa";
import { FaCog, FaFilter } from "react-icons/fa";
import MotionRegionFilterGrid from "@/components/filter/MotionRegionFilterGrid";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import ReviewActivityCalendar from "@/components/overlay/ReviewActivityCalendar";
import PlatformAwareDialog from "@/components/overlay/dialog/PlatformAwareDialog";
import MotionPreviewsPane from "./MotionPreviewsPane";
@ -1117,6 +1127,13 @@ function MotionReview({
const [controlsOpen, setControlsOpen] = useState(false);
const [dimStrength, setDimStrength] = useState(82);
const [isPreviewSettingsOpen, setIsPreviewSettingsOpen] = useState(false);
const [motionFilterCells, setMotionFilterCells] = useState<Set<number>>(
new Set(),
);
const [pendingFilterCells, setPendingFilterCells] = useState<Set<number>>(
new Set(),
);
const [isRegionFilterOpen, setIsRegionFilterOpen] = useState(false);
const objectReviewItems = useMemo(
() =>
@ -1314,6 +1331,68 @@ function MotionReview({
updateSelectedDay={onUpdateSelectedDay}
/>
)}
<Dialog
open={isRegionFilterOpen}
onOpenChange={(open) => {
if (open) {
setPendingFilterCells(new Set(motionFilterCells));
}
setIsRegionFilterOpen(open);
}}
>
<DialogTrigger asChild>
<Button
className={cn(
isDesktop ? "flex items-center gap-2" : "rounded-lg",
)}
size="sm"
variant={motionFilterCells.size > 0 ? "select" : "default"}
aria-label={t("motionPreviews.filter")}
>
<FaFilter
className={
motionFilterCells.size > 0
? "text-selected-foreground"
: "text-secondary-foreground"
}
/>
{isDesktop && t("motionPreviews.filter")}
</Button>
</DialogTrigger>
<DialogContent className="max-h-[90dvh] overflow-y-auto sm:max-w-[85%] md:max-w-[70%] lg:max-w-[60%]">
<DialogHeader>
<DialogTitle>{t("motionPreviews.filter")}</DialogTitle>
<DialogDescription>
{t("motionPreviews.filterDesc")}
</DialogDescription>
</DialogHeader>
<MotionRegionFilterGrid
cameraName={selectedMotionPreviewCamera.name}
selectedCells={pendingFilterCells}
onCellsChange={setPendingFilterCells}
/>
<DialogFooter className="justify-end gap-1">
<Button
variant="outline"
disabled={pendingFilterCells.size === 0}
onClick={() => {
setPendingFilterCells(new Set());
}}
>
{t("motionPreviews.filterClear")}
</Button>
<Button
variant="select"
onClick={() => {
setMotionFilterCells(new Set(pendingFilterCells));
setIsRegionFilterOpen(false);
}}
>
{t("button.apply", { ns: "common" })}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<PlatformAwareDialog
trigger={
<Button
@ -1456,6 +1535,7 @@ function MotionReview({
}
playbackRate={playbackRate}
nonMotionAlpha={dimStrength / 100}
motionFilterCells={motionFilterCells}
onSeek={(timestamp) => {
onOpenRecording({
camera: selectedMotionPreviewCamera.name,

View File

@ -589,6 +589,7 @@ type MotionPreviewsPaneProps = {
isLoadingMotionRanges?: boolean;
playbackRate: number;
nonMotionAlpha: number;
motionFilterCells?: Set<number>;
onSeek: (timestamp: number) => void;
};
@ -600,6 +601,7 @@ export default function MotionPreviewsPane({
isLoadingMotionRanges = false,
playbackRate,
nonMotionAlpha,
motionFilterCells,
onSeek,
}: MotionPreviewsPaneProps) {
const { t } = useTranslation(["views/events"]);
@ -879,6 +881,26 @@ export default function MotionPreviewsPane({
],
);
const filteredClipData = useMemo(() => {
if (!motionFilterCells || motionFilterCells.size === 0) {
return clipData;
}
return clipData.filter(({ motionHeatmap }) => {
if (!motionHeatmap) {
return false;
}
for (const cellIndex of motionFilterCells) {
if ((motionHeatmap[cellIndex.toString()] ?? 0) > 0) {
return true;
}
}
return false;
});
}, [clipData, motionFilterCells]);
const hasCurrentHourRanges = useMemo(
() => motionRanges.some((range) => isCurrentHour(range.end_time)),
[motionRanges],
@ -901,13 +923,13 @@ export default function MotionPreviewsPane({
ref={setContentNode}
className="no-scrollbar min-h-0 flex-1 overflow-y-auto"
>
{clipData.length === 0 ? (
{filteredClipData.length === 0 ? (
<div className="flex h-full items-center justify-center text-lg text-primary">
{t("motionPreviews.empty")}
</div>
) : (
<div className="grid grid-cols-1 gap-2 pb-2 sm:grid-cols-2 md:gap-4 xl:grid-cols-4">
{clipData.map(
{filteredClipData.map(
({ range, preview, fallbackFrameTimes, motionHeatmap }, idx) => {
const clipId = `${camera.name}-${range.start_time}-${range.end_time}-${idx}`;
const isMounted = mountedClips.has(clipId);