[Animal][Ration] Refactor Pen.formulate_optimized_ration()#3043
Conversation
38ff11c to
ffb44f8
Compare
ffb44f8 to
d3cb123
Compare
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1155 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1155 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1145 |
|
🚨 Please update the changelog. This PR cannot be merged until |
Resolved two docstring conflicts in RUFAS/biophysical/animal/pen.py: - remove_animals_by_ids: kept origin's Notes block (O(n) cost explanation) - update_animal_combination: kept HEAD's full-sentence description Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1145 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1145 |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1144 |
|
🚨 Please update the changelog. This PR cannot be merged until |
@tomhuhh , can you elaborate a little bit more on this? I'm a little bit confused about exactly where to add the top-level available feeds(which input file?). Also, I'm assuming it's missing/failing for both dev and this branch from looking at the graph, is that right? Or is it something I removed on this PR? |
JoeWaddell
left a comment
There was a problem hiding this comment.
This looks great! Tested on a few rations and it performs just as it does on dev. Good job tidying this up.
| # Constraint failures that indicate a lactating-cow ration retry should bump the dry matter intake. | ||
| _DMI_INCREASE_CONSTRAINTS: frozenset[str] = frozenset( | ||
| { | ||
| "NE_total_constraint", | ||
| "NE_maintenance_and_activity_constraint", | ||
| "NE_lactation_constraint", | ||
| "NE_growth_constraint", | ||
| "calcium_constraint", | ||
| "phosphorus_constraint", | ||
| "protein_constraint_lower", | ||
| "DMI_constraint_lower", | ||
| } | ||
| ) | ||
| # Multiplier applied to the dry matter intake when a lactating-cow ration retry is warranted. | ||
| _DMI_RETRY_INCREASE_FACTOR: float = 1.1 |
There was a problem hiding this comment.
I also wonder if the _DMI_RETRY_INCREASE_FACTOR should be defined in animal_module_constants.py
It's also failing on |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1144 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1144 |
|
🚨 Please update the changelog. This PR cannot be merged until |
|
Current Coverage: 99% Mypy errors on refactor-pen branch: 1144 |
|
🚨 Unauthorized changes detected in protected files. Please remove these changes if they are not intended. |


Refactor Pen.formulate_optimized_ration() to remove the # noqa: C901 complexity suppression. Reduces complexity from 13 to 2 by extracting four focused helpers, hoists magic values into named class constants, and tightens a few adjacent rough edges in _attempt_formulation.
Context
Issue(s) closed by this pull request: closes #2846
What
Why
formulate_optimized_ration had a McCabe complexity of 13 (suppressed with # noqa: C901), making it hard to read, hard to test in isolation, and hard to extend.
How
Reduced complexity.
Test plan
Input Changes
Output Changes
Filter