mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 09:45:22 +03:00
Use timezone for recording and recordings summary endpoints
This commit is contained in:
parent
43d43524ab
commit
b23f50c549
@ -88,6 +88,7 @@ def is_healthy():
|
|||||||
@bp.route("/events/summary")
|
@bp.route("/events/summary")
|
||||||
def events_summary():
|
def events_summary():
|
||||||
tz_name = request.args.get("timezone", default="localtime", type=str)
|
tz_name = request.args.get("timezone", default="localtime", type=str)
|
||||||
|
tz_offset = f"{int(datetime.now(pytz.timezone(tz_name)).utcoffset().total_seconds()/60/60)} hour"
|
||||||
has_clip = request.args.get("has_clip", type=int)
|
has_clip = request.args.get("has_clip", type=int)
|
||||||
has_snapshot = request.args.get("has_snapshot", type=int)
|
has_snapshot = request.args.get("has_snapshot", type=int)
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ def events_summary():
|
|||||||
Event.camera,
|
Event.camera,
|
||||||
Event.label,
|
Event.label,
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d", fn.datetime(Event.start_time, "unixepoch", tz_name)
|
"%Y-%m-%d", fn.datetime(Event.start_time, "unixepoch", "utc", tz_offset)
|
||||||
).alias("day"),
|
).alias("day"),
|
||||||
Event.zones,
|
Event.zones,
|
||||||
fn.COUNT(Event.id).alias("count"),
|
fn.COUNT(Event.id).alias("count"),
|
||||||
@ -117,7 +118,7 @@ def events_summary():
|
|||||||
Event.camera,
|
Event.camera,
|
||||||
Event.label,
|
Event.label,
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d", fn.datetime(Event.start_time, "unixepoch", tz_name)
|
"%Y-%m-%d", fn.datetime(Event.start_time, "unixepoch", "utc", tz_offset)
|
||||||
),
|
),
|
||||||
Event.zones,
|
Event.zones,
|
||||||
)
|
)
|
||||||
@ -798,12 +799,13 @@ def get_recordings_storage_usage():
|
|||||||
# return hourly summary for recordings of camera
|
# return hourly summary for recordings of camera
|
||||||
@bp.route("/<camera_name>/recordings/summary")
|
@bp.route("/<camera_name>/recordings/summary")
|
||||||
def recordings_summary(camera_name):
|
def recordings_summary(camera_name):
|
||||||
tz_name = request.args.get("timezone", default="localtime", type=str)
|
tz_name = request.args.get("timezone", default="utc", type=str)
|
||||||
|
tz_offset = f"{int(datetime.now(pytz.timezone(tz_name)).utcoffset().total_seconds()/60/60)} hour"
|
||||||
recording_groups = (
|
recording_groups = (
|
||||||
Recordings.select(
|
Recordings.select(
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d %H",
|
"%Y-%m-%d %H",
|
||||||
fn.datetime(Recordings.start_time, "unixepoch", tz_name),
|
fn.datetime(Recordings.start_time, "unixepoch", "utc", tz_offset),
|
||||||
).alias("hour"),
|
).alias("hour"),
|
||||||
fn.SUM(Recordings.duration).alias("duration"),
|
fn.SUM(Recordings.duration).alias("duration"),
|
||||||
fn.SUM(Recordings.motion).alias("motion"),
|
fn.SUM(Recordings.motion).alias("motion"),
|
||||||
@ -813,13 +815,13 @@ def recordings_summary(camera_name):
|
|||||||
.group_by(
|
.group_by(
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d %H",
|
"%Y-%m-%d %H",
|
||||||
fn.datetime(Recordings.start_time, "unixepoch", tz_name),
|
fn.datetime(Recordings.start_time, "unixepoch", "utc", tz_offset),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.order_by(
|
.order_by(
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d H",
|
"%Y-%m-%d H",
|
||||||
fn.datetime(Recordings.start_time, "unixepoch", tz_name),
|
fn.datetime(Recordings.start_time, "unixepoch", "utc", tz_offset),
|
||||||
).desc()
|
).desc()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -827,14 +829,16 @@ def recordings_summary(camera_name):
|
|||||||
event_groups = (
|
event_groups = (
|
||||||
Event.select(
|
Event.select(
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d %H", fn.datetime(Event.start_time, "unixepoch", tz_name)
|
"%Y-%m-%d %H",
|
||||||
|
fn.datetime(Event.start_time, "unixepoch", "utc", tz_offset),
|
||||||
).alias("hour"),
|
).alias("hour"),
|
||||||
fn.COUNT(Event.id).alias("count"),
|
fn.COUNT(Event.id).alias("count"),
|
||||||
)
|
)
|
||||||
.where(Event.camera == camera_name, Event.has_clip)
|
.where(Event.camera == camera_name, Event.has_clip)
|
||||||
.group_by(
|
.group_by(
|
||||||
fn.strftime(
|
fn.strftime(
|
||||||
"%Y-%m-%d %H", fn.datetime(Event.start_time, "unixepoch", tz_name)
|
"%Y-%m-%d %H",
|
||||||
|
fn.datetime(Event.start_time, "unixepoch", "utc", tz_offset),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.objects()
|
.objects()
|
||||||
|
|||||||
@ -9,17 +9,22 @@ import { useApiHost } from '../api';
|
|||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
|
||||||
export default function Recording({ camera, date, hour = '00', minute = '00', second = '00' }) {
|
export default function Recording({ camera, date, hour = '00', minute = '00', second = '00' }) {
|
||||||
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||||
|
//const timezone = "America/Chicago"
|
||||||
const currentDate = useMemo(
|
const currentDate = useMemo(
|
||||||
() => (date ? parseISO(`${date}T${hour || '00'}:${minute || '00'}:${second || '00'}`) : new Date()),
|
() => (date ? parseISO(`${date}T${hour || '00'}:${minute || '00'}:${second || '00'}`) : new Date()),
|
||||||
[date, hour, minute, second]
|
[date, hour, minute, second]
|
||||||
);
|
);
|
||||||
|
|
||||||
const apiHost = useApiHost();
|
const apiHost = useApiHost();
|
||||||
const { data: recordingsSummary } = useSWR(`${camera}/recordings/summary`, { revalidateOnFocus: false });
|
const { data: recordingsSummary } = useSWR([`${camera}/recordings/summary`, { timezone }], {
|
||||||
|
revalidateOnFocus: false,
|
||||||
|
});
|
||||||
|
|
||||||
const recordingParams = {
|
const recordingParams = {
|
||||||
before: getUnixTime(endOfHour(currentDate)),
|
before: getUnixTime(endOfHour(currentDate)),
|
||||||
after: getUnixTime(startOfHour(currentDate)),
|
after: getUnixTime(startOfHour(currentDate)),
|
||||||
|
timezone,
|
||||||
};
|
};
|
||||||
const { data: recordings } = useSWR([`${camera}/recordings`, recordingParams], { revalidateOnFocus: false });
|
const { data: recordings } = useSWR([`${camera}/recordings`, recordingParams], { revalidateOnFocus: false });
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user