Skip to content

Commit d155a7d

Browse files
committed
Show the graph even if no data was recieved during a 30 minute period to highlight periods offline
1 parent 42c1cca commit d155a7d

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

website/app/routes/index.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ export const handle = {
1010
};
1111
export 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;

0 commit comments

Comments
 (0)