From 07fbfdca7193ea8f1b46f3312ae69d139a3ffdc5 Mon Sep 17 00:00:00 2001 From: Sanidhya Singh Date: Tue, 6 May 2025 14:38:10 +0530 Subject: [PATCH] Updating exports.down for migrations and css change --- ..._watch_stats_over_time_include_duration.js | 106 +++++++-------- ...s_popular_days_of_week_include_duration.js | 128 +++++++++--------- ...ts_popular_hour_of_day_include_duration.js | 10 +- src/pages/css/stats.css | 9 +- src/pages/statistics.jsx | 2 + 5 files changed, 134 insertions(+), 121 deletions(-) diff --git a/backend/migrations/095_fs_watch_stats_over_time_include_duration.js b/backend/migrations/095_fs_watch_stats_over_time_include_duration.js index e88fa04..78e63b5 100644 --- a/backend/migrations/095_fs_watch_stats_over_time_include_duration.js +++ b/backend/migrations/095_fs_watch_stats_over_time_include_duration.js @@ -62,60 +62,60 @@ ALTER FUNCTION public.fs_watch_stats_over_time(integer) }; exports.down = async function (knex) { - // try { - // await knex.schema.raw(` - // DROP FUNCTION IF EXISTS public.fs_watch_stats_over_time(integer); + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_over_time(integer); - // CREATE OR REPLACE FUNCTION fs_watch_stats_over_time( - // days integer - // ) - // RETURNS TABLE( - // "Date" date, - // "Count" bigint, - // "Library" text - // ) - // LANGUAGE 'plpgsql' - // COST 100 - // VOLATILE PARALLEL UNSAFE - // ROWS 1000 + CREATE OR REPLACE FUNCTION fs_watch_stats_over_time( + days integer + ) + RETURNS TABLE( + "Date" date, + "Count" bigint, + "Library" text + ) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 - // AS $BODY$ - // BEGIN - // RETURN QUERY - // SELECT - // dates."Date", - // COALESCE(counts."Count", 0) AS "Count", - // l."Name" as "Library" - // FROM - // (SELECT generate_series( - // DATE_TRUNC('day', NOW() - CAST(days || ' days' as INTERVAL)), - // DATE_TRUNC('day', NOW()), - // '1 day')::DATE AS "Date" - // ) dates - // CROSS JOIN jf_libraries l - // LEFT JOIN - // (SELECT - // DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", - // COUNT(*) AS "Count", - // l."Name" as "Library" - // FROM - // jf_playback_activity a - // JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" - // JOIN jf_libraries l ON i."ParentId" = l."Id" - // WHERE - // a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() - // GROUP BY - // l."Name", DATE_TRUNC('day', a."ActivityDateInserted") - // ) counts - // ON counts."Date" = dates."Date" AND counts."Library" = l."Name" - // ORDER BY - // "Date", "Library"; - // END; - // $BODY$; + AS $BODY$ + BEGIN + RETURN QUERY + SELECT + dates."Date", + COALESCE(counts."Count", 0) AS "Count", + l."Name" as "Library" + FROM + (SELECT generate_series( + DATE_TRUNC('day', NOW() - CAST(days || ' days' as INTERVAL)), + DATE_TRUNC('day', NOW()), + '1 day')::DATE AS "Date" + ) dates + CROSS JOIN jf_libraries l + LEFT JOIN + (SELECT + DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + COUNT(*) AS "Count", + l."Name" as "Library" + FROM + jf_playback_activity a + JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + JOIN jf_libraries l ON i."ParentId" = l."Id" + WHERE + a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + GROUP BY + l."Name", DATE_TRUNC('day', a."ActivityDateInserted") + ) counts + ON counts."Date" = dates."Date" AND counts."Library" = l."Name" + ORDER BY + "Date", "Library"; + END; + $BODY$; - // ALTER FUNCTION fs_watch_stats_over_time(integer) - // OWNER TO "${process.env.POSTGRES_ROLE}";`); - // } catch (error) { - // console.error(error); - // } + ALTER FUNCTION fs_watch_stats_over_time(integer) + OWNER TO "${process.env.POSTGRES_ROLE}";`); + } catch (error) { + console.error(error); + } }; diff --git a/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js b/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js index 630f72b..c0849e0 100644 --- a/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js +++ b/backend/migrations/096_fs_watch_stats_popular_days_of_week_include_duration.js @@ -72,70 +72,72 @@ ALTER FUNCTION public.fs_watch_stats_popular_days_of_week(integer) }; exports.down = async function (knex) { -// try { -// await knex.schema.raw(` -// DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_days_of_week(integer); + try { + await knex.schema.raw(` + DROP FUNCTION IF EXISTS public.fs_watch_stats_popular_days_of_week(integer); -// CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_days_of_week( -// days integer) -// RETURNS TABLE("Day" text, "Count" bigint, "Library" text) -// LANGUAGE 'plpgsql' -// COST 100 -// VOLATILE PARALLEL UNSAFE -// ROWS 1000 +CREATE OR REPLACE FUNCTION public.fs_watch_stats_popular_days_of_week( + days integer) + RETURNS TABLE("Day" text, "Count" bigint, "Library" text) + LANGUAGE 'plpgsql' + COST 100 + VOLATILE PARALLEL UNSAFE + ROWS 1000 -// AS $BODY$ -// BEGIN -// RETURN QUERY -// WITH library_days AS ( -// SELECT -// l."Name" AS "Library", -// d.day_of_week, -// d.day_name -// FROM -// jf_libraries l, -// (SELECT 0 AS "day_of_week", 'Sunday' AS "day_name" UNION ALL -// SELECT 1 AS "day_of_week", 'Monday' AS "day_name" UNION ALL -// SELECT 2 AS "day_of_week", 'Tuesday' AS "day_name" UNION ALL -// SELECT 3 AS "day_of_week", 'Wednesday' AS "day_name" UNION ALL -// SELECT 4 AS "day_of_week", 'Thursday' AS "day_name" UNION ALL -// SELECT 5 AS "day_of_week", 'Friday' AS "day_name" UNION ALL -// SELECT 6 AS "day_of_week", 'Saturday' AS "day_name" -// ) d -// ) -// SELECT -// library_days.day_name AS "Day", -// COALESCE(SUM(counts."Count"), 0)::bigint AS "Count", -// library_days."Library" AS "Library" -// FROM -// library_days -// LEFT JOIN -// (SELECT -// DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", -// COUNT(*) AS "Count", -// EXTRACT(DOW FROM a."ActivityDateInserted") AS "DOW", -// l."Name" AS "Library" -// FROM -// jf_playback_activity a -// JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" -// JOIN jf_libraries l ON i."ParentId" = l."Id" -// WHERE -// a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() -// GROUP BY -// l."Name", EXTRACT(DOW FROM a."ActivityDateInserted"), DATE_TRUNC('day', a."ActivityDateInserted") -// ) counts -// ON counts."DOW" = library_days.day_of_week AND counts."Library" = library_days."Library" -// GROUP BY -// library_days.day_name, library_days.day_of_week, library_days."Library" -// ORDER BY -// library_days.day_of_week, library_days."Library"; -// END; +AS $BODY$ + BEGIN + RETURN QUERY + WITH library_days AS ( + SELECT + l."Name" AS "Library", + d.day_of_week, + d.day_name + FROM + jf_libraries l, + (SELECT 0 AS "day_of_week", 'Sunday' AS "day_name" UNION ALL + SELECT 1 AS "day_of_week", 'Monday' AS "day_name" UNION ALL + SELECT 2 AS "day_of_week", 'Tuesday' AS "day_name" UNION ALL + SELECT 3 AS "day_of_week", 'Wednesday' AS "day_name" UNION ALL + SELECT 4 AS "day_of_week", 'Thursday' AS "day_name" UNION ALL + SELECT 5 AS "day_of_week", 'Friday' AS "day_name" UNION ALL + SELECT 6 AS "day_of_week", 'Saturday' AS "day_name" + ) d + where l.archived=false + ) + SELECT + library_days.day_name AS "Day", + COALESCE(SUM(counts."Count"), 0)::bigint AS "Count", + library_days."Library" AS "Library" + FROM + library_days + LEFT JOIN + (SELECT + DATE_TRUNC('day', a."ActivityDateInserted")::DATE AS "Date", + COUNT(*) AS "Count", + EXTRACT(DOW FROM a."ActivityDateInserted") AS "DOW", + l."Name" AS "Library" + FROM + jf_playback_activity a + JOIN jf_library_items i ON i."Id" = a."NowPlayingItemId" + JOIN jf_libraries l ON i."ParentId" = l."Id" and l.archived=false + WHERE + a."ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' as INTERVAL) AND NOW() + GROUP BY + l."Name", EXTRACT(DOW FROM a."ActivityDateInserted"), DATE_TRUNC('day', a."ActivityDateInserted") + ) counts + ON counts."DOW" = library_days.day_of_week AND counts."Library" = library_days."Library" + GROUP BY + library_days.day_name, library_days.day_of_week, library_days."Library" + ORDER BY + library_days.day_of_week, library_days."Library"; + END; -// $BODY$; - -// ALTER FUNCTION fs_watch_stats_popular_days_of_week(integer) -// OWNER TO "${process.env.POSTGRES_ROLE}";`); -// } catch (error) { -// console.error(error); -// } +$BODY$; + +ALTER FUNCTION public.fs_watch_stats_popular_days_of_week(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); + } catch (error) { + console.error(error); + } }; diff --git a/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js b/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js index 4909788..57f943f 100644 --- a/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js +++ b/backend/migrations/097_fs_watch_stats_popular_hour_of_day_include_duration.js @@ -96,7 +96,8 @@ AS $BODY$ "ActivityDateInserted" BETWEEN NOW() - CAST(days || ' days' AS INTERVAL) AND NOW() ) a ON a."NowPlayingItemId" = i."Id" AND a."Hour"::integer = h."Hour" WHERE - l."Id" IN (SELECT "Id" FROM jf_libraries) + l.archived=false + and l."Id" IN (SELECT "Id" FROM jf_libraries) GROUP BY h."Hour", l."Name" @@ -106,9 +107,10 @@ AS $BODY$ END; $BODY$; - - ALTER FUNCTION fs_watch_stats_popular_hour_of_day(integer) - OWNER TO "${process.env.POSTGRES_ROLE}";`); + +ALTER FUNCTION public.fs_watch_stats_popular_hour_of_day(integer) + OWNER TO "${process.env.POSTGRES_ROLE}"; + `); } catch (error) { console.error(error); } diff --git a/src/pages/css/stats.css b/src/pages/css/stats.css index f300da5..3e0f186 100644 --- a/src/pages/css/stats.css +++ b/src/pages/css/stats.css @@ -49,12 +49,19 @@ .stats-tab-nav { background-color: var(--secondary-background-color); - display: flex; border-radius: 8px; align-self: flex-end; +} + +.nav-item { + display: flex; justify-content: center; } +/* .tab-content { + display: none; +} */ + .chart-canvas { width: 100%; height: 400px; diff --git a/src/pages/statistics.jsx b/src/pages/statistics.jsx index b04ff7e..283db21 100644 --- a/src/pages/statistics.jsx +++ b/src/pages/statistics.jsx @@ -53,6 +53,7 @@ function Statistics() {
} /> +