feat: nutrient_cost tool — cheapest fertilizer per lb of N/P/K
CI / test (pull_request) Successful in 18s
CI / build-push (pull_request) Has been skipped

New agbids__nutrient_cost(geo) tool: wraps ag-monitor's /api/data/nutrient-cost
and formats a per-nutrient value comparison for the advisor — cheapest source of
N / P2O5 / K2O + a ranked $/lb table. This is what answers "which fertilizer is
the best nitrogen value per dollar?" (input_cost_trend is $/ton only). UAN grade
shown as assumed 32-0-0.

client.nutrient_cost + fmt.fmt_nutrient_cost (+ _per_lb). 42 tests pass.

For planning #90.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-04 15:52:33 -04:00
parent fb50c103d3
commit 65509a27d6
4 changed files with 123 additions and 0 deletions
+41
View File
@@ -390,3 +390,44 @@ def test_fmt_summary_includes_best_for_today():
assert "Mercer Landmark — St Henry" in out
assert "$4.5800" in out # corn last
assert "No current-month local bid posted" in out # soy fallback
def test_fmt_nutrient_cost():
payload = {
"geo": "Cornbelt",
"source": "USDA AgTransport",
"products": [
{"item": "anhydrous", "label": "anhydrous ammonia", "unit": "$/ton",
"geo": "Cornbelt", "period": "2026-03-01", "price_cents_per_ton": 88062,
"analysis": {"grade": "82-0-0", "grade_assumed": False},
"cost_per_lb": {"n": 54, "p2o5": None, "k2o": None}},
{"item": "urea", "label": "urea", "unit": "$/ton", "geo": "Cornbelt",
"period": "2026-03-01", "price_cents_per_ton": 69812,
"analysis": {"grade": "46-0-0", "grade_assumed": False},
"cost_per_lb": {"n": 76, "p2o5": None, "k2o": None}},
{"item": "uan", "label": "UAN (28-32%)", "unit": "$/ton", "geo": "Cornbelt",
"period": "2026-03-01", "price_cents_per_ton": 47612,
"analysis": {"grade": "32-0-0", "grade_assumed": True},
"cost_per_lb": {"n": 74, "p2o5": None, "k2o": None}},
{"item": "potash", "label": "potash (0-0-60)", "unit": "$/ton",
"geo": "Cornbelt", "period": "2026-03-01", "price_cents_per_ton": 35938,
"analysis": {"grade": "0-0-60", "grade_assumed": False},
"cost_per_lb": {"n": None, "p2o5": None, "k2o": 30}},
],
"cheapest": {"n": "anhydrous", "p2o5": None, "k2o": "potash"},
}
out = fmt.fmt_nutrient_cost(payload)
assert "Cornbelt" in out
assert "Cheapest Nitrogen (N):** anhydrous ammonia at $0.54/lb" in out
assert "Cheapest Potash (K₂O):** potash (0-0-60) at $0.30/lb" in out
# anhydrous (cheapest N) sorts above urea in the table
assert out.index("anhydrous ammonia |") < out.index("| urea |")
# UAN grade-assumed marker + footnote
assert "32-0-0*" in out
assert "UAN grade assumed 32-0-0" in out
# potash supplies no N -> em-dash in the N column
assert "" in out
def test_fmt_nutrient_cost_empty():
assert "No data on file" in fmt.fmt_nutrient_cost({"geo": "Cornbelt", "products": []})