8000 refactor: gather the nitrogen rules in nitrogen.py and break the remedies cycle by rafatahmed · Pull Request #326 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

refactor: gather the nitrogen rules in nitrogen.py and break the remedies cycle - #326

Merged
rafatahmed merged 3 commits into
mainfrom
refactor/nitrogen-module
Nov 26, 2026
Merged

rafatahmed merged 3 commits into
mainfrom
refactor/nitrogen-module

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Closes #325.

  • New nitrogen.py holds NITROGEN_FORMS, TOTAL_NITROGEN_TOLERANCE, nitrogen_rows, fitted_targets, total_nitrogen and target_total_nitrogen (from composition), and ammonium_allowance, ammonium_allowance_preset, total_n_report and the AMMONIUM_* constants (from engine). validate_targets stays in composition. No re-export shim; importers and tests re-point.
  • materials and label_reconciliation import the shared NITROGEN_FORMS instead of their own copies.
  • evaluate_remedies takes the planner as a required keyword plan; plan_fertilizer_workflow passes itself. Both deferred imports of the fertilizer_workflow / evaluated_remedies cycle go. New test: each scenario runs through the planner that is passed in.
  • A pure restructure: no recipe, total-N report, ammonium cap or error changes. Nothing new is exported; the API reference is unchanged.

Left alone, for a separate decision: joint_problem sums the three forms inline with sum, while total_nitrogen uses math.fsum. Using one function could change the last bit of a result.

Verification: two snapshots from main were compared after each commit and are identical (64-hex hashes masked): 48 files for 11 nitrogen target sets (plain, with the ammonium allowance, with an NH4-N maximum, the workflow, a contradicting total and a batch with a total-N targets file) and 31 files for the batch and mix scenarios. Every runnable test module passes; test_mix_cli and test_grower_journey were run test by test. test_file_headers fails the same 434 cases as main on Windows. Not run locally: the slow ratio modules (they reach this code only through recommend, covered by the snapshot) and the pre-push script (over 5 minutes). No chemistry changed, so the PHREEQC fixture is not re-captured.

…OGEN_FORMS

nitrogen_rows, fitted_targets, total_nitrogen and target_total_nitrogen move from
composition, and the ammonium allowance and total_n_report from engine. materials
and label_reconciliation use the shared form tuple.
…workflow and the remedies no longer import each other
@rafatahmed rafatahmed added the enhancement New feature or request label Nov 26, 2026
@rafatahmed rafatahmed self-assigned this Nov 26, 2026
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 Flahax | 🛠️ Build #36179871 | 📁 Comparing 29e7eb3 against latest (b148375)

  🔍 Preview build  

1 file changed
± changelog.html

@codecov
codecov Bot commented Nov 26, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b148375) to head (29e7eb3).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #326   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          147       148    +1     
  Lines        17459     17464    +5     
  Branches      3539      3539           
=========================================
+ Hits         17459     17464    +5     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafatahmed
rafatahmed marked this pull request as ready for review November 26, 2026 05:42
@rafatahmed
rafatahmed merged commit 0c708be into main Nov 26, 2026
29 checks passed
@rafatahmed
rafatahmed deleted the refactor/nitrogen-module branch November 26, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gather the nitrogen rules in one module and break the remedies import cycle

1 participant

0