From 7f8a9a9df57b33ef0f1c27e326fe0e2befaefe59 Mon Sep 17 00:00:00 2001 From: luen Date: Tue, 3 Nov 2026 08:58:59 +1000 Subject: [PATCH] Environment: public holidays and festive period as busy-day proxies holidays.ts computes French Polynesia's public holidays (incl. Good Friday, Easter Monday, Ascension, Whit Monday; Matari'i i ni'a replacing Autonomy Day from 2025) and a Christmas-New Year window. The Human pressure page compares catch rates on weekdays, weekends, holidays and the festive period, and by day of the week, with 95% CIs and a Welch test. Refs #25 Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 1 + src/lib/server/holidays.test.ts | 33 ++++++++++++ src/lib/server/holidays.ts | 80 +++++++++++++++++++++++++++++ src/routes/pressure/+page.server.ts | 56 +++++++++++++++++++- src/routes/pressure/+page.svelte | 65 +++++++++++++++++++++++ 5 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 src/lib/server/holidays.test.ts create mode 100644 src/lib/server/holidays.ts diff --git a/AGENTS.md b/AGENTS.md index a7f56d7..93857d7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,6 +42,7 @@ src/lib/server/data.ts loads the whole dataset into memory per import; memo() src/lib/server/analytics common.ts (CPUE, Fulton's K, recapture pairs…) · env.ts (per-set variables) findings.ts (live findings) src/lib/server/astro.ts sunset/twilight/moon (local formulas) · tides.ts (extrema, interpolation) +src/lib/server/holidays.ts French Polynesia public holidays (Easter-based too) + festive window src/lib/stats.ts regression, Spearman, Welch, Wilson, binomial, histograms, box stats src/lib/components/ ChartCard, StatTile, DataTable, FindingCard, MooreaMap, charts/* src/routes/ one folder per page (+page.server.ts computes, +page.svelte renders) diff --git a/src/lib/server/holidays.test.ts b/src/lib/server/holidays.test.ts new file mode 100644 index 0000000..d9d1ee8 --- /dev/null +++ b/src/lib/server/holidays.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from 'vitest'; +import { dayType, easter, holidayOn, publicHolidays } from './holidays'; + +describe('French Polynesia holidays', () => { + it('computes Easter', () => { + expect(easter(2014)).toBe('2014-04-20'); + expect(easter(2019)).toBe('2019-04-21'); + expect(easter(2025)).toBe('2025-04-20'); + }); + + it('includes the Easter-based and local holidays', () => { + const h = publicHolidays(2025); + expect(h.get('2025-04-18')).toBe('Good Friday'); + expect(h.get('2025-05-29')).toBe('Ascension Day'); + expect(h.get('2025-06-09')).toBe('Whit Monday'); + expect(h.get('2025-03-05')).toBe('Arrival of the Gospel'); + expect(h.size).toBe(14); + }); + + it("swaps Autonomy Day for Matari'i i ni'a in 2025", () => { + expect(holidayOn('2024-06-29')).toBe('Internal Autonomy Day'); + expect(holidayOn('2024-11-20')).toBeNull(); + expect(holidayOn('2025-06-29')).toBeNull(); + expect(holidayOn('2025-11-20')).toBe("Matari'i i ni'a"); + }); + + it('labels each day once', () => { + expect(dayType('2023-12-25')).toBe('Public holiday'); + expect(dayType('2023-12-30')).toBe('Festive period'); // a Saturday + expect(dayType('2023-11-18')).toBe('Weekend'); + expect(dayType('2023-11-21')).toBe('Weekday'); + }); +}); diff --git a/src/lib/server/holidays.ts b/src/lib/server/holidays.ts new file mode 100644 index 0000000..4ed6e22 --- /dev/null +++ b/src/lib/server/holidays.ts @@ -0,0 +1,80 @@ +/** + * Human-activity proxies for French Polynesia (#25): public holidays (computed, including the + * Easter-based ones) and the Christmas–New Year festive period. Dates are local (UTC−10) ISO + * strings, like set dates. + * + * School holidays are not included: the Polynesian school calendar changes every year and isn't + * derivable from rules. The festive window below is a deliberately generic stand-in. + */ + +/** Easter Sunday (Gregorian, anonymous algorithm) as an ISO date. */ +export function easter(year: number): string { + const a = year % 19; + const b = Math.floor(year / 100); + const c = year % 100; + const d = Math.floor(b / 4); + const e = b % 4; + const f = Math.floor((b + 8) / 25); + const g = Math.floor((b - f + 1) / 3); + const h = (19 * a + b - d - g + 15) % 30; + const i = Math.floor(c / 4); + const k = c % 4; + const l = (32 + 2 * e + 2 * i - h - k) % 7; + const m = Math.floor((a + 11 * h + 22 * l) / 451); + const month = Math.floor((h + l - 7 * m + 114) / 31); + const day = ((h + l - 7 * m + 114) % 31) + 1; + return `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`; +} + +const addDays = (iso: string, n: number) => + new Date(Date.parse(`${iso}T00:00:00Z`) + n * 86_400_000).toISOString().slice(0, 10); + +/** Public holidays of French Polynesia in a year: ISO date → name. */ +export function publicHolidays(year: number): Map { + const e = easter(year); + const fixed: [string, string][] = [ + ['01-01', "New Year's Day"], + ['03-05', 'Arrival of the Gospel'], + ['05-01', 'Labour Day'], + ['05-08', 'Victory in Europe Day'], + ['07-14', 'Bastille Day'], + ['08-15', 'Assumption'], + ['11-01', "All Saints' Day"], + ['11-11', 'Armistice Day'], + ['12-25', 'Christmas Day'] + ]; + // Matari'i i ni'a (20 Nov) replaced Internal Autonomy Day (29 Jun) from 2025. + fixed.push(year >= 2025 ? ['11-20', "Matari'i i ni'a"] : ['06-29', 'Internal Autonomy Day']); + const out = new Map(fixed.map(([md, name]) => [`${year}-${md}`, name])); + out.set(addDays(e, -2), 'Good Friday'); + out.set(addDays(e, 1), 'Easter Monday'); + out.set(addDays(e, 39), 'Ascension Day'); + out.set(addDays(e, 50), 'Whit Monday'); + return out; +} + +const cache = new Map>(); + +/** Name of the public holiday on this date, or null. */ +export function holidayOn(iso: string): string | null { + const y = Number(iso.slice(0, 4)); + if (!cache.has(y)) cache.set(y, publicHolidays(y)); + return cache.get(y)!.get(iso) ?? null; +} + +/** 20 December – 5 January: Christmas and New Year, when beaches and lagoons are busiest. */ +export function isFestive(iso: string): boolean { + const md = iso.slice(5); + return md >= '12-20' || md <= '01-05'; +} + +export type DayType = 'Public holiday' | 'Festive period' | 'Weekend' | 'Weekday'; +export const DAY_TYPES: DayType[] = ['Weekday', 'Weekend', 'Public holiday', 'Festive period']; + +/** One label per date; a holiday wins over the festive window, which wins over the weekend. */ +export function dayType(iso: string): DayType { + if (holidayOn(iso)) return 'Public holiday'; + if (isFestive(iso)) return 'Festive period'; + const wd = new Date(`${iso}T00:00:00Z`).getUTCDay(); + return wd === 0 || wd === 6 ? 'Weekend' : 'Weekday'; +} diff --git a/src/routes/pressure/+page.server.ts b/src/routes/pressure/+page.server.ts index d1c2b3e..a8e2fb5 100644 --- a/src/routes/pressure/+page.server.ts +++ b/src/routes/pressure/+page.server.ts @@ -9,7 +9,8 @@ import { recapturePairs, round } from '#lib/server/analytics/common'; -import { mean, median, pairs, spearman } from '#lib/stats'; +import { DAY_TYPES, dayType, holidayOn } from '#lib/server/holidays'; +import { mean, median, pairs, se, spearman, welch } from '#lib/stats'; import type { PageServerLoad } from './$types'; export const load: PageServerLoad = () => @@ -70,5 +71,56 @@ export const load: PageServerLoad = () => return r ? round(r.rho, 2) : null; }) })); - return { rows, metrics, outcomes: outcomes.map((o) => o[1]), corr }; + // Busy days (#25): do weekends and holidays, when more people are on the water, change the + // evening catch? Mean per-set catch rate with a ±1.96·SE interval. + const dated = eff.filter((s) => s.date && s.cpue != null); + const group = (ss: typeof dated, label: string) => { + const ys = ss.map((s) => s.cpue); + const m = mean(ys); + const e = se(ys); + return { + label, + n: ss.length, + mean: round(m, 3), + lo: m != null && e != null ? round(Math.max(0, m - 1.96 * e), 3) : null, + hi: m != null && e != null ? round(m + 1.96 * e, 3) : null + }; + }; + const byType = DAY_TYPES.map((t) => + group( + dated.filter((s) => dayType(s.date!) === t), + t + ) + ); + const byWeekday = [1, 2, 3, 4, 5, 6, 0].map((wd, i) => + group( + dated.filter((s) => s.weekday === wd), + ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][i] + ) + ); + const busy = dated.filter((s) => dayType(s.date!) !== 'Weekday'); + const quiet = dated.filter((s) => dayType(s.date!) === 'Weekday'); + const test = welch( + busy.map((s) => s.cpue), + quiet.map((s) => s.cpue) + ); + const holidaySets = new Map(); + for (const s of dated) { + const h = holidayOn(s.date!); + if (h) holidaySets.set(h, (holidaySets.get(h) ?? 0) + 1); + } + return { + rows, + metrics, + outcomes: outcomes.map((o) => o[1]), + corr, + busyDays: { + byType, + byWeekday, + busyMean: round(mean(busy.map((s) => s.cpue)), 2), + quietMean: round(mean(quiet.map((s) => s.cpue)), 2), + p: test ? round(test.p, 3) : null, + holidays: [...holidaySets].sort((a, b) => b[1] - a[1]).map(([name, n]) => ({ name, n })) + } + }; }); diff --git a/src/routes/pressure/+page.svelte b/src/routes/pressure/+page.svelte index f5c2a56..794658f 100644 --- a/src/routes/pressure/+page.svelte +++ b/src/routes/pressure/+page.svelte @@ -14,6 +14,15 @@ data.rows .filter((r) => fx(r) != null && fy(r) != null) .map((r) => ({ x: fx(r)!, y: fy(r)!, label: r.name, href: `/nurseries/${r.id}` })); + const busyText = $derived.by(() => { + const { busyMean, quietMean, p } = data.busyDays; + const test = p != null ? ` (Welch's t-test p = ${num(p, 3)})` : ''; + const verdict = + p != null && p < 0.05 + ? "The difference is unlikely to be chance alone, but the sets aren't randomised: crews, sites and moon phases differ between these days too." + : 'That is within what chance alone would produce.'; + return `Busy days average ${num(busyMean, 2)} sharks per net-hour against ${num(quietMean, 2)} on ordinary weekdays${test}. ${verdict}`; + });
@@ -135,6 +144,62 @@ +
+

Busy days

+

+ A rough proxy for people on the water: weekends, French Polynesia's public holidays and the + Christmas–New Year period (20 Dec – 5 Jan). {busyText} + School holidays aren't included yet: the Polynesian school calendar changes every year. +

+
+ + `${t.label} (${t.n})`)} + series={[ + { + name: 'Sharks / net-hour', + color: 'var(--series-1)', + values: data.busyDays.byType.map((t) => t.mean) + } + ]} + errors={data.busyDays.byType.map((t) => + t.lo != null && t.hi != null ? [t.lo, t.hi] : null + )} + valueFormat={(v) => num(v, 2)} + /> + + + `${t.label} (${t.n})`)} + series={[ + { + name: 'Sharks / net-hour', + color: 'var(--series-1)', + values: data.busyDays.byWeekday.map((t) => t.mean) + } + ]} + errors={data.busyDays.byWeekday.map((t) => + t.lo != null && t.hi != null ? [t.lo, t.hi] : null + )} + valueFormat={(v) => num(v, 2)} + /> + +
+ {#if data.busyDays.holidays.length} +

+ Sets on public holidays: {data.busyDays.holidays + .map((h) => `${h.name} (${h.n})`) + .join(', ')}. +

+ {/if} +
+