Added way to filter out expansions
This commit is contained in:
parent
45ffc7e89c
commit
f21d63d23e
1 changed files with 13 additions and 5 deletions
18
src/main.py
18
src/main.py
|
|
@ -7,6 +7,7 @@ from contextlib import asynccontextmanager
|
|||
|
||||
from src.classes import boardgame_classes, play_classes, statistic_classes
|
||||
from src.modules import data_connection
|
||||
from src.filters import boardgame_filters
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
|
|
@ -41,8 +42,15 @@ def get_boardgame_by_id(id: int):
|
|||
return requested_boardgame
|
||||
|
||||
@app.get("/owned", response_model=list[Union[boardgame_classes.OwnedBoardGame, boardgame_classes.OwnedBoardGameExpansion]])
|
||||
def get_owned_collection():
|
||||
def get_owned_collection(filter_expansions_out: bool = False, only_expansions: bool = False):
|
||||
to_return_boardgames = data_connection.get_user_owned_collection()
|
||||
|
||||
if filter_expansions_out:
|
||||
to_return_boardgames = boardgame_filters.filter_expansions_out(to_return_boardgames)
|
||||
|
||||
if only_expansions:
|
||||
to_return_boardgames = boardgame_filters.filter_non_expansions_out(to_return_boardgames)
|
||||
|
||||
return to_return_boardgames
|
||||
|
||||
|
||||
|
|
@ -78,11 +86,11 @@ def get_amount_of_games():
|
|||
return statistic_to_return
|
||||
|
||||
@app.get('/statistics/amount_of_games_over_time', response_model=statistic_classes.TimeLineStatistic)
|
||||
def get_amount_of_games_over_time():
|
||||
def get_amount_of_games_over_time(day_step: int = 1):
|
||||
|
||||
def daterange(start_date: date, end_date: date):
|
||||
def daterange(start_date: date, end_date: date, day_step):
|
||||
days = int((end_date - start_date).days)
|
||||
for n in range(days):
|
||||
for n in range(0, days, day_step):
|
||||
yield start_date + timedelta(n)
|
||||
|
||||
games_in_owned_collection = data_connection.get_user_owned_collection()
|
||||
|
|
@ -90,7 +98,7 @@ def get_amount_of_games_over_time():
|
|||
|
||||
timeline_dict = {}
|
||||
|
||||
for current_date in daterange(games_in_owned_collection[0].acquisition_date, date.today()):
|
||||
for current_date in daterange(games_in_owned_collection[0].acquisition_date, date.today(), day_step):
|
||||
games_in_collection_at_date = list(filter(lambda game: game.acquisition_date <= current_date, games_in_owned_collection))
|
||||
timeline_dict[current_date] = len(games_in_collection_at_date)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue