fix: scope all-categories suggestion candidates by subtype, not category (finding 6)
.build_suggestions()'s recipe-candidate sub-select was keyed on `WHERE category IN (<category>)`. The reserved pseudo-category "All Categories" is never itself a row in summary_categories.category, so in all-categories mode `candidates` always came back empty and coverage signposting (uscogdata#9) was structurally impossible for the one mode whose entire premise is "you cannot sum the wrong scope" -- measured on Los Angeles County FY2011: category = "Public Welfare" reports 2 suggestions (incl. $271,589,000 excluded E68), category = "All Categories" reported 0, silently losing that same signal. Apply the branch's own design principle: the concept boundary is subtype, not category. .build_suggestions() now accepts all_categories/subtype_col/ subtype_scope (all optional, default off, so no other caller's behaviour changes) and, when all-categories mode is active, scopes the candidate sub-select by `<subtype_col> IN (<subtype_scope>)` instead -- symmetric with .build_verb_sql()'s own WHERE predicate. The M/L recipe exclusion and the is.null(category) early return are unchanged. After the fix, LA County FY2011 "All Categories" reports 5 suggestions, including welfare_cash_e68_wide for the exact $271,589,000 gap. Adds two covering tests to test-all-categories.R using the bundled fixture (AL state gov, FY2011, "Corrections"): one end-to-end (per-category and all-categories both signpost the same recipe) and one direct on .build_suggestions() proving the subtype-vs-category branch is what changes the query. Updates the 0.2.0 NEWS entry.
This commit is contained in:
@@ -19,6 +19,19 @@
|
||||
* `cog_categories()` advertises `"All Categories"` for the expenditure and
|
||||
revenue vocabularies, so the reserved value is discoverable.
|
||||
|
||||
* Coverage signposting (see "Signposting now catches partially-suppressed
|
||||
categories" below) now also works in `category = "All Categories"` mode.
|
||||
The recipe-suggestion candidate query used to be scoped by `category`,
|
||||
which is never a match for the reserved `"All Categories"` value, so
|
||||
`provenance$suggestions` always came back empty there — the one mode whose
|
||||
whole point is "you cannot sum the wrong scope" was silently unable to
|
||||
signal a wrong scope. The candidate query is now scoped by the concept's
|
||||
subtype allowlist instead, symmetric with how `.build_verb_sql()` itself
|
||||
scopes the summed total: Los Angeles County FY2011, `category = "All
|
||||
Categories"` still excludes $271,589,000 of aggregate-published Public
|
||||
Welfare (`E68`), but now names `recipe = "welfare_cash_e68_wide"` to
|
||||
recover it instead of reporting zero suggestions.
|
||||
|
||||
## Documentation
|
||||
|
||||
* `cog_geographic_rollup()` and `cog_peer_compare()` now document that
|
||||
|
||||
Reference in New Issue
Block a user