8000 feat: pH interval, deviation ranges and the total-N urea rule (#303, #304, #305) by rafatahmed · Pull Request #306 · rafatahmed/Flahax · GitHub
[go: up one dir, main page]

Skip to content

feat: pH interval, deviation ranges and the total-N urea rule (#303, #304, #305) - #306

Merged
rafatahmed merged 6 commits into
mainfrom
fix/total-n-urea-zero
Nov 25, 2026
Merged

rafatahmed merged 6 commits into
mainfrom
fix/total-n-urea-zero

Conversation

@rafatahmed
Copy link
Copy Markdown
Owner

Closes #303. Closes #304. Closes #305.

Closes the remaining Phase 3 items of the contract audit that need code: the total-N urea rule (D2), the pH interval (C5, Q31) and acceptable deviation ranges (C2, Q24/26/28/30). Decisions of 2026-11-25: contract Q8/Q9 amended to match decision G24 and the urea-zero rule; keep decisions G1-G4 for omitted alkalinity (C7); pH interval as target_ph=(low, high); build Assess and Require together.

  • Total N: an absent urea is not counted as a zero requirement when checking a declared total #303: total N is nitrate + ammonium + urea and an absent urea is a zero requirement, so a declared nitrate with a positive ammonium determine a declared total. N 150 with N_NO3 100 and N_NH4 30 is now rejected before fitting; a consistent total is scored once. An explicit zero N_NH4 does not determine the total (G24).
  • Accept an acceptable pH interval as the target (C5, Q31) #304: target_ph accepts (low, high), a list in the JSON workflow, and flahax batch takes --ph-min with --ph-max. A mix already inside needs no reagent; otherwise the plan aims at the nearest bound, never a midpoint. Stages that plan a reagent to one pH (nitric, titration, acid selection) report unsupported_ph_interval instead of choosing a point. The summary and report state the interval and the bound aimed at.
  • Deviation ranges: Assess and Require modes (C2, Q24, Q26, Q28, Q30) #305: deviation_ranges on recommend and the workflow, and --range-percent, --range and --require-ranges on flahax batch. A symmetric percentage with per-nutrient shortage/excess overrides in percent or mg/L, none by default; effective ranges are shown. Assess classifies the result as inside, below or above. Require fits with each upper bound as a hard maximum and doubles the weight of a nutrient below its lower bound; an unmet candidate is kept, feasible is false, the unmet nutrients are named and no range is widened. A zero target and a declared maximum are never relaxed.

Limits stated in the docs: Require constrains the nutrient fit before the pH reagent; the final recipe with the reagent is classified in the summary and a miss asks for review. The interactive flahax mix takes one pH and no ranges. The Require search is a candidate, not a proof.

No conversion, speciation, saturation or EC input changed, so the PHREEQC fixture needs no re-capture (it was re-captured on main today: every number matches).

Local checks: ruff clean; 204 of 214 test modules pass (1,798 tests); the 10 heavy modules were run test by test where they exercise the fit (102 of 112 tests OK, 2 over the time cap, 8 not reached). CI is the verifier for the rest.

…red total N (#303)

Total N is nitrate + ammonium + urea. A declared nitrate and a positive ammonium now
determine the total, with urea declared or zero: the forms are scored once and a
disagreeing total is rejected before fitting. An explicit zero N_NH4 asks for nothing
(decision G24) and does not determine the total.
target_ph may be (low, high), a list in the JSON workflow, and flahax batch takes
--ph-min with --ph-max. The interval is judged against its bounds with no midpoint:
a mix already inside needs no reagent and a mix outside is moved to the nearest bound.
Stages that plan a reagent to one pH (nitric, titration, acid selection) report
unsupported_ph_interval instead of choosing a point. The summary and report state the
interval and the bound aimed at.
…Q24, Q26, Q28, Q30) (#305)

A user-declared symmetric percentage with per-nutrient shortage and excess overrides in
percent or mg/L, none by default. Assess classifies the result as inside, below or above
each range; Require fits with each upper bound as a hard maximum and doubles the weight of
a nutrient below its lower bound, keeping an unmet candidate and naming it without widening
any range. Ranges apply to positive targets only and never relax a zero target or a declared
maximum. Available on recommend, the workflow, the JSON workflow and flahax batch
(--range-percent, --range, --require-ranges); the report prints the ranges and the settings
are saved with the inputs.
@rafatahmed rafatahmed added the enhancement New feature or request label Nov 25, 2026
@rafatahmed rafatahmed self-assigned this Nov 25, 2026
@read-the-docs-community
read-the-docs-community Bot commented Nov 25, 2026 •
Copy link
Copy Markdown

…uired range missed on a blocked recipe

The exact coverage gate found the non-mapping override guards, the --ph / --ph-min / --ph-max
command errors and the branch where a missed required range meets an already blocked status
unexecuted.
@codecov
codecov Bot commented Nov 25, 2026
Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #306    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          140       141     +1     
  Lines        17186     17416   +230     
  Branches      3494      3550    +56     
==========================================
+ Hits         17186     17416   +230     
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.

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

1 participant

0