Store recordings for manual events

This commit is contained in:
Nicolas Mowen 2024-04-02 06:10:06 -06:00
parent fb19912afc
commit fd204b5a3a

View File

@ -165,6 +165,7 @@ class RecordingMaintainer(threading.Thread):
Event.select( Event.select(
Event.start_time, Event.start_time,
Event.end_time, Event.end_time,
Event.data,
) )
.where( .where(
Event.camera == camera, Event.camera == camera,
@ -188,7 +189,7 @@ class RecordingMaintainer(threading.Thread):
) )
async def validate_and_move_segment( async def validate_and_move_segment(
self, camera: str, events: Event, recording: dict[str, any] self, camera: str, events: list[Event], recording: dict[str, any]
) -> None: ) -> None:
cache_path = recording["cache_path"] cache_path = recording["cache_path"]
start_time = recording["start_time"] start_time = recording["start_time"]
@ -256,6 +257,7 @@ class RecordingMaintainer(threading.Thread):
duration, duration,
cache_path, cache_path,
record_mode, record_mode,
event.data["type"] == "api",
) )
# if it doesn't overlap with an event, go ahead and drop the segment # if it doesn't overlap with an event, go ahead and drop the segment
# if it ends more than the configured pre_capture for the camera # if it ends more than the configured pre_capture for the camera
@ -347,11 +349,12 @@ class RecordingMaintainer(threading.Thread):
duration: float, duration: float,
cache_path: str, cache_path: str,
store_mode: RetainModeEnum, store_mode: RetainModeEnum,
manual_event: bool = False, # if this segment is being moved due to a manual event
) -> Optional[Recordings]: ) -> Optional[Recordings]:
segment_info = self.segment_stats(camera, start_time, end_time) segment_info = self.segment_stats(camera, start_time, end_time)
# check if the segment shouldn't be stored # check if the segment shouldn't be stored
if segment_info.should_discard_segment(store_mode): if not manual_event and segment_info.should_discard_segment(store_mode):
Path(cache_path).unlink(missing_ok=True) Path(cache_path).unlink(missing_ok=True)
self.end_time_cache.pop(cache_path, None) self.end_time_cache.pop(cache_path, None)
return return
@ -424,7 +427,8 @@ class RecordingMaintainer(threading.Thread):
Recordings.duration: duration, Recordings.duration: duration,
Recordings.motion: segment_info.motion_count, Recordings.motion: segment_info.motion_count,
# TODO: update this to store list of active objects at some point # TODO: update this to store list of active objects at some point
Recordings.objects: segment_info.active_object_count, Recordings.objects: segment_info.active_object_count
+ (1 if manual_event else 0),
Recordings.regions: segment_info.region_count, Recordings.regions: segment_info.region_count,
Recordings.dBFS: segment_info.average_dBFS, Recordings.dBFS: segment_info.average_dBFS,
Recordings.segment_size: segment_size, Recordings.segment_size: segment_size,