Keep track of total segment and hour averages

This commit is contained in:
Nick Mowen 2022-09-25 10:20:45 -06:00
parent 384595f5e6
commit 1284e3edaa
4 changed files with 17 additions and 3 deletions

BIN
config/rockchip.rknn Normal file

Binary file not shown.

View File

@ -752,7 +752,6 @@ def recordings(camera_name):
Recordings.start_time,
Recordings.end_time,
Recordings.segment_size,
Recordings.duration,
Recordings.motion,
Recordings.objects,
)

View File

@ -287,7 +287,7 @@ class RecordingMaintainer(threading.Thread):
try:
segment_size = float(os.path.getsize(file_path)) / 1000000
except OSError:
segment_size = -1
segment_size = 0
rand_id = "".join(
random.choices(string.ascii_lowercase + string.digits, k=6)

View File

@ -23,10 +23,14 @@ class StorageMaintainer(threading.Thread):
def calculate_camera_segment_sizes(self):
"""Calculate the size of each cameras recording segments."""
total_avg_segment = 0.0
total_avg_hour = 0.0
for camera in self.config.cameras.keys():
if not self.config.cameras[camera].record.enabled:
continue
# get average of non-zero segment sizes to ignore segment with no value
avg_segment_size = round(
Recordings.select(fn.AVG(Recordings.segment_size))
.where(Recordings.camera == camera)
@ -34,16 +38,27 @@ class StorageMaintainer(threading.Thread):
.scalar(),
2,
)
# get average of an hour using the average segment size
segment_duration = int(
Recordings.select(Recordings.duration)
.where(Recordings.camera == camera)
.scalar()
)
avg_hour_size = round((3600 / segment_duration) * avg_segment_size, 2)
total_avg_segment += avg_segment_size
total_avg_hour += avg_hour_size
self.avg_segment_sizes[camera] = {
"segment": avg_segment_size,
"hour": (3600 / segment_duration) * avg_segment_size,
"hour": avg_hour_size,
}
self.avg_segment_sizes["total"] = {
"segment": total_avg_segment,
"hour": total_avg_hour,
}
def run(self):
# Check storage consumption every 5 minutes
while not self.stop_event.wait(20):