openfoodfacts / open-prices

An open database of prices 🧾💸💰🏷️🤑🍽️
https://prices.openfoodfacts.org
GNU Affero General Public License v3.0
35 stars 11 forks source link

Stats per product #254

Open raphodn opened 6 months ago

raphodn commented 6 months ago

Story

In the frontend we would like to start making visualizations (graph, map). Instead of having to fetch all the data via the API, and let the frontend do the aggregation, we could instead create an endpoint /products/{id}/stats that would return the pre-processed data.

Linked issues

Other useful links

Ideas

Price timeseries

Shadows97 commented 5 months ago

@raphodn I offer an automated task which every weekend calculates the average price for each product and stores it in a table. So the endpoint for the stats will only have to retrieve the data over the desired period for the product concerned.

raphodn commented 4 months ago

As discussed on Slack, maybe start with a simpler approach that generates the stat data per request. And see in a second iteration to calculate this data asynchronously + store it in a differant DB

raphodn commented 2 weeks ago

Opting for a generic /prices/stats endpoint that will aggregate price data depending on the filters provided.

Might be very time-consuming to do it on thousands of prices (if no or not enough filters provided), so maybe restrict at some point the number of prices concerned (for instance : if 1000 prices or more, than return an error message instead of doing aggregations)