feat: revenue_concept = c("general", "total") off the crosswalk (#12)
Closes the last blocked test in the suite. Owner ruled both halves of the open question yes on 2026-07-30. `cog_revenue()` gains `revenue_concept`, mirroring `expenditure_concept`, with Census's two published concepts defined as crosswalk `revenue_subtype` sets rather than item-code prefixes: general = own_source + federal + state + local_aid (the default) total = general + utility + liquor_store + insurance_trust The manual defines the first by subtracting the other three from the second (4.3), so both are computable only once all four families are named -- which cog_pipeline#79 does. Insurance trust now includes the employee-retirement X codes (X01/X02/X05/X08) alongside the Y codes. - inst/sql: revenue_long / revenue_long_harmonized carry EVERY revenue subtype; the concept narrows in R via the existing subtype_scope machinery, exactly as expenditure_concept narrows spending_long. - cog_explain() now prints each verb's OWN concept. It previously printed `expenditure_concept` unconditionally, so a cog_revenue() caller was told "Concept: primary" -- a spending concept their result has nothing to do with. - Fixture regenerated at pipeline_commit aadb46b (330 crosswalk rows). Corrected two stale expectations in the blocked test while un-skipping it. It asserted X01+X04+X05+X08 and omitted X02, which applies to state governments and is nonzero for Wisconsin; X04 is an exhibit code for an INTRAgovernmental transfer that Census's own "Total Emp Ret Rev" excludes. Verified against that Census field: the right set is X01+X02+X05+X08 = $2,283,883k, exactly. And its expected `total` of $33,377,093k predated the Y codes being classified -- complete Total Revenue for WI FY2012 is $34,881,961k (general 31,338,293 + Y 1,259,785 + X 2,283,883). Behaviour change worth knowing: `general` is now STRICT Census General Revenue, so utility and liquor store revenue leave the default. Measured on the fixture that is 15.9% of what cog_revenue() returned for cities, vs 1.2% for states and 1.7% for counties. Suite: 716 pass / 0 fail / 0 skip -- the first time this package has had no skipped tests. Closes #12
This commit is contained in:
+37
-7
@@ -31,9 +31,26 @@
|
||||
)
|
||||
}
|
||||
|
||||
# cog_revenue()'s single concept (until uscogdata#12 adds more): Census
|
||||
# General Revenue -- every crosswalk revenue subtype except insurance_trust.
|
||||
# The two revenue concepts (uscogdata#12), again as crosswalk subtype sets.
|
||||
# Census's manual section 4.3 defines the first by SUBTRACTING from the second
|
||||
# -- "General revenue comprises all revenue except that classified as liquor
|
||||
# store, utility, or insurance trust revenue" -- giving the identity
|
||||
#
|
||||
# Total Revenue = General + Utility + Liquor Store + Insurance Trust
|
||||
#
|
||||
# Verified against Census's own computed concept fields (IndFin FY2012,
|
||||
# Wisconsin state): 31,410,686 + 0 + 0 + 4,469,906 = 35,880,592, exact.
|
||||
.revenue_subtypes_general <- c("own_source", "federal", "state", "local_aid")
|
||||
.revenue_subtypes_total <- c(.revenue_subtypes_general, "utility",
|
||||
"liquor_store", "insurance_trust")
|
||||
|
||||
#' @noRd
|
||||
.revenue_concept_subtypes <- function(concept) {
|
||||
switch(concept,
|
||||
general = .revenue_subtypes_general,
|
||||
total = .revenue_subtypes_total
|
||||
)
|
||||
}
|
||||
|
||||
#' Summarized spending by category
|
||||
#'
|
||||
@@ -198,6 +215,7 @@ cog_spending <- function(govid, years, category = NULL,
|
||||
per_capita, adjust_to_year,
|
||||
basis = c("harmonized", "raw"), recipe = NULL,
|
||||
expenditure_concept = c("primary", "direct", "total"),
|
||||
revenue_concept = c("general", "total"),
|
||||
complete = FALSE) {
|
||||
basis_explicit <- length(basis) == 1L
|
||||
basis <- match.arg(basis, c("harmonized", "raw"))
|
||||
@@ -215,16 +233,27 @@ cog_spending <- function(govid, years, category = NULL,
|
||||
}
|
||||
)
|
||||
|
||||
revenue_concept <- tryCatch(
|
||||
match.arg(revenue_concept, c("general", "total")),
|
||||
error = function(e) {
|
||||
cli::cli_abort(
|
||||
"`revenue_concept` must be one of {.val general} or {.val total}.",
|
||||
class = "uscogdata_invalid_revenue_concept",
|
||||
parent = e
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
# The concept's subtype scope. Every code path below -- the verb SQL, the
|
||||
# harmonization exclusion count, and the complete = TRUE grid -- is scoped
|
||||
# by crosswalk subtype membership, never by item-code prefix. For revenue
|
||||
# there is a single concept today (General Revenue; uscogdata#12 will add
|
||||
# more). "total"'s extra intergovernmental leg travels through the ig_*
|
||||
# views, not through this scope.
|
||||
# by crosswalk subtype membership, never by item-code prefix. The
|
||||
# expenditure "total" concept's extra intergovernmental leg is the one
|
||||
# exception: it travels through the ig_* views rather than this scope,
|
||||
# because its legacy rows are aggregate-flagged.
|
||||
subtype_scope <- if (identical(subtype_col, "spend_subtype")) {
|
||||
.expenditure_concept_subtypes(expenditure_concept)
|
||||
} else {
|
||||
.revenue_subtypes_general
|
||||
.revenue_concept_subtypes(revenue_concept)
|
||||
}
|
||||
|
||||
govid <- .coerce_govid_input(govid, arg = "govid")
|
||||
@@ -427,6 +456,7 @@ cog_spending <- function(govid, years, category = NULL,
|
||||
expenditure_concept = expenditure_concept,
|
||||
expenditure_concept_note = expenditure_concept_note_for_prov,
|
||||
expenditure_concept_direct_suppressed = direct_suppressed_flag,
|
||||
revenue_concept = revenue_concept,
|
||||
harmonization = harmonization,
|
||||
recipe = recipe_block,
|
||||
suggestions = suggestions,
|
||||
|
||||
Reference in New Issue
Block a user