Added a shelf of shame statistic
This commit is contained in:
parent
427a482b7c
commit
eafb2b386f
3 changed files with 29 additions and 5 deletions
30
src/main.py
30
src/main.py
|
|
@ -170,7 +170,7 @@ def get_amount_of_games_over_time(query: BoardgameFilterParams = Depends(), day_
|
|||
return statistic_to_return
|
||||
|
||||
@app.get('/statistics/games_played_per_year', response_model=statistic_classes.TimeLineStatistic)
|
||||
def get_amount_of_games_played_per_year(query: BoardgameFilterParams = Depends(), session: Session = Depends(get_session)):
|
||||
def get_amount_of_games_played_per_year(query: PlayFilterParams = Depends(), session: Session = Depends(get_session)):
|
||||
all_plays = data_connection.get_plays(session)
|
||||
|
||||
all_plays.sort(key= lambda x: x.play_date)
|
||||
|
|
@ -225,5 +225,29 @@ def get_most_expensive_game(query: BoardgameFilterParams = Depends(), top_amount
|
|||
return statistic_to_return
|
||||
|
||||
@app.get('/statistics/shelf_of_shame', response_model=statistic_classes.GamesStatistic)
|
||||
def get_shelf_of_shame(query: BoardgameFilterParams = Depends(), session: Session = Depends(get_session)):
|
||||
pass
|
||||
def get_shelf_of_shame(query: BoardgameFilterParams = Depends(), top_amount: int = 10, session: Session = Depends(get_session)):
|
||||
boardgames_in_collection = data_connection.get_user_collection(session)
|
||||
|
||||
owned_boardgames = data_connection.get_user_owned_collection(session)
|
||||
|
||||
#To make sure plays are loaded in
|
||||
data_connection.get_plays(session)
|
||||
|
||||
owned_ids = [boardgame.id for boardgame in owned_boardgames]
|
||||
|
||||
owned_boardgames_in_collection = list(filter(lambda x: x.id in owned_ids, boardgames_in_collection))
|
||||
|
||||
owned_boardgames_in_collection = query.do_filtering(owned_boardgames_in_collection)
|
||||
|
||||
print(owned_boardgames_in_collection[0].plays)
|
||||
|
||||
owned_boardgames_no_plays = list(filter(lambda x: len(x.plays) == 0, owned_boardgames_in_collection))
|
||||
|
||||
statistic_dict = {
|
||||
"name":"Shelf of Shame",
|
||||
"result":owned_boardgames_no_plays[0:top_amount]
|
||||
}
|
||||
|
||||
statistic_to_return = statistic_classes.GamesStatistic.model_validate(statistic_dict)
|
||||
|
||||
return statistic_to_return
|
||||
|
|
@ -88,7 +88,7 @@ def get_user_wishlist_collection(session: Session, wishlist_priority: int = 0) -
|
|||
return to_return_boardgames
|
||||
|
||||
|
||||
def get_plays(session: Session, ) -> list[play_classes.Play]:
|
||||
def get_plays(session: Session) -> list[play_classes.Play]:
|
||||
|
||||
plays_from_db = db_connection.get_plays(session)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ sqlite_url = definitions.SQLITE_URL
|
|||
|
||||
|
||||
connect_args = {"check_same_thread": False}
|
||||
engine = create_engine(sqlite_url, echo=True, connect_args=connect_args)
|
||||
engine = create_engine(sqlite_url, echo=False, connect_args=connect_args)
|
||||
|
||||
def get_engine():
|
||||
return engine
|
||||
|
|
|
|||
Loading…
Reference in a new issue