From c9015aeb8311dcdbcf0d000b7529e4474fbbd0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Gessler?= <36667834+gessfred@users.noreply.github.com> Date: Mon, 1 Apr 2024 20:52:50 +0200 Subject: [PATCH] add fallbacks to timebysession floats --- api/routers/analytics.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/routers/analytics.py b/api/routers/analytics.py index da14d8e..6db10b9 100644 --- a/api/routers/analytics.py +++ b/api/routers/analytics.py @@ -192,13 +192,13 @@ def get_session_times(request: Request, x_user_id: str = Header(default=None), i day_of_week, user_id, session_date, - extract(epoch from sum(session_end - session_start)) / 3600 as total_hours, - extract(epoch from sum(session_end - session_start)) / 60 as total_minutes, + coalesce(extract(epoch from sum(session_end - session_start)) / 3600, 0.0) as total_hours, + coalesce(extract(epoch from sum(session_end - session_start)) / 60, 0.0) as total_minutes, sum(session_end - session_start) as total_time, count(*) as number_of_sessions, - percentile_cont(0.5) within group( + coalesce(percentile_cont(0.5) within group( order by extract(epoch from session_end - session_start) / 60 - ) median_session_duration, + ), 0.0) median_session_duration, max(session_end) as sessions_end from session_boundaries group by user_id, session_date, day_of_week @@ -253,4 +253,4 @@ def get_timeofday(request: Request, x_user_id: str = Header(default=None), inter """, con=db.bind, params={"user_id": x_user_id, "interval": interval, "bucketing": bucketing}).to_dict(orient="records") return { "data": data - } \ No newline at end of file + }