Support filtering for graph (no frontend support yet)
This commit is contained in:
parent
fbdc98f967
commit
dee0c26260
@ -1,4 +1,5 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, Request
|
from fastapi import APIRouter, Depends, Request
|
||||||
from fastapi.responses import HTMLResponse
|
from fastapi.responses import HTMLResponse
|
||||||
@ -16,7 +17,7 @@ html_router = APIRouter(
|
|||||||
|
|
||||||
|
|
||||||
@api_router.get("/graph")
|
@api_router.get("/graph")
|
||||||
def stats_graph_api(db=Depends(get_db)):
|
def stats_graph_api(deck_ids: Optional[str] = None, db=Depends(get_db)):
|
||||||
# TODO - parallelize? (Probably not worth it :P )
|
# TODO - parallelize? (Probably not worth it :P )
|
||||||
|
|
||||||
# SO Answer on row_number: https://stackoverflow.com/a/38160409/1040915
|
# SO Answer on row_number: https://stackoverflow.com/a/38160409/1040915
|
||||||
@ -34,8 +35,11 @@ def stats_graph_api(db=Depends(get_db)):
|
|||||||
.outerjoin(models.EloScore, models.Deck.id == models.EloScore.deck_id)
|
.outerjoin(models.EloScore, models.Deck.id == models.EloScore.deck_id)
|
||||||
.join(models.Game, models.EloScore.after_game_id == models.Game.id)
|
.join(models.Game, models.EloScore.after_game_id == models.Game.id)
|
||||||
.add_column(row_number_column)
|
.add_column(row_number_column)
|
||||||
.subquery()
|
|
||||||
)
|
)
|
||||||
|
if deck_ids is not None:
|
||||||
|
sub_query = sub_query.filter(models.Deck.id.in_(deck_ids.split(",")))
|
||||||
|
|
||||||
|
sub_query = sub_query.subquery()
|
||||||
query = db.query(sub_query).filter(sub_query.c.row_number == 1)
|
query = db.query(sub_query).filter(sub_query.c.row_number == 1)
|
||||||
results = query.all()
|
results = query.all()
|
||||||
|
|
||||||
|
@ -1,14 +1,4 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
const data = [
|
|
||||||
{ year: 2010, count: 10 },
|
|
||||||
{ year: 2011, count: 20 },
|
|
||||||
{ year: 2012, count: 15 },
|
|
||||||
{ year: 2013, count: 25 },
|
|
||||||
{ year: 2014, count: 22 },
|
|
||||||
{ year: 2015, count: 30 },
|
|
||||||
{ year: 2016, count: 28 },
|
|
||||||
];
|
|
||||||
|
|
||||||
fetch('/api/stats/graph')
|
fetch('/api/stats/graph')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user