diff --git a/AGENTS.md b/AGENTS.md index bd5e202..570b47b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -43,6 +43,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) · insitu.ts (logger temperature summaries) population.ts (Schnabel abundance, von Bertalanffy growth) + diet.ts (gastric lavage: fullness, prey groups) glm.ts (NB/Poisson GLM, splines) · catchModel.ts (joint catch model) 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 @@ -64,6 +65,7 @@ samples/fixture/ synthetic workbooks for tests/CI (committed) - 2013-14 `Shark log physioshark` / `Set Log physioshark` duplicate `Catch data` / `Set Log` and are skipped (#9). 2013-14 recaptures are grouped in its `Recaptures` sheet; 2014-15 `Recaptures` holds extra catches; 2015-16 stores recaptures as horizontal column blocks (`1st Recap Site`…). - 2016-17 `Shark Log` has a date _value_ as its date header; 2021-22 `Set Log` has a garbled date header (`16(`). Both are handled. - Species codes: `Cm` blacktip, `Na` sicklefin lemon, `Nf` tawny nurse shark. 2024-25 writes the nurse shark as `GF` / `Gf1` (`GF Log Juv`), probably from _Ginglymostoma_, the Atlantic nurse shark genus; it is read as `Nf` (confirmed by Jodie Rummer, #12). +- Diet (#40): `Lavage (y/n)` / `Gastic lavage` → `captures.lavage`; `Lavage (full/empty)` / `Stomach content` → `stomach` (full | traces | empty; "no sample" is null); `Lavage (contents)` / `Stomach sample type` / 2013-14 `State of Stomach` → `stomach_contents` free text. A fullness cell that isn't a fullness word (e.g. "worm found") becomes contents. Analyses in `analytics/diet.ts` (fed = full or traces). - Individuals: union-find over tags (PIT 15-digit, `COFA 12345`, re-tags) plus recapture groups. Conflicting sex/species/shrinking length is logged, not fixed. - Captures link to sets by season + set number (±1 day), then date + site, then a unique set that date. - CPUE = max(set-log count, linked captures) / net-hours. 2013-14 has no set times (no CPUE). diff --git a/drizzle/0002_cloudy_red_wolf.sql b/drizzle/0002_cloudy_red_wolf.sql new file mode 100644 index 0000000..4336b60 --- /dev/null +++ b/drizzle/0002_cloudy_red_wolf.sql @@ -0,0 +1,3 @@ +ALTER TABLE `captures` ADD `lavage` integer;--> statement-breakpoint +ALTER TABLE `captures` ADD `stomach` text;--> statement-breakpoint +ALTER TABLE `captures` ADD `stomach_contents` text; \ No newline at end of file diff --git a/drizzle/meta/0002_snapshot.json b/drizzle/meta/0002_snapshot.json new file mode 100644 index 0000000..c248552 --- /dev/null +++ b/drizzle/meta/0002_snapshot.json @@ -0,0 +1,3060 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "e07a85a5-9c17-4708-aec2-c253925ce71c", + "prevId": "cbc44ba9-81dd-4198-816c-0e17c202c1f1", + "tables": { + "adult_captures": { + "name": "adult_captures", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "shark_id": { + "name": "shark_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hooked_min": { + "name": "hooked_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "boat_min": { + "name": "boat_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "released_min": { + "name": "released_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fight_min": { + "name": "fight_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "handling_min": { + "name": "handling_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lat": { + "name": "lat", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lon": { + "name": "lon", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site": { + "name": "site", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sex": { + "name": "sex", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "maturity": { + "name": "maturity", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "repro_code": { + "name": "repro_code", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pcl_mm": { + "name": "pcl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fl_mm": { + "name": "fl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tl_mm": { + "name": "tl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pec_girth_mm": { + "name": "pec_girth_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dors_girth_mm": { + "name": "dors_girth_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "caud_girth_mm": { + "name": "caud_girth_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "clasper_inner": { + "name": "clasper_inner", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "clasper_outer": { + "name": "clasper_outer", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sperm": { + "name": "sperm", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ultrasound": { + "name": "ultrasound", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pregnant": { + "name": "pregnant", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "blood1_min": { + "name": "blood1_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lact1": { + "name": "lact1", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gluc1": { + "name": "gluc1", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bhb1": { + "name": "bhb1", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "blood2_min": { + "name": "blood2_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lact2": { + "name": "lact2", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gluc2": { + "name": "gluc2", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bhb2": { + "name": "bhb2", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tagged": { + "name": "tagged", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bait": { + "name": "bait", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comments": { + "name": "comments", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_file": { + "name": "source_file", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_sheet": { + "name": "source_sheet", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "adult_effort": { + "name": "adult_effort", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session": { + "name": "session", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bait_in_min": { + "name": "bait_in_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bait_out_min": { + "name": "bait_out_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "soak_min": { + "name": "soak_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shark_times": { + "name": "shark_times", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_sharks": { + "name": "n_sharks", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "comments": { + "name": "comments", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "adult_samples": { + "name": "adult_samples", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "sample": { + "name": "sample", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "size_cm": { + "name": "size_cm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sex": { + "name": "sex", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "island": { + "name": "island", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "year": { + "name": "year", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "blood": { + "name": "blood", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "species": { + "name": "species", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "experiment": { + "name": "experiment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shark_no": { + "name": "shark_no", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hct": { + "name": "hct", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "hb": { + "name": "hb", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cholesterol": { + "name": "cholesterol", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ffa": { + "name": "ffa", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "triglycerides": { + "name": "triglycerides", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "captures": { + "name": "captures", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "species": { + "name": "species", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_raw": { + "name": "site_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "set_id": { + "name": "set_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "set_no": { + "name": "set_no", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shark_no": { + "name": "shark_no", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "capture_no": { + "name": "capture_no", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "individual_id": { + "name": "individual_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sex": { + "name": "sex", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "age_class": { + "name": "age_class", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "umbilical": { + "name": "umbilical", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "uss": { + "name": "uss", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pcl_mm": { + "name": "pcl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fl_mm": { + "name": "fl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tl_mm": { + "name": "tl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pec_girth_mm": { + "name": "pec_girth_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dors_girth_mm": { + "name": "dors_girth_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "caud_girth_mm": { + "name": "caud_girth_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mass_kg": { + "name": "mass_kg", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "clasper_l": { + "name": "clasper_l", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "clasper_r": { + "name": "clasper_r", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "capture_min": { + "name": "capture_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "landing_min": { + "name": "landing_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "release_min": { + "name": "release_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "workup_min": { + "name": "workup_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "to_lab": { + "name": "to_lab", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "died": { + "name": "died", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "blood": { + "name": "blood", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dna": { + "name": "dna", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "us_area": { + "name": "us_area", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "us_perimeter": { + "name": "us_perimeter", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "habitat": { + "name": "habitat", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_raw": { + "name": "tide_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lavage": { + "name": "lavage", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stomach": { + "name": "stomach", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stomach_contents": { + "name": "stomach_contents", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_after_sunset": { + "name": "min_after_sunset", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "min_after_net_in": { + "name": "min_after_net_in", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_mm": { + "name": "tide_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_trend": { + "name": "tide_trend", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "moon_illum": { + "name": "moon_illum", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "moon_phase": { + "name": "moon_phase", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sst": { + "name": "sst", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dhw": { + "name": "dhw", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_file": { + "name": "source_file", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_sheet": { + "name": "source_sheet", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "captures_season": { + "name": "captures_season", + "columns": [ + "season" + ], + "isUnique": false + }, + "captures_site": { + "name": "captures_site", + "columns": [ + "site_id" + ], + "isUnique": false + }, + "captures_individual": { + "name": "captures_individual", + "columns": [ + "individual_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "climate_monthly": { + "name": "climate_monthly", + "columns": { + "ym": { + "name": "ym", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "oni": { + "name": "oni", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "soi": { + "name": "soi", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "data_issues": { + "name": "data_issues", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "severity": { + "name": "severity", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "file": { + "name": "file", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sheet": { + "name": "sheet", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "row": { + "name": "row", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "column": { + "name": "column", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "field_notes": { + "name": "field_notes", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ref_id": { + "name": "ref_id", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "species": { + "name": "species", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "field_wq": { + "name": "field_wq", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_min": { + "name": "time_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "depth_cm": { + "name": "depth_cm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "salinity": { + "name": "salinity", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "do_mg": { + "name": "do_mg", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "do_pct": { + "name": "do_pct", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "temp": { + "name": "temp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ph": { + "name": "ph", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "hobo": { + "name": "hobo", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_raw": { + "name": "site_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "logger": { + "name": "logger", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deployed": { + "name": "deployed", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "retrieved": { + "name": "retrieved", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "individuals": { + "name": "individuals", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "species": { + "name": "species", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sex": { + "name": "sex", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "first_date": { + "name": "first_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_date": { + "name": "last_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_captures": { + "name": "n_captures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "n_seasons": { + "name": "n_seasons", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sites": { + "name": "sites", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "first_tl_mm": { + "name": "first_tl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "last_tl_mm": { + "name": "last_tl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tags": { + "name": "tags", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "conflict": { + "name": "conflict", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "lab_feeding": { + "name": "lab_feeding", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tank": { + "name": "tank", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shark": { + "name": "shark", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "food_g": { + "name": "food_g", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rejected_g": { + "name": "rejected_g", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pct": { + "name": "pct", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "lab_sharks": { + "name": "lab_sharks", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "shark_no": { + "name": "shark_no", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "individual_id": { + "name": "individual_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "species": { + "name": "species", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sex": { + "name": "sex", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "arrival_date": { + "name": "arrival_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "release_date": { + "name": "release_date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "days": { + "name": "days", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "arr_tl_mm": { + "name": "arr_tl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "arr_fl_mm": { + "name": "arr_fl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "arr_mass_kg": { + "name": "arr_mass_kg", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rel_tl_mm": { + "name": "rel_tl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rel_fl_mm": { + "name": "rel_fl_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rel_mass_kg": { + "name": "rel_mass_kg", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tank": { + "name": "tank", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "project": { + "name": "project", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "died": { + "name": "died", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_file": { + "name": "source_file", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_sheet": { + "name": "source_sheet", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "lab_wq": { + "name": "lab_wq", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time_min": { + "name": "time_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tank": { + "name": "tank", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "temp": { + "name": "temp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ph": { + "name": "ph", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "do_mg": { + "name": "do_mg", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "do_pct": { + "name": "do_pct", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "salinity": { + "name": "salinity", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "recorder": { + "name": "recorder", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "logger_daily": { + "name": "logger_daily", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mean": { + "name": "mean", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "min": { + "name": "min", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "max": { + "name": "max", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hours": { + "name": "hours", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "loggers": { + "name": "loggers", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "logger_daily_site": { + "name": "logger_daily_site", + "columns": [ + "site_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "logger_diel": { + "name": "logger_diel", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "month": { + "name": "month", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hour": { + "name": "hour", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "temp": { + "name": "temp", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "logger_files": { + "name": "logger_files", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "file": { + "name": "file", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "system": { + "name": "system", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "logger": { + "name": "logger", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "serial": { + "name": "serial", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_basis": { + "name": "site_basis", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "start": { + "name": "start", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "end": { + "name": "end", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "samples": { + "name": "samples", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kept": { + "name": "kept", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "lat": { + "name": "lat", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lon": { + "name": "lon", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "excluded": { + "name": "excluded", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "meta": { + "name": "meta", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "mouth": { + "name": "mouth", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "shark_no": { + "name": "shark_no", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tag": { + "name": "tag", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "species": { + "name": "species", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sex": { + "name": "sex", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mol": { + "name": "mol", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mow": { + "name": "mow", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "ocean_daily": { + "name": "ocean_daily", + "columns": { + "date": { + "name": "date", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "oisst": { + "name": "oisst", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crw_sst": { + "name": "crw_sst", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crw_anom": { + "name": "crw_anom", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crw_hotspot": { + "name": "crw_hotspot", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crw_dhw": { + "name": "crw_dhw", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crw_baa": { + "name": "crw_baa", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wave_max": { + "name": "wave_max", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wave_period": { + "name": "wave_period", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wave_dir": { + "name": "wave_dir", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "swell_max": { + "name": "swell_max", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "prey": { + "name": "prey", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "location": { + "name": "location", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "set_crew": { + "name": "set_crew", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "set_id": { + "name": "set_id", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "person": { + "name": "person", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "set_crew_set": { + "name": "set_crew_set", + "columns": [ + "set_id" + ], + "isUnique": false + }, + "set_crew_person": { + "name": "set_crew_person", + "columns": [ + "person" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "sets": { + "name": "sets", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "season": { + "name": "season", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "set_no": { + "name": "set_no", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_id": { + "name": "site_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "site_raw": { + "name": "site_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "weekday": { + "name": "weekday", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gear": { + "name": "gear", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "visit": { + "name": "visit", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crew_raw": { + "name": "crew_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "crew_size": { + "name": "crew_size", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "start_min": { + "name": "start_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "end_min": { + "name": "end_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "duration_min": { + "name": "duration_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_cm": { + "name": "n_cm", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_na": { + "name": "n_na", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_nf": { + "name": "n_nf", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_total": { + "name": "n_total", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "n_linked": { + "name": "n_linked", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpue": { + "name": "cpue", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpue_cm": { + "name": "cpue_cm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpue_na": { + "name": "cpue_na", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cpue_sheet": { + "name": "cpue_sheet", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_raw": { + "name": "tide_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "moon_raw": { + "name": "moon_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "weather_raw": { + "name": "weather_raw", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cloud_cover": { + "name": "cloud_cover", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "water_temp": { + "name": "water_temp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "ph": { + "name": "ph", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "do_mg": { + "name": "do_mg", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "do_pct": { + "name": "do_pct", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "salinity": { + "name": "salinity", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "depth_cm": { + "name": "depth_cm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sunset_min": { + "name": "sunset_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "civil_dusk_min": { + "name": "civil_dusk_min", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "moon_phase": { + "name": "moon_phase", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "moon_illum": { + "name": "moon_illum", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "moon_alt_mid": { + "name": "moon_alt_mid", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_start_mm": { + "name": "tide_start_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_mid_mm": { + "name": "tide_mid_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_trend": { + "name": "tide_trend", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tide_range_mm": { + "name": "tide_range_mm", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "air_temp": { + "name": "air_temp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wind_speed": { + "name": "wind_speed", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wind_dir": { + "name": "wind_dir", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gusts": { + "name": "gusts", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rain_24h": { + "name": "rain_24h", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rain_evening": { + "name": "rain_evening", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cloud_evening": { + "name": "cloud_evening", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pressure": { + "name": "pressure", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sst": { + "name": "sst", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sst_anom": { + "name": "sst_anom", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dhw": { + "name": "dhw", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wave_height": { + "name": "wave_height", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "swell_height": { + "name": "swell_height", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "oni": { + "name": "oni", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "insitu_temp": { + "name": "insitu_temp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_file": { + "name": "source_file", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_sheet": { + "name": "source_sheet", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "sets_season": { + "name": "sets_season", + "columns": [ + "season" + ], + "isUnique": false + }, + "sets_site": { + "name": "sets_site", + "columns": [ + "site_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "sites": { + "name": "sites", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "island": { + "name": "island", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "lat": { + "name": "lat", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lon": { + "name": "lon", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "coord_source": { + "name": "coord_source", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "retired": { + "name": "retired", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fishing_effort": { + "name": "fishing_effort", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "human_impact": { + "name": "human_impact", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "artificialisation": { + "name": "artificialisation", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pressure_composite": { + "name": "pressure_composite", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pressure_tier": { + "name": "pressure_tier", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "directions": { + "name": "directions", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "habitat": { + "name": "habitat", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "aliases": { + "name": "aliases", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tide_extrema": { + "name": "tide_extrema", + "columns": { + "ts": { + "name": "ts", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mm": { + "name": "mm", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "tide_hourly": { + "name": "tide_hourly", + "columns": { + "ts": { + "name": "ts", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "mm": { + "name": "mm", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "weather_daily": { + "name": "weather_daily", + "columns": { + "date": { + "name": "date", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "tmax": { + "name": "tmax", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tmin": { + "name": "tmin", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tmean": { + "name": "tmean", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "precip": { + "name": "precip", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wind_max": { + "name": "wind_max", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gust_max": { + "name": "gust_max", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wind_dir": { + "name": "wind_dir", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "radiation": { + "name": "radiation", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cloud": { + "name": "cloud", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pressure": { + "name": "pressure", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "humidity": { + "name": "humidity", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sunshine_h": { + "name": "sunshine_h", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "weather_hourly": { + "name": "weather_hourly", + "columns": { + "ts": { + "name": "ts", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "temp": { + "name": "temp", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "precip": { + "name": "precip", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cloud": { + "name": "cloud", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wind": { + "name": "wind", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wind_dir": { + "name": "wind_dir", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "gust": { + "name": "gust", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "pressure": { + "name": "pressure", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index a859206..cbd1e96 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1793666235332, "tag": "0001_breezy_phantom_reporter", "breakpoints": true + }, + { + "idx": 2, + "version": "6", + "when": 1793678374777, + "tag": "0002_cloudy_red_wolf", + "breakpoints": true } ] } \ No newline at end of file diff --git a/samples/fixture/Physioshark_Shark Log 2021-2022.xlsx b/samples/fixture/Physioshark_Shark Log 2021-2022.xlsx index d775785..203a1b8 100644 Binary files a/samples/fixture/Physioshark_Shark Log 2021-2022.xlsx and b/samples/fixture/Physioshark_Shark Log 2021-2022.xlsx differ diff --git a/scripts/make-fixture.mjs b/scripts/make-fixture.mjs index bde8986..7bb837b 100644 --- a/scripts/make-fixture.mjs +++ b/scripts/make-fixture.mjs @@ -111,7 +111,10 @@ const cm = [ 'Release Time', 'US', 'Photo ', - 'Notes' + 'Notes', + 'Gastic lavage', + 'Stomach content ', + 'Stomach sample type ' ] ]; const na = [cm[0].slice()]; @@ -160,7 +163,15 @@ for (let i = 0; i < 40; i++) { T(start + 30 + k * 25), open ? 'Open' : 'Closed', 'Yes', - k === 0 && i % 7 === 0 ? 'Synthetic note: ray swimming along the net' : null + k === 0 && i % 7 === 0 ? 'Synthetic note: ray swimming along the net' : null, + // Gastric lavage on every other blacktip (deterministic, so other values don't shift). + ...(species === 'Cm' && shark.Cm % 2 === 0 + ? [ + 'yes', + ['empty', 'traces of food', 'full'][shark.Cm % 3], + shark.Cm % 3 === 2 ? 'small fish' : 'na' + ] + : ['no', 'no sample', 'na']) ]; (species === 'Cm' ? cm : na).push(row); if (species === 'Cm') nCm++; diff --git a/src/lib/server/analytics/diet.ts b/src/lib/server/analytics/diet.ts new file mode 100644 index 0000000..687e230 --- /dev/null +++ b/src/lib/server/analytics/diet.ts @@ -0,0 +1,117 @@ +/** + * Stomach contents from gastric lavage (#40): 2016-17 (full/empty + contents) and 2020-21 + * (empty / traces / full). "Fed" = anything in the stomach (full or traces). Exploratory: a + * lavage only sees the last few hours of feeding. + */ +import { boxStats, chiSquare, welch, wilson } from '#lib/stats'; +import type { Capture, Dataset } from '../data'; +import { fieldCaptures, fulton, round } from './common'; + +export const PREY_GROUPS = [ + { key: 'fish', label: 'Fish', re: /fish|bone|vertebra|lens|scale|surgeon|tuna|goby|mullet/ }, + { key: 'crustacean', label: 'Crustaceans', re: /shrimp|crab|crustac|prawn|isopod|amphipod/ }, + { key: 'other', label: 'Worms and molluscs', re: /worm|squid|octopus|mollus|snail|polych/ }, + { key: 'plastic', label: 'Plastic', re: /plastic/ }, + { key: 'unknown', label: 'Unidentified', re: /goo|unident|chunk|meat|muscle|piece|mush/ } +] as const; + +const fed = (c: Capture) => c.stomach === 'full' || c.stomach === 'traces'; + +function share(caps: Capture[]) { + const k = caps.filter(fed).length; + const ci = wilson(k, caps.length); + return { + n: caps.length, + fed: k, + rate: caps.length ? round(k / caps.length, 3) : null, + lo: round(ci?.lo, 3), + hi: round(ci?.hi, 3) + }; +} + +/** Chi-square across groups of fed / not fed. */ +const test = (groups: Capture[][]) => + chiSquare(groups.map((g) => [g.filter(fed).length, g.filter((c) => !fed(c)).length])); + +const MOON = [ + { label: 'New moon', test: (p: number) => p < 0.125 || p >= 0.875 }, + { label: 'First quarter', test: (p: number) => p >= 0.125 && p < 0.375 }, + { label: 'Full moon', test: (p: number) => p >= 0.375 && p < 0.625 }, + { label: 'Last quarter', test: (p: number) => p >= 0.625 && p < 0.875 } +]; + +const AFTER_SUNSET = [ + { label: 'Before sunset', lo: -Infinity, hi: 0 }, + { label: '0–1 h after', lo: 0, hi: 60 }, + { label: '1 h or more after', lo: 60, hi: Infinity } +]; + +const SCAR = [ + { key: 'open', label: 'Open scar (newborn)' }, + { key: 'semi', label: 'Healing scar' }, + { key: 'closed', label: 'Healed scar' } +] as const; + +export function diet(d: Dataset) { + const checked = fieldCaptures(d).filter((c) => c.stomach != null); + const cm = checked.filter((c) => c.species === 'Cm'); + if (!checked.length) return null; + + const bySeason = [...new Set(checked.map((c) => `${c.season}|${c.species}`))] + .sort() + .map((k) => { + const [season, species] = k.split('|'); + const g = checked.filter((c) => c.season === season && c.species === species); + return { + season, + species, + n: g.length, + full: g.filter((c) => c.stomach === 'full').length, + traces: g.filter((c) => c.stomach === 'traces').length, + empty: g.filter((c) => c.stomach === 'empty').length + }; + }) + .filter((r) => r.n >= 10); + + const scarGroups = SCAR.map((s) => cm.filter((c) => c.umbilical === s.key)); + const moonGroups = MOON.map((m) => cm.filter((c) => c.moonPhase != null && m.test(c.moonPhase))); + const sunsetGroups = AFTER_SUNSET.map((b) => + cm.filter( + (c) => c.minAfterSunset != null && c.minAfterSunset >= b.lo && c.minAfterSunset < b.hi + ) + ); + + // Body condition of fed vs empty blacktips (Fulton's K). + const kFed = cm.filter(fed).map(fulton); + const kEmpty = cm.filter((c) => !fed(c)).map(fulton); + const kTest = welch(kFed, kEmpty); + + // Prey groups named in the free-text contents (any species). + const withContents = checked.filter((c) => c.stomachContents); + const prey = PREY_GROUPS.map((g) => ({ + key: g.key, + label: g.label, + n: withContents.filter((c) => g.re.test(c.stomachContents!.toLowerCase())).length + })).filter((g) => g.n > 0); + + return { + n: checked.length, + nCm: cm.length, + seasons: [...new Set(checked.map((c) => c.season))].sort(), + bySeason, + cmFed: share(cm), + scar: SCAR.map((s, i) => ({ label: s.label, ...share(scarGroups[i]) })), + scarTest: test(scarGroups), + moon: MOON.map((m, i) => ({ label: m.label, ...share(moonGroups[i]) })), + moonTest: test(moonGroups), + sunset: AFTER_SUNSET.map((b, i) => ({ label: b.label, ...share(sunsetGroups[i]) })), + sunsetTest: test(sunsetGroups), + condition: [ + { name: 'Food in stomach', stats: boxStats(kFed) }, + { name: 'Empty', stats: boxStats(kEmpty) } + ].filter((b) => b.stats && b.stats.n >= 5), + conditionP: kTest?.p ?? null, + withContents: withContents.length, + prey + }; +} diff --git a/src/lib/server/analytics/findings.ts b/src/lib/server/analytics/findings.ts index 8838272..8de249f 100644 --- a/src/lib/server/analytics/findings.ts +++ b/src/lib/server/analytics/findings.ts @@ -20,6 +20,7 @@ import { } from './common'; import { catchModel } from './catchModel'; import { cloudWater } from './cloud'; +import { diet } from './diet'; import { dailyMaxBySite, versusSst } from './insitu'; export interface Finding { @@ -417,6 +418,21 @@ function compute(d: Dataset): Finding[] { }); } + // Stomach contents (#40) + const dt = diet(d); + if (dt && dt.nCm >= 30 && dt.cmFed.rate != null) { + const items = [...dt.prey].filter((p) => p.key !== 'unknown').sort((a, b) => b.n - a.n); + const plastic = dt.prey.find((p) => p.key === 'plastic')?.n ?? 0; + out.push({ + id: 'lavage', + kind: 'pattern', + title: dt.cmFed.rate < 0.5 ? 'Most pups have an empty stomach' : 'Most pups had eaten', + value: `${pct(dt.cmFed.rate)} fed`, + text: `Of ${num(dt.nCm)} blacktips checked by gastric lavage, ${num(dt.cmFed.fed)} had food in the stomach.${items.length ? ` ${items[0].label} turn up most often in the samples (${items[0].n})${items[1] ? `, then ${items[1].label.toLowerCase()} (${items[1].n})` : ''}.` : ''}${plastic ? ` ${plastic === 1 ? 'One sample' : `${plastic} samples`} contained plastic.` : ''}`, + href: '/physiology' + }); + } + // Fun totals const totalTl = caps.reduce((a, c) => a + (c.tlMm ?? 0), 0) / 1e6; const totalKg = caps.reduce((a, c) => a + (c.massKg ?? 0), 0); diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts index f8ce78d..4bc6d50 100644 --- a/src/lib/server/db/schema.ts +++ b/src/lib/server/db/schema.ts @@ -160,6 +160,10 @@ export const captures = sqliteTable( habitat: text('habitat'), tideRaw: text('tide_raw'), notes: text('notes'), + // Gastric lavage (#40): done?, fullness (full | traces | empty), free-text contents. + lavage: integer('lavage'), + stomach: text('stomach'), + stomachContents: text('stomach_contents'), // Environment joined at import time. minAfterSunset: real('min_after_sunset'), minAfterNetIn: real('min_after_net_in'), diff --git a/src/lib/server/import/import.test.ts b/src/lib/server/import/import.test.ts index 2eb9c2b..09998b4 100644 --- a/src/lib/server/import/import.test.ts +++ b/src/lib/server/import/import.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from 'vitest'; import { dataset } from '../data'; +import { diet } from '../analytics/diet'; import { topFindings } from '../analytics/findings'; import { seasonRewind } from '../analytics/rewind'; @@ -53,6 +54,21 @@ describe('import of the synthetic fixture', () => { expect(d.notes.some((n) => n.text.includes('ray swimming'))).toBe(true); }); + it('reads gastric lavage columns (#40)', () => { + const checked = d.captures.filter((c) => c.stomach != null); + expect(checked.length).toBeGreaterThan(5); + expect(checked.every((c) => c.species === 'Cm' && c.lavage === 1)).toBe(true); + expect(new Set(checked.map((c) => c.stomach))).toEqual(new Set(['empty', 'traces', 'full'])); + // "no sample" and "na" are not contents; only the full stomachs name food. + const named = d.captures.filter((c) => c.stomachContents); + expect(named.every((c) => c.stomach === 'full' && c.stomachContents === 'small fish')).toBe( + true + ); + const r = diet(d)!; + expect(r.nCm).toBe(checked.length); + expect(r.prey.map((p) => p.key)).toEqual(['fish']); + }); + it('computes findings without throwing', () => { expect(topFindings(d).length).toBeGreaterThan(3); }); diff --git a/src/lib/server/import/index.ts b/src/lib/server/import/index.ts index 42723c6..a3e90ce 100644 --- a/src/lib/server/import/index.ts +++ b/src/lib/server/import/index.ts @@ -73,7 +73,7 @@ import { SITE_DEFS } from './sites'; import { readWorkbook } from './xlsx'; /** Bump when import logic changes so existing caches rebuild on the next start. */ -export const IMPORTER_VERSION = '5'; +export const IMPORTER_VERSION = '6'; const MIGRATIONS = import.meta.glob('/drizzle/*.sql', { query: '?raw', @@ -743,6 +743,9 @@ export function runImport( habitat: c.habitat, tideRaw: c.tideRaw, notes: c.notes, + lavage: c.lavage, + stomach: c.stomach, + stomachContents: c.stomachContents, ...env, sourceFile: c.ref.file, sourceSheet: c.ref.sheet, diff --git a/src/lib/server/import/logs.ts b/src/lib/server/import/logs.ts index a8d108e..e3b14f4 100644 --- a/src/lib/server/import/logs.ts +++ b/src/lib/server/import/logs.ts @@ -7,6 +7,7 @@ import { parseCrew } from './crew'; import type { IssueLog, SourceRef } from './issues'; import { ageClassOf, + contentsOf, dateOf, durationOf, fixSeasonYear, @@ -15,6 +16,7 @@ import { num, sexOf, speciesOf, + stomachOf, str, tagsOf, text, @@ -24,7 +26,8 @@ import { umbilicalOf, yesNo, type AgeClass, - type SpeciesCode + type SpeciesCode, + type StomachState } from './normalize'; import { resolveSite } from './sites'; import type { CellValue, Sheet } from './xlsx'; @@ -66,6 +69,10 @@ export interface RawCapture { habitat: string | null; tideRaw: string | null; notes: string | null; + /** Gastric lavage done (#40). */ + lavage: number | null; + stomach: StomachState | null; + stomachContents: string | null; /** Grouping key from a "Recaptures" sheet (2013-15) used to link untagged captures. */ group?: string; ref: SourceRef; @@ -142,7 +149,9 @@ const CAPTURE_SPEC = { tide: [eq('tide')], notes: [eq('notes', 'notes s', 'comments', 'comment')], recapPrev: [/^recap from previous year/], - stomach: [/^stomach content/, /^lavage contents/] + lavage: [eq('lavage y n', 'gastic lavage', 'gastric lavage', 'eversion lavage')], + stomach: [eq('lavage full empty', 'stomach content', 'stomach contents')], + contents: [eq('lavage contents', 'stomach sample type', 'state of stomach')] } satisfies Record; /** Does this sheet hold shark captures (and not lab/set/HOBO/PIT logs)? */ @@ -355,6 +364,13 @@ export function parseCaptureSheet( ) kind = 'hook'; const notesLower = (notes ?? '').toLowerCase(); + // Fullness and contents share columns across seasons; whatever isn't a fullness word is content. + const stomachCell = cell(row, c.stomach); + const stomach = stomachOf(stomachCell); + const stomachContents = + [contentsOf(cell(row, c.contents)), stomach ? null : contentsOf(stomachCell)] + .filter(Boolean) + .join('; ') || null; const rec: RawCapture = { season, species, @@ -395,6 +411,9 @@ export function parseCaptureSheet( habitat, tideRaw: text(cell(row, c.tide)), notes, + lavage: yesNo(cell(row, c.lavage)) ?? (stomach || stomachContents ? 1 : null), + stomach, + stomachContents, ref }; if (!rec.sex && !isBlank(cell(row, c.sex)) && cell(row, c.sex) != null) @@ -567,6 +586,9 @@ export function parseRecaptures2014( habitat: null, tideRaw: null, notes, + lavage: null, + stomach: null, + stomachContents: null, ref }); } diff --git a/src/lib/server/import/normalize.test.ts b/src/lib/server/import/normalize.test.ts index 7174b85..b80929d 100644 --- a/src/lib/server/import/normalize.test.ts +++ b/src/lib/server/import/normalize.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest'; import { parseCrew } from './crew'; import { ageClassOf, + contentsOf, dateOf, dmsToDecimal, fixSeasonYear, @@ -10,6 +11,7 @@ import { seasonOf, sexOf, speciesOf, + stomachOf, tagsOf, timeOf, umbilicalFromNotes, @@ -19,6 +21,19 @@ import { resolveSite } from './sites'; import { ExcelDate } from './xlsx'; describe('cell parsers', () => { + it('reads stomach fullness and contents (#40)', () => { + expect(stomachOf('Full')).toBe('full'); + expect(stomachOf('empty')).toBe('empty'); + expect(stomachOf('almost empty')).toBe('traces'); + expect(stomachOf('traces of food')).toBe('traces'); + expect(stomachOf('no sample')).toBeNull(); + expect(stomachOf('n/a')).toBeNull(); + expect(stomachOf('worm found')).toBeNull(); + expect(contentsOf('small fish, shrimp')).toBe('small fish, shrimp'); + for (const v of ['na', 'no food', 'traces of food (too small for sample)', 'no sample']) + expect(contentsOf(v)).toBeNull(); + }); + it('parses numbers and rejects NA spellings', () => { expect(num('1,2')).toBe(1.2); expect(num('45 mm')).toBe(45); diff --git a/src/lib/server/import/normalize.ts b/src/lib/server/import/normalize.ts index 7654d74..cd974fe 100644 --- a/src/lib/server/import/normalize.ts +++ b/src/lib/server/import/normalize.ts @@ -45,6 +45,27 @@ export function text(v: CellValue | undefined): string | null { return /^(#n\/a|na|n\/a|-|\?)$/i.test(s) ? null : s; } +export type StomachState = 'full' | 'traces' | 'empty'; + +/** Lavage / stomach fullness (#40): "full", "empty", "almost empty", "traces of food"… */ +export function stomachOf(v: CellValue | undefined): StomachState | null { + const s = text(v)?.toLowerCase(); + if (!s || /no sample/.test(s)) return null; + if (/almost empty|trace/.test(s)) return 'traces'; + if (/^(empty|no food)\b/.test(s)) return 'empty'; + if (/^full\b/.test(s)) return 'full'; + return null; +} + +/** Free-text stomach contents, without the cells that only restate fullness or "no sample". */ +export function contentsOf(v: CellValue | undefined): string | null { + const s = text(v); + if (!s) return null; + return /^(no sample|no food|none|empty|full|almost empty|traces? of food\b.*)$/i.test(s.trim()) + ? null + : s; +} + /** Numbers, including strings like "1,2", "~45", "45 mm", "0.9kg". */ export function num(v: CellValue | undefined): number | null { if (v == null || typeof v === 'boolean') return null; diff --git a/src/lib/stats.test.ts b/src/lib/stats.test.ts index 1752790..83877e8 100644 --- a/src/lib/stats.test.ts +++ b/src/lib/stats.test.ts @@ -2,9 +2,12 @@ import { describe, expect, it } from 'vitest'; import { binomTestHalf, boxStats, + chiSquare, + chiSquareP, histogram, linearFit, median, + normalP, powerFit, quantile, spearman, @@ -56,3 +59,24 @@ describe('stats', () => { expect(b.hi).toBe(4); }); }); + +describe('chi-square', () => { + it('matches textbook critical values', () => { + expect(chiSquareP(3.841, 1)).toBeCloseTo(0.05, 3); + expect(chiSquareP(5.991, 2)).toBeCloseTo(0.05, 3); + expect(chiSquareP(18.307, 10)).toBeCloseTo(0.05, 3); + expect(chiSquareP(0, 3)).toBe(1); + expect(normalP(1.96)).toBeCloseTo(0.05, 4); + expect(normalP(-2.576)).toBeCloseTo(0.01, 4); + }); + it('tests independence in a table of counts', () => { + const r = chiSquare([ + [10, 20], + [20, 10] + ])!; + expect(r.df).toBe(1); + expect(r.stat).toBeCloseTo(6.667, 3); + expect(r.p).toBeCloseTo(0.00982, 4); + expect(chiSquare([[5, 5]])).toBeNull(); + }); +}); diff --git a/src/lib/stats.ts b/src/lib/stats.ts index 2844c68..e492686 100644 --- a/src/lib/stats.ts +++ b/src/lib/stats.ts @@ -143,6 +143,66 @@ export function normalP(z: number): number { return Math.min(1, t * Math.exp(poly)); } +/** Upper regularised incomplete gamma Q(a, x) (Numerical Recipes series / continued fraction). */ +function gammaQ(a: number, x: number): number { + if (x <= 0) return 1; + const front = Math.exp(-x + a * Math.log(x) - logGamma(a)); + if (x < a + 1) { + let ap = a; + let del = 1 / a; + let sum = del; + for (let n = 0; n < 500; n++) { + ap++; + del *= x / ap; + sum += del; + if (Math.abs(del) < Math.abs(sum) * 1e-14) break; + } + return Math.max(0, 1 - sum * front); + } + const tiny = 1e-300; + let b = x + 1 - a; + let c = 1 / tiny; + let d = 1 / b; + let h = d; + for (let i = 1; i < 500; i++) { + const an = -i * (i - a); + b += 2; + d = an * d + b; + if (Math.abs(d) < tiny) d = tiny; + c = b + an / c; + if (Math.abs(c) < tiny) c = tiny; + d = 1 / d; + const del = d * c; + h *= del; + if (Math.abs(del - 1) < 1e-14) break; + } + return front * h; +} + +/** Upper-tail p-value of a chi-square statistic. */ +export const chiSquareP = (stat: number, df: number) => gammaQ(df / 2, stat / 2); + +/** Pearson chi-square test of independence for a table of counts (rows × columns). */ +export function chiSquare(table: number[][]): { stat: number; df: number; p: number } | null { + const rows = table.filter((r) => r.some((v) => v > 0)); + const cols = rows[0]?.map((_, j) => rows.reduce((a, r) => a + r[j], 0)) ?? []; + const keep = cols.map((c) => c > 0); + const t = rows.map((r) => r.filter((_, j) => keep[j])); + const colSums = cols.filter((c) => c > 0); + const n = colSums.reduce((a, b) => a + b, 0); + if (t.length < 2 || colSums.length < 2 || !n) return null; + let stat = 0; + for (const r of t) { + const rs = r.reduce((a, b) => a + b, 0); + r.forEach((v, j) => { + const e = (rs * colSums[j]) / n; + stat += (v - e) ** 2 / e; + }); + } + const df = (t.length - 1) * (colSums.length - 1); + return { stat, df, p: chiSquareP(stat, df) }; +} + /** Two-sided p-value for a t statistic with `df` degrees of freedom. */ export function tTestP(t: number, df: number): number { if (!Number.isFinite(t) || df <= 0) return NaN; diff --git a/src/routes/physiology/+page.server.ts b/src/routes/physiology/+page.server.ts index efe4234..cf0c84b 100644 --- a/src/routes/physiology/+page.server.ts +++ b/src/routes/physiology/+page.server.ts @@ -1,4 +1,5 @@ import { memo } from '#lib/server/data'; +import { diet } from '#lib/server/analytics/diet'; import { boxOf, fulton, round, seasonDay, siteName } from '#lib/server/analytics/common'; import { countBy, histogram, linearFit, mean, pairs } from '#lib/stats'; import type { PageServerLoad } from './$types'; @@ -80,6 +81,7 @@ export const load: PageServerLoad = () => .filter((s) => s.points.length > 5); return { + diet: diet(d), nBlood: blood.length, hct: metric('hct'), chol: metric('cholesterol'), diff --git a/src/routes/physiology/+page.svelte b/src/routes/physiology/+page.svelte index f3e93cd..550a5a1 100644 --- a/src/routes/physiology/+page.svelte +++ b/src/routes/physiology/+page.svelte @@ -6,8 +6,8 @@ import Histogram from '#lib/components/charts/Histogram.svelte'; import LineChart from '#lib/components/charts/LineChart.svelte'; import Scatter from '#lib/components/charts/Scatter.svelte'; - import { date, num, pValue, season } from '#lib/format'; - import { SERIES } from '#lib/species'; + import { date, num, pct, pValue, season } from '#lib/format'; + import { SERIES, speciesName } from '#lib/species'; import type { PageProps } from './$types'; let { data }: PageProps = $props(); @@ -15,6 +15,25 @@ const d = new Date(Date.UTC(2001, 7, 1) + day * 86_400_000); return `${d.getUTCDate()} ${['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getUTCMonth()]}`; }; + const dt = $derived(data.diet); + type Share = { + label: string; + n: number; + rate: number | null; + lo: number | null; + hi: number | null; + }; + const shareBars = (rows: Share[]) => ({ + categories: rows.map((r) => `${r.label} (${r.n})`), + series: [ + { name: 'Food in stomach', color: 'var(--series-3)', values: rows.map((r) => r.rate) } + ], + errors: rows.map((r) => + r.lo != null && r.hi != null ? ([r.lo, r.hi] as [number, number]) : null + ) + }); + const testNote = (t: { stat: number; df: number; p: number } | null) => + t ? `χ² = ${num(t.stat, 1)}, df = ${t.df}, ${pValue(t.p)}` : ''; const maxMass = $derived(Math.max(1.5, ...data.massPairs.flatMap((p) => [p.x, p.y]))); @@ -156,7 +175,100 @@

Diet

+ {#if dt} +

+ Gastric lavage gently flushes a pup's stomach so its last meals can be seen. The logs record + {num(dt.n)} lavaged pups ({dt.seasons.map((x) => season(x)).join(' and ')}); {pct( + dt.cmFed.rate + )} + of {num(dt.nCm)} blacktips had food in the stomach. A lavage only shows the last few hours of + feeding, so an empty stomach is common. +

+ {/if}
+ {#if dt} + + `${season(r.season)} ${speciesName(r.species).toLowerCase()} (${r.n})` + )} + series={[ + { name: 'Full', color: 'var(--seq-6)', values: dt.bySeason.map((r) => r.full / r.n) }, + { + name: 'Traces of food', + color: 'var(--seq-4)', + values: dt.bySeason.map((r) => r.traces / r.n) + }, + { + name: 'Empty', + color: 'var(--seq-2)', + values: dt.bySeason.map((r) => r.empty / r.n) + } + ]} + valueFormat={(v) => pct(v)} + /> + + = 0.05 ? 'No difference between phases, in line with the published analysis of these lavages.' : 'The phases differ more than chance would suggest.'}` + : ''} + > + pct(v)} labels /> + + = 0.05 ? 'The groups overlap: with these numbers the difference could be chance.' : 'The share differs between scar stages.'}` + : ''} + > + pct(v)} labels /> + + = 0.05 ? 'No clear change through the evening.' : 'The share changes through the evening.'}` + : ''} + > + pct(v)} labels /> + + {#if dt.condition.length === 2} + = 0.05 ? 'pups with food in the stomach are no plumper than those without' : 'the two groups differ'}.` + : ''} + > + num(v, 2)} /> + + {/if} + {#if dt.prey.length} + + p.label)} + series={[ + { name: 'Samples', color: 'var(--series-6)', values: dt.prey.map((p) => p.n) } + ]} + labels + /> + + {/if} + {/if} {#if data.preyTop.length}