Skip to content

frs_wsg_drainage: FWA WSG drainage-closure primitive (v0.32.0) (#211)#212

Merged
NewGraphEnvironment merged 6 commits into
mainfrom
211-frs-wsg-drainage-fwa-wsg-drainage-closur
May 27, 2026
Merged

frs_wsg_drainage: FWA WSG drainage-closure primitive (v0.32.0) (#211)#212
NewGraphEnvironment merged 6 commits into
mainfrom
211-frs-wsg-drainage-fwa-wsg-drainage-closur

Conversation

@NewGraphEnvironment
Copy link
Copy Markdown
Owner

Summary

  • Adds frs_wsg_drainage(conn, watershed_group_code, table = "public.wsg_outlet") — pure FWA-topology primitive returning a focal set's drainage closure, ordered downstream-first by outlet ltree depth.
  • Promotes the inline closure query from NewGraphEnvironment/link@v0.40.5 data-raw/study_area_wsgs.R:44-50 into a reusable, tested fresh export. First consumer: link::lnk_wsg_resolve (lnk_wsg_resolve: bundle-aware WSG resolver (closure + species filter); study_area_wsgs.R → CLI shim link#207).
  • New @family wsg. 11 test_that blocks / 14 expectations (6 arg-validation + 5 live-DB gated on PG_DB_SHARE). Live-validated against fwapg.

Related Issues

Test plan

  • devtools::test(filter = "frs_wsg_drainage") — all 14 expectations pass against live fwapg
  • devtools::document()NAMESPACE + man/frs_wsg_drainage.Rd regenerated, no warnings
  • Live regression baseline: frs_wsg_drainage(conn, c("PARS","BULK")) returns the exact 15-WSG closure KISP, KLUM, LKEL, LSKE, MSKE, USKE, BULK, FINA, LBTN, LPCE, MORR, PARA, PCEA, UPCE, PARS (DS-first)
  • Focal-order invariance, lowercase normalization, unmatched-focal warning, all-unmatched error — all validated in tests

Notes

Beyond the literal SQL port from link, the function adds three safety properties caught during /code-check:

  • Scalar table arg enforced (.frs_validate_identifier is vectorized internally — a vector value would silently slip validation and produce malformed SQL)
  • Focal codes upper-cased internally so c("pars","bulk") doesn't silently miss
  • Unmatched focals warn rather than silently drop, so c("BULK","TYPO") is no longer a quiet partial success

lintr not run — fresh hasn't adopted lintr (not in Suggests); the convention is link-side.

🤖 Generated with Claude Code

NewGraphEnvironment and others added 6 commits May 27, 2026 02:54
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Column confirmed: wsg varchar(4) (matches link's existing query)
- Live PARS+BULK closure returns 15 WSGs DS-first, exact regression
  baseline match

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pure FWA topology primitive — given a focal set of WSG codes, returns the
drainage closure (focal + every WSG they flow through) ordered downstream-first
by outlet ltree depth (`nlevel(outlet) ASC`). SQL ported from link@v0.40.5
data-raw/study_area_wsgs.R; identifier validated, focal values quoted via
DBI::dbQuoteLiteral, scalar table arg enforced, focal codes upper-cased
internally, unmatched focals warn rather than silently drop.

Live-validated against fwapg: PARS+BULK returns the exact 15-WSG closure
(KISP, KLUM, LKEL, LSKE, MSKE, USKE, BULK, FINA, LBTN, LPCE, MORR, PARA,
PCEA, UPCE, PARS) DS-first; lowercase input normalized; TYPO warns.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
11 test_that blocks / 14 expectations:

- Arg validation (no DB): non-character, empty, NA, empty-string, vector
  table, and invalid identifier (asserts the validator's specific
  "table contains invalid characters" message — not a generic class
  match)
- Live DB (skip on PG_DB_SHARE empty): PARS+BULK 15-WSG exact closure,
  focal-order invariance, lowercase input case-folds, unmatched-focal
  warning is raised + returned vector still valid, all-fake-focal errors

All 14 pass against live fwapg.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
frs_wsg_drainage — FWA WSG drainage-closure primitive. Promotes the inline
closure query from link@v0.40.5 data-raw/study_area_wsgs.R into a reusable,
tested fresh export. Pure FWA topology; first consumer is link::lnk_wsg_resolve
(NewGraphEnvironment/link#207).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NewGraphEnvironment NewGraphEnvironment merged commit 5e7fa81 into main May 27, 2026
1 check passed
@NewGraphEnvironment NewGraphEnvironment deleted the 211-frs-wsg-drainage-fwa-wsg-drainage-closur branch May 27, 2026 12:54
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.

frs_wsg_drainage: FWA WSG drainage-closure primitive

1 participant