From f21d63d23e4dbe8e9c6540c29d922191e4dd3260 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Mon, 12 Aug 2024 09:10:03 +0200 Subject: [PATCH] Added way to filter out expansions --- src/main.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 669f281..4bd1027 100644 --- a/src/main.py +++ b/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)