Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions src/lib/server/holidays.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
80 changes: 80 additions & 0 deletions src/lib/server/holidays.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> {
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<string, string>(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<number, Map<string, string>>();

/** 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';
}
56 changes: 54 additions & 2 deletions src/routes/pressure/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand Down Expand Up @@ -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<string, number>();
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 }))
}
};
});
65 changes: 65 additions & 0 deletions src/routes/pressure/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
});
</script>

<div class="container">
Expand Down Expand Up @@ -135,6 +144,62 @@
</ChartCard>
</section>

<section class="section">
<h2>Busy days</h2>
<p>
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.
</p>
<div class="grid-2">
<ChartCard
title="Catch rate by type of day"
subtitle="Mean sharks per net-hour per set, sets in brackets. Whiskers: 95% confidence intervals"
>
<BarChart
categories={data.busyDays.byType.map((t) => `${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)}
/>
</ChartCard>
<ChartCard
title="Catch rate by day of the week"
subtitle="Mean sharks per net-hour per set, sets in brackets. Whiskers: 95% confidence intervals"
>
<BarChart
categories={data.busyDays.byWeekday.map((t) => `${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)}
/>
</ChartCard>
</div>
{#if data.busyDays.holidays.length}
<p class="small">
Sets on public holidays: {data.busyDays.holidays
.map((h) => `${h.name} (${h.n})`)
.join(', ')}.
</p>
{/if}
</section>

<section class="section card">
<DataTable
columns={[
Expand Down
Loading