add velocity angle to frontend

This commit is contained in:
Josh Hawkins 2024-12-23 08:21:13 -06:00
parent f2aabfec50
commit d627e6ccda
5 changed files with 32 additions and 4 deletions

View File

@ -323,6 +323,7 @@ def events_explore(limit: int = 10):
"description", "description",
"sub_label_score", "sub_label_score",
"average_estimated_speed", "average_estimated_speed",
"velocity_angle",
] ]
}, },
"event_count": label_counts[event.label], "event_count": label_counts[event.label],
@ -596,6 +597,7 @@ def events_search(request: Request, params: EventsSearchQueryParams = Depends())
"description", "description",
"sub_label_score", "sub_label_score",
"average_estimated_speed", "average_estimated_speed",
"velocity_angle",
] ]
} }

View File

@ -27,6 +27,7 @@ def should_update_db(prev_event: Event, current_event: Event) -> bool:
or prev_event["end_time"] != current_event["end_time"] or prev_event["end_time"] != current_event["end_time"]
or prev_event["average_estimated_speed"] or prev_event["average_estimated_speed"]
!= current_event["average_estimated_speed"] != current_event["average_estimated_speed"]
or prev_event["velocity_angle"] != current_event["velocity_angle"]
): ):
return True return True
return False return False
@ -212,6 +213,7 @@ class EventProcessor(threading.Thread):
"top_score": event_data["top_score"], "top_score": event_data["top_score"],
"attributes": attributes, "attributes": attributes,
"average_estimated_speed": event_data["average_estimated_speed"], "average_estimated_speed": event_data["average_estimated_speed"],
"velocity_angle": event_data["velocity_angle"],
"type": "object", "type": "object",
"max_severity": event_data.get("max_severity"), "max_severity": event_data.get("max_severity"),
}, },

View File

@ -138,6 +138,7 @@ class TrackedObject:
"score": obj_data["score"], "score": obj_data["score"],
"attributes": obj_data["attributes"], "attributes": obj_data["attributes"],
"current_estimated_speed": self.current_estimated_speed, "current_estimated_speed": self.current_estimated_speed,
"velocity_angle": self.velocity_angle,
} }
thumb_update = True thumb_update = True
@ -217,7 +218,7 @@ class TrackedObject:
self.speed_history self.speed_history
) )
logger.debug( logger.debug(
f"Camera: {self.camera_config.name}, tracked object ID: {self.obj_data['id']}, zone: {name}, pixel velocity: {str(tuple(np.round(self.obj_data['estimate_velocity']).flatten().astype(int)))}, speed magnitude: {speed_magnitude}, estimated speed: {self.current_estimated_speed:.1f}, average speed: {self.average_estimated_speed:.1f}, length: {len(self.speed_history)}" f"Camera: {self.camera_config.name}, tracked object ID: {self.obj_data['id']}, zone: {name}, pixel velocity: {str(tuple(np.round(self.obj_data['estimate_velocity']).flatten().astype(int)))}, speed magnitude: {speed_magnitude}, velocity angle: {self.velocity_angle}, estimated speed: {self.current_estimated_speed:.1f}, average speed: {self.average_estimated_speed:.1f}, length: {len(self.speed_history)}"
) )
# update loitering status # update loitering status

View File

@ -25,6 +25,7 @@ import { baseUrl } from "@/api/baseUrl";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import ActivityIndicator from "@/components/indicators/activity-indicator"; import ActivityIndicator from "@/components/indicators/activity-indicator";
import { import {
FaArrowRight,
FaCheckCircle, FaCheckCircle,
FaChevronDown, FaChevronDown,
FaDownload, FaDownload,
@ -328,6 +329,18 @@ function ObjectDetailsTab({
} }
}, [search]); }, [search]);
const velocityAngle = useMemo(() => {
if (!search || !search.data?.velocity_angle) {
return undefined;
}
if (search.data?.velocity_angle != 0) {
return search.data?.velocity_angle.toFixed(1);
} else {
return undefined;
}
}, [search]);
const updateDescription = useCallback(() => { const updateDescription = useCallback(() => {
if (!search) { if (!search) {
return; return;
@ -441,13 +454,22 @@ function ObjectDetailsTab({
</div> </div>
{averageEstimatedSpeed && ( {averageEstimatedSpeed && (
<div className="flex flex-col gap-1.5"> <div className="flex flex-col gap-1.5">
<div className="text-sm text-primary/40">Estimated Speeds</div> <div className="text-sm text-primary/40">Estimated Speed</div>
<div className="flex flex-col space-y-0.5 text-sm"> <div className="flex flex-col space-y-0.5 text-sm">
{averageEstimatedSpeed && ( {averageEstimatedSpeed && (
<div> <div className="flex flex-row items-center gap-2">
{averageEstimatedSpeed}{" "} {averageEstimatedSpeed}{" "}
{config?.ui.unit_system == "imperial" ? "mph" : "kph"}{" "} {config?.ui.unit_system == "imperial" ? "mph" : "kph"}{" "}
<span className="text-primary/40">(average)</span> {velocityAngle != undefined && (
<span className="text-primary/40">
<FaArrowRight
size={10}
style={{
transform: `rotate(${(360 - Number(velocityAngle)) % 360}deg)`,
}}
/>
</span>
)}
</div> </div>
)} )}
</div> </div>

View File

@ -56,6 +56,7 @@ export type SearchResult = {
type: "object" | "audio" | "manual"; type: "object" | "audio" | "manual";
description?: string; description?: string;
average_estimated_speed: number; average_estimated_speed: number;
velocity_angle: number;
}; };
}; };