From 1579666db4b8ebe3a819008b4f05f9731f3aabe0 Mon Sep 17 00:00:00 2001 From: Yarne Coppens Date: Thu, 15 Aug 2024 19:47:30 +0200 Subject: [PATCH] Added collection cost statistic --- src/main.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.py b/src/main.py index 87e8d2b..ee1c21d 100644 --- a/src/main.py +++ b/src/main.py @@ -139,6 +139,24 @@ def get_amount_of_games(query: BoardgameFilterParams = Depends(), session: Sessi return statistic_to_return +@app.get('/statistics/total_collection_cost', response_model=statistic_classes.NumberStatistic) +def get_total_collection_cost(query: BoardgameFilterParams = Depends(), session: Session = Depends(get_session)): + + owned_collection = data_connection.get_user_owned_collection(session) + + owned_collection = query.do_filtering(owned_collection) + + total_cost = sum([boardgame.price_paid for boardgame in owned_collection]) + + statistic_dict = { + "name":"Total cost of the owned collection", + "result":total_cost + } + + statistic_to_return = statistic_classes.NumberStatistic(**statistic_dict) + + return statistic_to_return + @app.get('/statistics/amount_of_games_over_time', response_model=statistic_classes.TimeLineStatistic) def get_amount_of_games_over_time(query: BoardgameFilterParams = Depends(), day_step: int = 1, filter_expansions_out: bool = False, only_expansions: bool = False, session: Session = Depends(get_session)):