Add price_trend / price_series MCP tools (USDA NASS grain)
Real $/bu price + MoM/YoY change + seasonal percentile context for corn/soy/ wheat, US + states, deep history. Wraps the new /api/data/price-trend and /api/data/price-series endpoints. Changelog updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,49 @@ def test_fmt_futures_no_quote():
|
||||
assert "No futures quote on file" in out
|
||||
|
||||
|
||||
def test_fmt_price_trend():
|
||||
payload = {"commodity": "corn", "geo": "OH", "unit": "$/bu",
|
||||
"source": "USDA NASS Quick Stats",
|
||||
"trend": {"period": "2026-04-01", "value_cents": 468,
|
||||
"prev_cents": 459, "change_cents": 9, "change_pct": 2.0,
|
||||
"yoy_cents": 480, "yoy_change_cents": -12, "yoy_pct": -2.5,
|
||||
"seasonal": {"normal_cents": 435, "median_cents": 430,
|
||||
"min_cents": 400, "max_cents": 480,
|
||||
"percentile": 75, "vs_normal_pct": 7.6,
|
||||
"sample_years": 4},
|
||||
"recent_direction": "up", "baseline_years": 10, "points": 120}}
|
||||
out = fmt.fmt_price_trend(payload)
|
||||
assert "corn — OH" in out
|
||||
assert "$4.68/bu" in out
|
||||
assert "+$0.09" in out and "+2.0%" in out # MoM change
|
||||
assert "−$0.12" in out and "−2.5%" in out # YoY
|
||||
assert "75th pct" in out
|
||||
|
||||
|
||||
def test_fmt_price_trend_empty():
|
||||
out = fmt.fmt_price_trend({"commodity": "wheat", "geo": "US", "unit": "$/bu", "trend": None})
|
||||
assert "No data on file" in out
|
||||
|
||||
|
||||
def test_fmt_price_series():
|
||||
payload = {"commodity": "corn", "geo": "US", "unit": "$/bu", "count": 2,
|
||||
"series": [{"period": "2026-03-01", "value_cents": 459},
|
||||
{"period": "2026-04-01", "value_cents": 468}]}
|
||||
out = fmt.fmt_price_series(payload)
|
||||
assert "Mar 2026" in out and "$4.59/bu" in out
|
||||
assert "Apr 2026" in out and "$4.68/bu" in out
|
||||
|
||||
|
||||
def test_fmt_price_trend_diesel_units():
|
||||
payload = {"commodity": "diesel", "geo": "US", "unit": "$/gal", "source": "EIA",
|
||||
"trend": {"period": "2026-05-25", "value_cents": 552, "prev_cents": 560,
|
||||
"change_cents": -8, "change_pct": -1.4, "yoy_cents": None,
|
||||
"yoy_change_cents": None, "yoy_pct": None, "seasonal": None,
|
||||
"recent_direction": "down", "baseline_years": 10, "points": 200}}
|
||||
out = fmt.fmt_price_trend(payload, label="retail diesel")
|
||||
assert "$5.520/gal" in out # 3-decimal $/gal formatting
|
||||
|
||||
|
||||
def test_fmt_inputs_lime_table():
|
||||
payload = {
|
||||
"product": "lime", "count": 2,
|
||||
|
||||
Reference in New Issue
Block a user