Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Price stats API: Allow stats to be grouped by specific field #674

Open
TTalex opened this issue Jan 11, 2025 · 0 comments · May be fixed by #675
Open

Price stats API: Allow stats to be grouped by specific field #674

TTalex opened this issue Jan 11, 2025 · 0 comments · May be fixed by #675

Comments

@TTalex
Copy link
Collaborator

TTalex commented Jan 11, 2025

Problem

There are currently no way of fetching stats grouped by a value other than pulling the entire database.

For example, it would be great to be able to fetch price counts per users, or average price per location, or price count per day, and so on...

In the upcoming challenge page, this would help

  • Rank users by price count (group by users)
  • Display number of contributions per day on a graph (group by date)

Proposed solution

Add a new GET /api/v1/prices/grouped_stats endpoint, with mandatory param group_by matching an existing field.
For example, GET /api/v1/prices/grouped_stats?group_by=date&size=2 would give

{
  "items": [
    {
      "date": "2018-03-27",
      "price__count": 24,
      "price__min": 0.47,
      "price__max": 7.8,
      "price__avg": 2.55,
      "price__sum": 61.2
    },
    {
      "date": "2018-03-31",
      "price__count": 13,
      "price__min": 0.54,
      "price__max": 6.49,
      "price__avg": 3.19,
      "price__sum": 41.49
    }
  ],
  "page": 1,
  "pages": 55,
  "size": 2,
  "total": 110
}

By default, results are ordered following the group_by parameter (here by date), but we could also add an optional param order_by to sort the result with one of the computed result.
For example, GET /api/v1/prices/grouped_stats?group_by=date&size=2&order_by=-price__count would give

{
  "items": [
    {
      "date": "2021-01-11",
      "price__count": 37,
      "price__min": 0.4,
      "price__max": 5.99,
      "price__avg": 2.05,
      "price__sum": 75.8
    },
    {
      "date": "2018-08-09",
      "price__count": 37,
      "price__min": 0.59,
      "price__max": 12.15,
      "price__avg": 2.67,
      "price__sum": 98.71
    }
  ],
  "page": 1,
  "pages": 55,
  "size": 2,
  "total": 110
}
@TTalex TTalex changed the title Price stats API: Allow stats to be grouped by Price stats API: Allow stats to be grouped by specific field Jan 11, 2025
@TTalex TTalex linked a pull request Jan 11, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

1 participant