Added most bought artist statistic
This commit is contained in:
parent
6bed246702
commit
61d7abd7f3
5 changed files with 76 additions and 30 deletions
|
|
@ -15,7 +15,7 @@ class PlayerStatistic(StatisticBase):
|
||||||
|
|
||||||
class GamesStatistic(StatisticBase):
|
class GamesStatistic(StatisticBase):
|
||||||
games: list[boardgame_classes.BoardGamePublicNoPlays]
|
games: list[boardgame_classes.BoardGamePublicNoPlays]
|
||||||
result: Dict[int, Union[int,float]]
|
result: Dict[int, Union[int,float,str]]
|
||||||
|
|
||||||
model_config = {
|
model_config = {
|
||||||
'validate_assignment':True
|
'validate_assignment':True
|
||||||
|
|
@ -24,13 +24,6 @@ class GamesStatistic(StatisticBase):
|
||||||
class TimeLineStatistic(StatisticBase):
|
class TimeLineStatistic(StatisticBase):
|
||||||
result: Dict[Union[date, int], Union[int, float]]
|
result: Dict[Union[date, int], Union[int, float]]
|
||||||
|
|
||||||
model_config = {
|
|
||||||
'validate_assignment':True
|
|
||||||
}
|
|
||||||
|
|
||||||
class PeopleStatistic(StatisticBase):
|
|
||||||
result: Union[list[people_classes.DesignerPublic], list[people_classes.ArtistPublic]]
|
|
||||||
|
|
||||||
model_config = {
|
model_config = {
|
||||||
'validate_assignment':True
|
'validate_assignment':True
|
||||||
}
|
}
|
||||||
14
src/main.py
14
src/main.py
|
|
@ -236,8 +236,14 @@ def get_winrate_over_time(player_name: str | None = None, day_step: int = 1, ses
|
||||||
return statistic_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
|
|
||||||
@app.get('/statistics/most_bought_designers', response_model=statistic_classes.PeopleStatistic)
|
@app.get('/statistics/most_bought_designer', response_model=statistic_classes.GamesStatistic)
|
||||||
def get_most_bought_from_designers(top_amount: int = 10, session=Depends(get_session)):
|
def get_most_bought_from_designer(query: BoardgameFilterParams = Depends(), session: Session=Depends(get_session)):
|
||||||
statistics_to_return = statistic_creator.get_most_bought_designers(session, top_amount)
|
statistic_to_return = statistic_creator.get_most_bought_designer(session, query)
|
||||||
|
|
||||||
return statistics_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
|
@app.get('/statistics/most_bought_artist', response_model=statistic_classes.GamesStatistic)
|
||||||
|
def get_most_bought_from_artist(query: BoardgameFilterParams = Depends(), session: Session=Depends(get_session)):
|
||||||
|
statistic_to_return = statistic_creator.get_most_bought_artist(session, query)
|
||||||
|
|
||||||
|
return statistic_to_return
|
||||||
|
|
@ -138,6 +138,10 @@ def get_all_designers(session: Session) -> list[people_classes.Designer]:
|
||||||
designers_from_db = db_connection.get_all_designers(session)
|
designers_from_db = db_connection.get_all_designers(session)
|
||||||
return designers_from_db
|
return designers_from_db
|
||||||
|
|
||||||
|
def get_all_artists(session: Session) -> list[people_classes.Artist]:
|
||||||
|
artists_from_db = db_connection.get_all_artists(session)
|
||||||
|
return artists_from_db
|
||||||
|
|
||||||
def delete_database():
|
def delete_database():
|
||||||
db_connection.delete_database()
|
db_connection.delete_database()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,11 +142,17 @@ def get_multiple_designers(session: Session, designer_ids: list[int]) -> list[pe
|
||||||
return designers, missing_designer_ids
|
return designers, missing_designer_ids
|
||||||
|
|
||||||
def get_all_designers(session: Session) -> list[people_classes.Designer]:
|
def get_all_designers(session: Session) -> list[people_classes.Designer]:
|
||||||
statement = statement = select(people_classes.Designer)
|
statement = select(people_classes.Designer)
|
||||||
results = session.exec(statement)
|
results = session.exec(statement)
|
||||||
designers = results.all()
|
designers = results.all()
|
||||||
return designers
|
return designers
|
||||||
|
|
||||||
|
def get_all_artists(session: Session) -> list[people_classes.Artist]:
|
||||||
|
statement = select(people_classes.Artist)
|
||||||
|
results = session.exec(statement)
|
||||||
|
artists = results.all()
|
||||||
|
return artists
|
||||||
|
|
||||||
def get_player(player_name: str, session: Session) -> player_classes.Player:
|
def get_player(player_name: str, session: Session) -> player_classes.Player:
|
||||||
statement = statement = select(player_classes.Player).where(player_classes.Player.name == player_name)
|
statement = statement = select(player_classes.Player).where(player_classes.Player.name == player_name)
|
||||||
results = session.exec(statement)
|
results = session.exec(statement)
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ def get_from_cache(argument_dict: dict):
|
||||||
else:
|
else:
|
||||||
return md5hash, None
|
return md5hash, None
|
||||||
|
|
||||||
def get_total_owned_games(session: Session, filtering_query: BoardgameFilterParams = None) -> statistic_classes.NumberStatistic:
|
def get_total_owned_games(session: Session, filtering_query: BoardgameFilterParams) -> statistic_classes.NumberStatistic:
|
||||||
|
|
||||||
statistic_name = 'Amount of games in owned collection'
|
statistic_name = 'Amount of games in owned collection'
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ def get_total_owned_games(session: Session, filtering_query: BoardgameFilterPara
|
||||||
return statistic_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
|
|
||||||
def get_total_owned_collection_cost(session: Session, filtering_query: BoardgameFilterParams = None) -> statistic_classes.NumberStatistic:
|
def get_total_owned_collection_cost(session: Session, filtering_query: BoardgameFilterParams) -> statistic_classes.NumberStatistic:
|
||||||
|
|
||||||
statistic_name = 'Total cost of the owned collection'
|
statistic_name = 'Total cost of the owned collection'
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ def get_total_owned_collection_cost(session: Session, filtering_query: Boardgame
|
||||||
return statistic_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
|
|
||||||
def get_amount_of_games_over_time(session: Session, filtering_query: BoardgameFilterParams = None, day_step: int = 1) -> statistic_classes.TimeLineStatistic:
|
def get_amount_of_games_over_time(session: Session, filtering_query: BoardgameFilterParams, day_step: int = 1) -> statistic_classes.TimeLineStatistic:
|
||||||
|
|
||||||
statistic_name = 'Amount of games in owned collection over time'
|
statistic_name = 'Amount of games in owned collection over time'
|
||||||
|
|
||||||
|
|
@ -172,7 +172,7 @@ def get_amount_of_games_played_per_year(session: Session, filtering_query: PlayF
|
||||||
|
|
||||||
return statistic_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
def get_most_expensive_games(session: Session, filtering_query: BoardgameFilterParams = None, top_amount: int = 10) -> statistic_classes.GamesStatistic:
|
def get_most_expensive_games(session: Session, filtering_query: BoardgameFilterParams, top_amount: int = 10) -> statistic_classes.GamesStatistic:
|
||||||
|
|
||||||
statistic_name = 'Most expensive games'
|
statistic_name = 'Most expensive games'
|
||||||
|
|
||||||
|
|
@ -207,7 +207,7 @@ def get_most_expensive_games(session: Session, filtering_query: BoardgameFilterP
|
||||||
|
|
||||||
return statistic_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
def get_cheapest_per_play_games(session: Session, filtering_query: BoardgameFilterParams = None, top_amount: int = 10) -> statistic_classes.GamesStatistic:
|
def get_cheapest_per_play_games(session: Session, filtering_query: BoardgameFilterParams, top_amount: int = 10) -> statistic_classes.GamesStatistic:
|
||||||
statistic_name = 'Cheapest plays'
|
statistic_name = 'Cheapest plays'
|
||||||
|
|
||||||
md5hash, cached_statistic = get_from_cache({**locals()})
|
md5hash, cached_statistic = get_from_cache({**locals()})
|
||||||
|
|
@ -245,7 +245,7 @@ def get_cheapest_per_play_games(session: Session, filtering_query: BoardgameFilt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_shelf_of_shame(session: Session, filtering_query: BoardgameFilterParams = None) -> statistic_classes.GamesStatistic:
|
def get_shelf_of_shame(session: Session, filtering_query: BoardgameFilterParams) -> statistic_classes.GamesStatistic:
|
||||||
|
|
||||||
statistic_name = "Shelf of Shame"
|
statistic_name = "Shelf of Shame"
|
||||||
|
|
||||||
|
|
@ -390,7 +390,7 @@ def get_winrate_over_time(session: Session, player_name: str | None = None, day_
|
||||||
return dict_to_return
|
return dict_to_return
|
||||||
|
|
||||||
|
|
||||||
def get_most_bought_designers(session: Session, top_amount: int= 10) -> statistic_classes.PeopleStatistic:
|
def get_most_bought_designer(session: Session, filtering_query: BoardgameFilterParams) -> statistic_classes.GamesStatistic:
|
||||||
statistic_name = 'Designer most bought from'
|
statistic_name = 'Designer most bought from'
|
||||||
|
|
||||||
md5hash, cached_statistic = get_from_cache({**locals()})
|
md5hash, cached_statistic = get_from_cache({**locals()})
|
||||||
|
|
@ -400,24 +400,61 @@ def get_most_bought_designers(session: Session, top_amount: int= 10) -> statisti
|
||||||
|
|
||||||
all_designers = data_connection.get_all_designers(session)
|
all_designers = data_connection.get_all_designers(session)
|
||||||
|
|
||||||
all_designers.sort(key=lambda x: len(list(filter(lambda y: y.owned_info != None,x.designed_boardgames))), reverse=True)
|
all_designers.sort(key=lambda x: len(list(filter(lambda y: y.owned_info != None,filtering_query.do_filtering(x.designed_boardgames)))), reverse=True)
|
||||||
|
|
||||||
top_bought_designers = all_designers[0:top_amount]
|
top_bought_designer = all_designers[0]
|
||||||
|
|
||||||
temp_top_bought_designers = []
|
designed_owned_boardgames = list(filter(lambda x: x.owned_info != None, top_bought_designer.designed_boardgames))
|
||||||
|
|
||||||
for designer in top_bought_designers:
|
|
||||||
designed_owned_boardgames = list(filter(lambda x: x.owned_info != None, designer.designed_boardgames))
|
|
||||||
temp_top_bought_designers.append(people_classes.Designer(id=designer.id, name=designer.name, designed_boardgames=designed_owned_boardgames))
|
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for boardgame in designed_owned_boardgames:
|
||||||
|
result[boardgame.id] = top_bought_designer.name
|
||||||
|
|
||||||
|
|
||||||
statistic_dict = {
|
statistic_dict = {
|
||||||
'name': statistic_name,
|
'name': statistic_name,
|
||||||
'result': temp_top_bought_designers
|
'games': designed_owned_boardgames,
|
||||||
|
'result': result
|
||||||
}
|
}
|
||||||
|
|
||||||
statistic_to_return = statistic_classes.PeopleStatistic.model_validate(statistic_dict)
|
statistic_to_return = statistic_classes.GamesStatistic.model_validate(statistic_dict)
|
||||||
|
|
||||||
cached_statistics[md5hash] = statistic_to_return
|
cached_statistics[md5hash] = statistic_to_return
|
||||||
|
|
||||||
return statistic_to_return
|
return statistic_to_return
|
||||||
|
|
||||||
|
|
||||||
|
def get_most_bought_artist(session: Session, filtering_query: BoardgameFilterParams) -> statistic_classes.GamesStatistic:
|
||||||
|
statistic_name = 'Artist most bought from'
|
||||||
|
|
||||||
|
md5hash, cached_statistic = get_from_cache({**locals()})
|
||||||
|
|
||||||
|
if cached_statistic != None:
|
||||||
|
return cached_statistic
|
||||||
|
|
||||||
|
all_artists = data_connection.get_all_artists(session)
|
||||||
|
|
||||||
|
all_artists.sort(key=lambda x: len(list(filter(lambda y: y.owned_info != None,filtering_query.do_filtering(x.drawn_boardgames)))), reverse=True)
|
||||||
|
|
||||||
|
top_bought_artist = all_artists[0]
|
||||||
|
|
||||||
|
drawn_owned_boardgames = list(filter(lambda x: x.owned_info != None, top_bought_artist.drawn_boardgames))
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for boardgame in drawn_owned_boardgames:
|
||||||
|
result[boardgame.id] = top_bought_artist.name
|
||||||
|
|
||||||
|
|
||||||
|
statistic_dict = {
|
||||||
|
'name': statistic_name,
|
||||||
|
'games': drawn_owned_boardgames,
|
||||||
|
'result': result
|
||||||
|
}
|
||||||
|
|
||||||
|
statistic_to_return = statistic_classes.GamesStatistic.model_validate(statistic_dict)
|
||||||
|
|
||||||
|
cached_statistics[md5hash] = statistic_to_return
|
||||||
|
|
||||||
|
return statistic_to_return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue