diff --git a/frigate/http.py b/frigate/http.py index 295c4ae67..c453f2a75 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -115,7 +115,7 @@ def is_healthy(): @bp.route("/events/summary") def events_summary(): tz_name = request.args.get("timezone", default="utc", type=str) - hour_modifier, minute_modifier = get_tz_modifiers(tz_name) + hour_modifier, minute_modifier, seconds_offset = get_tz_modifiers(tz_name) has_clip = request.args.get("has_clip", type=int) has_snapshot = request.args.get("has_snapshot", type=int) @@ -149,12 +149,7 @@ def events_summary(): Event.camera, Event.label, Event.sub_label, - fn.strftime( - "%Y-%m-%d", - fn.datetime( - Event.start_time, "unixepoch", hour_modifier, minute_modifier - ), - ), + (Event.start_time + seconds_offset).cast("int") / (3600 * 24), Event.zones, ) ) @@ -995,7 +990,7 @@ def events(): if time_range != DEFAULT_TIME_RANGE: # get timezone arg to ensure browser times are used tz_name = request.args.get("timezone", default="utc", type=str) - hour_modifier, minute_modifier = get_tz_modifiers(tz_name) + hour_modifier, minute_modifier, seconds_offset = get_tz_modifiers(tz_name) times = time_range.split(",") time_after = times[0] @@ -1569,7 +1564,7 @@ def get_recordings_storage_usage(): @bp.route("//recordings/summary") def recordings_summary(camera_name): tz_name = request.args.get("timezone", default="utc", type=str) - hour_modifier, minute_modifier = get_tz_modifiers(tz_name) + hour_modifier, minute_modifier, seconds_offset = get_tz_modifiers(tz_name) recording_groups = ( Recordings.select( fn.strftime( @@ -1583,12 +1578,8 @@ def recordings_summary(camera_name): fn.SUM(Recordings.objects).alias("objects"), ) .where(Recordings.camera == camera_name) - .group_by( - Recordings.start_time.cast("int") / 3600 - ) - .order_by( - Recordings.start_time.desc() - ) + .group_by((Recordings.start_time + seconds_offset).cast("int") / 3600) + .order_by(Recordings.start_time.desc()) .namedtuples() ) @@ -1603,9 +1594,7 @@ def recordings_summary(camera_name): fn.COUNT(Event.id).alias("count"), ) .where(Event.camera == camera_name, Event.has_clip) - .group_by( - Event.start_time.cast("int") / 3600 - ) + .group_by((Event.start_time + seconds_offset).cast("int") / 3600) .namedtuples() ) diff --git a/frigate/util/builtin.py b/frigate/util/builtin.py index a0f0d7725..b93bfd214 100644 --- a/frigate/util/builtin.py +++ b/frigate/util/builtin.py @@ -156,7 +156,7 @@ def load_labels(path, encoding="utf-8", prefill=91): return labels -def get_tz_modifiers(tz_name: str) -> Tuple[str, str]: +def get_tz_modifiers(tz_name: str) -> Tuple[str, str, int]: seconds_offset = ( datetime.datetime.now(pytz.timezone(tz_name)).utcoffset().total_seconds() ) @@ -164,7 +164,7 @@ def get_tz_modifiers(tz_name: str) -> Tuple[str, str]: minutes_offset = int(seconds_offset / 60 - hours_offset * 60) hour_modifier = f"{hours_offset} hour" minute_modifier = f"{minutes_offset} minute" - return hour_modifier, minute_modifier + return hour_modifier, minute_modifier, seconds_offset def to_relative_box( diff --git a/migrations/020_update_index_recordings.py b/migrations/020_update_index_recordings.py index 9d28ccea3..2d236ed2a 100644 --- a/migrations/020_update_index_recordings.py +++ b/migrations/020_update_index_recordings.py @@ -1,4 +1,4 @@ -"""Peewee migrations -- 011_update_indexes.py. +"""Peewee migrations -- 020_update_index_recordings.py. Some examples (model - class or model name):: @@ -34,10 +34,10 @@ def migrate(migrator, database, fake=False, **kwargs): ) migrator.sql( 'CREATE INDEX "recordings_api_recordings_summary" ON "recordings" ("camera", "start_time" DESC, "duration", "motion", "objects")' - ) + ) migrator.sql( 'CREATE INDEX "recordings_start_time" ON "recordings" ("start_time")' - ) + ) def rollback(migrator, database, fake=False, **kwargs):