Commit graph

4 commits

Author SHA1 Message Date
d0b7b003f9 feat: fallback nutrient estimation for potassium/calcium/magnesium
OFF data is sparse for fresh produce — spinach, oats, most frozen fruit
have no potassium. Added a curated fallback table (114 foods, USDA-sourced)
that injects estimated K/Ca/Mg at log time when OFF has no data.

How it works:
- data/fallback_nutrients.json: 114 foods with mg/100g values
- FallbackTable: case-insensitive exact + substring name matching
- log_food: injects _est keys (potassium_100g_est etc.) when OFF missing
- sum_nutriments: tries OFF value first (grams×1000), then _est (already mg)

Results for today's smoothie + lunch:
- Potassium: 691mg → 2,530mg (47% of 5400mg goal)
- Calcium: 14mg → 304mg (30% of 1000mg goal)
- Magnesium: 61mg → 330mg (73% of 450mg goal)

38 tests passing (7 new: fallback lookup, est fallback, OFF vs est priority)
2026-08-21 11:36:14 +01:00
a072c6ba5e fix: potassium/calcium/magnesium unit conversion (g → mg)
OFF stores potassium_100g, calcium_100g, magnesium_100g in grams.
Goals are in mg. sum_nutriments now multiplies these by 1000.

Before: potassium showed 0.7mg (was 0.0007g displayed as mg)
After:  potassium shows 691.2mg (banana: 0.32g/100g × 216g × 1000)

Added MG_NUTRIENTS const to db.rs. Updated test assertions.
31 tests passing.
2026-08-21 10:10:22 +01:00
5d8976ef37 feat: POST /ingest endpoint + recent_vitals MCP tool for Apple Health
- Add vitals table (type, timestamp_utc, value JSON, source) with UNIQUE
  (type,timestamp_utc) for idempotent upserts.
- POST /ingest: Bearer-protected HTTP endpoint accepting batched health
  samples (weight, blood_pressure, heart_rate, spo2, steps, sleep, ...).
  Weight samples are mirrored into weight_log so existing weight tools see them.
- recent_vitals MCP tool: reads back ingested vitals, grouped by type with
  min/avg/max/units over a configurable window.
- 6 new tests (31 integration + 2 unit total, all passing).
- Verify live: /ingest POST -> recent_vitals round-trip over MCP protocol.
2026-08-20 21:32:19 +01:00
ebb44fd712 test: add 25-test suite + fix sum_nutriments display keys
- 25 integration tests: DB init, default goals, FTS5 cache, upsert,
  portion scaling (100g/50g/200g/empty/non-numeric), sum_nutriments
  (single/multiple/empty/partial/no-data), meal detection, date format,
  log entry + summary round trip, custom food + sum, delete entry,
  goals get/update, weight log + history + upsert
- Fix: sum_nutriments now uses TRACKED_NUTRIENTS display names (first
  tuple element) instead of deriving from OFF field names — fixes
  proteins→protein, energy-kcal→energy_kcal mismatches
- Fix: weight_log.date is now UNIQUE for proper upsert behavior
- Fix: build_daily_summary remaining keys use display names
- Added lib.rs for integration test access
- Added regex dev-dependency

Closes nutrition-mcp-45t
2026-08-20 17:25:41 +01:00