[Econ] Port bedding cost preprocessing to a special-case handler - #3219
Open
matthew7838 wants to merge 2 commits into
Open
[Econ] Port bedding cost preprocessing to a special-case handler#3219matthew7838 wants to merge 2 commits into
matthew7838 wants to merge 2 commits into
Conversation
Moves the issue #3088 bedding implementation from the dedicated_processor branch in EconomicPreprocessor onto the refactor_preprocess special-case architecture as BeddingRequirementsHandler. Behavior is unchanged: per-pen pairing of animal counts with each pen's own bedding price, name-to-type resolution through animal.bedding_configs, annual dollar-per-head billing by calendar year, LAC_COW-only billing per the SME-confirmed price basis, and the emitted econ_bedding_* reporting scalars. Verified identical output on the 7-year freestall example (623.02 head-years x $53.22 = $33,156.91). Also replaces the dangling SeedCostHandler import (seed_costs.py does not exist on the base branch) with the new handler registration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Issue(s) closed by this pull request: closes #3088
Ports the implementation from #3117 (
bedding-mapping) onto therefactor_preprocessspecial-case architecture; #3117 remains the reference for the review history.What
Implements the
Bedding requirementsline item as a special-case handler (RUFAS/EEE/economics/special_cases/bedding_requirements.py, registered asBeddingRequirementsHandler) on top of the preprocessing refactor, replacing thededicated_processordispatch used on thebedding-mappingbranch. Also fixes the base branch's danglingSeedCostHandlerimport (special_cases/seed_costs.pydoes not exist onrefactor_preprocess, so the package did not import).Why
The generic pipeline computed bedding cost as one blended average head count times one blended price, and the pen
bedding_name(a user config name such ascalf_straw) never matched the price-file keys (straw), so every pen fell back to a $1/head placeholder. On the example freestall farm this produced ~$42.50/yr instead of the correct value. The refactor branch introduces the special-case handler architecture, and this line item belongs there.How
BeddingRequirementsHandler.process()resolves each penbedding_name -> bedding_configs.bedding_type -> price file(matching pens by theiridfield, not list position), then bills(average head present that year) x (that year's dollar-per-head price)per calendar year, summed across pens and years.billable_pen_combinations(["LAC_COW"]) are billed - the SME-confirmed price basis is per lactating cow. Pens withbedding_type"none" incur no cost.bedding_type_to_file_keyinmapping.pyis the complete registry of billable bedding types (identity entries deliberate); lookups are strict.biophysical_aggregatereports the billed quantity (head-years) soquantity x price_aggregatereconciles with the line-item total; headline results are also emitted asecon_bedding_total_cost,econ_bedding_billed_head_years, andecon_bedding_avg_price_per_head_yearfor lightweight report filters.Bedding requirementsentry inECONOMIC_MAP, keeping the mapping the single declarative registry.Test plan
tests/test_EEE/test_economics_preprocessing.py(14 ported bedding tests covering per-pen pairing, name-to-type resolution, compound-type normalization, none-skip, leap/partial-year units, multi-year per-year pricing, out-of-order pen ids, missing price file, missing FIPS, quantity-x-price reconciliation, and the framework breakdown flow).bedding-mappingbranch output;quantity x pricereconciles to the cent.Input Changes
input/data/EEE/economics_map.json-Bedding requirementsblock updated to mirrormapping.py(reference file, not loaded at runtime). No user-facing input schema change;animal.bedding_configsandanimal.pen_informationalready exist.Output Changes
BeddingRequirementsHandler.process.econ_bedding_total_cost: total bedding cost in dollars.BeddingRequirementsHandler.process.econ_bedding_billed_head_years: billed quantity in head-years.BeddingRequirementsHandler.process.econ_bedding_avg_price_per_head_year: average dollar-per-head-per-year price used.econ_preprocessed_economic_inputs/econ_economic_line_item_breakdownnow reflects correct per-pen annual cost (values change materially vs the base branch).Filter
{ "name": "Bedding cost (issue #3088)", "filters": [ "econ_bedding_total_cost$", "econ_bedding_billed_head_years$", "econ_bedding_avg_price_per_head_year$" ] }