Skip to content

Commit

Permalink
Aggregate score stats APIs (#126)
Browse files Browse the repository at this point in the history
* Aggregate score stats API

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* cleanup import

* prevent exc

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refmt

* send to prod

* Expose under /public APIs

* remove prod takeover

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: James Wilson <[email protected]>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 2106ef8 commit 0bc59e8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/production-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:

- name: Get kubeconfig from github secrets
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
chmod 600 $HOME/.kube/config
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
chmod 600 $HOME/.kube/config
- name: Install helm
uses: azure/setup-helm@v3
Expand Down
6 changes: 6 additions & 0 deletions app/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fastapi.responses import RedirectResponse

import app.state.services
from . import aggregate_score_stats
from . import direct
from . import favourites
from . import lastfm
Expand Down Expand Up @@ -71,6 +72,11 @@ async def healthcheck() -> Response:

router.add_api_route("/api/v1/pp", pp.calculate_pp)

router.add_api_route(
"/public/api/v1/aggregate-score-stats/total-scores-set",
aggregate_score_stats.total_scores_set,
)


@router.get("/web/bancho-connect.php")
async def bancho_connect() -> Response:
Expand Down
7 changes: 7 additions & 0 deletions app/api/aggregate_score_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import annotations

import app.usecases


async def total_scores_set() -> int:
return await app.usecases.aggregate_score_stats.total_scores_set()
1 change: 1 addition & 0 deletions app/usecases/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from . import aggregate_score_stats
from . import akatsuki_beatmaps
from . import chat
from . import countries
Expand Down
20 changes: 20 additions & 0 deletions app/usecases/aggregate_score_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

import app.state.services


async def total_scores_set() -> int:
return sum(
[
(
await app.state.services.database.fetch_val(
f"""\
SELECT count(*)
FROM {table}
""",
)
or 0
)
for table in ("scores", "scores_relax", "scores_ap")
],
)

0 comments on commit 0bc59e8

Please sign in to comment.