Repository navigation
feat(Prices): API: stats: new country filter, distinct proof count & last 30 days summary. ref #854 - #1464
feat(Prices): API: stats: new country filter, distinct proof count & last 30 days summary. ref #854#1464rishiraj38 wants to merge 1 commit into
Conversation
…last 30 days summary. ref openfoodfacts#854
8ed4dfe to
c005f86
Compare
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Builds on the existing
GET /api/v1/prices/statsendpoint, following the outline in the issue:PriceFilter: newlocation__osm_address_country_codefilter (exact match, same naming as the existing price tag filter). Without it, all countries are included. Also exposesprice_per, so callers can keep price units apart the same way they already do withcurrency.PriceQuerySet.calculate_stats(): addsproof__count(distinctproof_id) to the existing aggregate, so the filtered stats get their own proof count in the same query.Product.price__stats()gains the same key.last_30_daysobject repeats the same fields for prices whosedateis within the last 30 days.Example:
GET /api/v1/prices/stats?location__osm_address_country_code=FR{ "price__count": 3, "price__min": "10.00", "price__max": "30.00", "price__avg": "20.00", "proof__count": 2, "last_30_days": { "price__count": 2, "price__min": "10.00", "price__max": "30.00", "price__avg": "20.00", "proof__count": 2 } }The OpenAPI schema picks up the new filters and the nested serializer automatically. No migration.
Fixes #854
Tests:
PriceStatsApiTestnow covers the country filter, the distinct proof count, the 30-day window boundary (day 30 in, day 31 out), combining with other filters, and the empty result.PriceQuerySetTestandProductPropertyTestexpectations updated for the new key. Full suite run locally: the new country test fails onmainand passes here. Four challenge tests fail onmaintoo (their fixtures use fixed 2024/2025 dates) and are untouched. ruff clean.Summary by CodeRabbit