File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,12 +10,12 @@ export const handle = {
1010} ;
1111export async function loader ( { context } : Route . LoaderArgs ) {
1212 const weatherStationHealthQuery = await context . db . all ( sql `
13- SELECT
14- FLOOR(unixepoch() + (period_index * 30 * 60)) AS period_time,
15- period_index,
16- SUM(CASE WHEN table_name = 'disregarded_observations' THEN count ELSE 0 END) AS disregarded,
17- SUM(CASE WHEN table_name = 'observations' THEN count ELSE 0 END) AS observed
18- FROM (
13+ WITH RECURSIVE time_periods(period_index) AS (
14+ SELECT -48 AS period_index
15+ UNION ALL
16+ SELECT period_index + 1 FROM time_periods WHERE period_index < 0
17+ ),
18+ data_summary AS (
1919 SELECT
2020 'disregarded_observations' AS table_name,
2121 COUNT(*) AS count,
@@ -31,9 +31,16 @@ export async function loader({ context }: Route.LoaderArgs) {
3131 FROM observations
3232 WHERE timestamp >= (unixepoch()-(24 * 60 * 60))
3333 GROUP BY period_index
34- ) AS combined
35- GROUP BY period_index
36- ORDER BY period_index;
34+ )
35+ SELECT
36+ FLOOR(unixepoch() + (tp.period_index * 30 * 60)) AS period_time,
37+ tp.period_index,
38+ COALESCE(SUM(CASE WHEN ds.table_name = 'disregarded_observations' THEN ds.count ELSE 0 END), 0) AS disregarded,
39+ COALESCE(SUM(CASE WHEN ds.table_name = 'observations' THEN ds.count ELSE 0 END), 0) AS observed
40+ FROM time_periods tp
41+ LEFT JOIN data_summary ds ON tp.period_index = ds.period_index
42+ GROUP BY tp.period_index
43+ ORDER BY tp.period_index;
3744 ` ) ;
3845 const weatherStationHealthData : {
3946 time : string ;
You can’t perform that action at this time.
0 commit comments