From 6ec80bb43644c9157a1c30d260d3b496ec589f99 Mon Sep 17 00:00:00 2001
From: luen
Date: Wed, 4 Nov 2026 09:25:20 +1000
Subject: [PATCH 1/2] Charts: add nursery month-hour temperature calendars
(#127)
---
AGENTS.md | 2 +
e2e/thermal-calendar.spec.ts | 27 ++++++
src/lib/components/ThermalCalendar.svelte | 97 +++++++++++++++++++
.../server/analytics/thermalCalendar.test.ts | 21 ++++
src/lib/server/analytics/thermalCalendar.ts | 31 ++++++
src/lib/server/import/index.ts | 2 +-
src/routes/water-quality/+page.server.ts | 2 +
src/routes/water-quality/+page.svelte | 2 +
8 files changed, 183 insertions(+), 1 deletion(-)
create mode 100644 e2e/thermal-calendar.spec.ts
create mode 100644 src/lib/components/ThermalCalendar.svelte
create mode 100644 src/lib/server/analytics/thermalCalendar.test.ts
create mode 100644 src/lib/server/analytics/thermalCalendar.ts
diff --git a/AGENTS.md b/AGENTS.md
index f71c8a0..64d0356 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -87,6 +87,8 @@ samples/fixture/ synthetic workbooks for tests/CI (committed)
### Cloud cover (#104)
+- Month-hour nursery heatmaps (#127) use `logger_diel.n` as contributing site-hour days, not sensor samples. Mask cells with fewer than ten days and keep a common 15–40 °C scale; pooled historical means cannot establish threshold-exceedance duration.
+
- ERA5 `cloud_evening` covers every set; the crew's 1–4 `cloud_cover` score exists only in 2020–22 and tracks ERA5 (score 1 ≈ 43%, 4 ≈ 94%). `moonlight()` in `analytics/cloud.ts` = illumination × sin(moon altitude) × clear-sky fraction.
- Cloud vs water temperature must be compared within the same month: the cloudy wet season is also the warmest, so raw correlations are ~0 while within-month ones are strongly negative.
diff --git a/e2e/thermal-calendar.spec.ts b/e2e/thermal-calendar.spec.ts
new file mode 100644
index 0000000..d1b5219
--- /dev/null
+++ b/e2e/thermal-calendar.spec.ts
@@ -0,0 +1,27 @@
+import { expect, test } from '@playwright/test';
+import AxeBuilder from '@axe-core/playwright';
+
+test('temperature calendar supports keyboard, CSV and mobile in both themes', async ({ page }) => {
+ await page.setViewportSize({ width: 375, height: 800 });
+ for (const theme of ['light', 'dark'] as const) {
+ await page.emulateMedia({ colorScheme: theme });
+ await page.goto('/water-quality');
+ const card = page
+ .locator('figure')
+ .filter({ has: page.getByRole('heading', { name: /^Month and hour:/ }) });
+ await expect(card).toBeVisible();
+ const chart = card.locator('svg');
+ await chart.focus();
+ await page.keyboard.press('ArrowRight');
+ await expect(card.locator('.tip')).toBeVisible();
+ await page.keyboard.press('Escape');
+ await expect(card.getByRole('button', { name: /Download CSV/ })).toBeVisible();
+ const result = await new AxeBuilder({ page }).include('main').analyze();
+ expect(
+ result.violations.filter((v) => ['serious', 'critical'].includes(v.impact ?? ''))
+ ).toEqual([]);
+ expect(
+ await page.evaluate(() => document.documentElement.scrollWidth - innerWidth)
+ ).toBeLessThanOrEqual(1);
+ }
+});
diff --git a/src/lib/components/ThermalCalendar.svelte b/src/lib/components/ThermalCalendar.svelte
new file mode 100644
index 0000000..21b5451
--- /dev/null
+++ b/src/lib/components/ThermalCalendar.svelte
@@ -0,0 +1,97 @@
+
+
+
+
Nursery temperature through the year
+
+ Historical month-by-hour averages, pooled across logged years. Each cell needs at least ten
+ observed days. Years and months have unequal coverage; this is neither a live forecast nor a
+ comparison of nursery safety. Existing logger exclusions apply, and very shallow loggers may be
+ exposed at low tide.
+
- Historical month-by-hour averages, pooled across logged years. Each cell needs at least ten
- observed days. Years and months have unequal coverage; this is neither a live forecast nor a
- comparison of nursery safety. Existing logger exclusions apply, and very shallow loggers may be
- exposed at low tide.
+ Mean logger temperature for each month and hour of the day, pooled over every year a nursery was
+ logged. A cell needs at least ten logged days. Nurseries were logged in different years and for
+ different lengths of time (under each chart), so years and months don't count equally. These are
+ long-run averages, not a forecast, and not a ranking of nurseries. Downloads left out above stay
+ out here, and a very shallow logger may be out of the water at low tide.