Skip to content

feat: add POLYGON_CRITERIA_STATS job handler - #14

Merged
ConnectedSystems merged 1 commit into
mainfrom
feat/polygon-criteria-stats
Aug 3, 2026
Merged

feat: add POLYGON_CRITERIA_STATS job handler#14
ConnectedSystems merged 1 commit into
mainfrom
feat/polygon-criteria-stats

Conversation

@ConnectedSystems

@ConnectedSystems ConnectedSystems commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a new POLYGON_CRITERIA_STATS job type that computes histogram bins and summary statistics for criteria values inside a user-drawn polygon. This is the compute half of the polygon criteria distribution feature; the UI and infra half lives in AIMS/reefguide (branch feat/consolidated-map-ui).

Changes

  • New handler (src/job_worker/handlers.jl): PolygonCriteriaStatsHandler takes a GeoJSON polygon, a region ID and a list of criteria IDs, and returns per-criteria { bins, min, max, mean, median, p5, p95, nodata_count }. Payload structs mirror the TypeScript PolygonCriteriaStatsInput / PolygonCriteriaStatsOutput schemas.
  • Two-pass spatial filter: the slope table is narrowed by a cheap vectorised bbox range check first, then the expensive point-in-polygon test runs only on the reduced candidate set.
  • Stuck-job fix (src/job_worker/worker.jl): if an unhandled exception occurs after a job has been claimed (e.g. an OOM kill), the job is now marked FAILED instead of sitting in IN_PROGRESS indefinitely.
  • Registers the job type in __init__, adds it to .env.dist JOB_TYPES, and adds the Statistics dependency.

Deployment note

PublishDockerImage.yml only runs on release: published or manual workflow_dispatch, and the latest tag is only applied on main. Merging this alone will not update the :latest image that dev/prod consume — a release or manual dispatch from main is needed before the deployed workers will accept the new job type.

Test plan

  • Submit a POLYGON_CRITERIA_STATS job against a known region and polygon; confirm bins and summary stats are returned
  • Confirm criteria columns missing from the slope table are skipped with a warning rather than erroring
  • Confirm an empty polygon (no reef data) returns zeroed stats rather than failing
  • Confirm a job killed mid-processing transitions to FAILED

🤖 Generated with Claude Code

Adds a new job type that computes histogram bins and summary statistics
(min/max/mean/median/p5/p95/nodata_count) for the requested criteria
columns within a user-drawn polygon.

The handler loads regional data, then narrows the slope table with a
two-pass spatial filter: a cheap vectorised bbox range check first, then
the expensive point-in-polygon test only on the reduced candidate set.

Also mark jobs FAILED when an unhandled exception occurs after the job
was claimed (e.g. OOM kill), so they don't sit in IN_PROGRESS forever.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ConnectedSystems
ConnectedSystems merged commit fb2565c into main Aug 3, 2026
1 check passed
@ConnectedSystems
ConnectedSystems deleted the feat/polygon-criteria-stats branch August 3, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant