Fixed bug where 'most bought from designer' statistic included not owned games
This commit is contained in:
parent
4965b48e9e
commit
6bed246702
1 changed files with 9 additions and 3 deletions
|
|
@ -5,7 +5,7 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from src.classes import statistic_classes
|
from src.classes import statistic_classes, people_classes
|
||||||
from src.modules import data_connection
|
from src.modules import data_connection
|
||||||
from datetime import date, timedelta, datetime
|
from datetime import date, timedelta, datetime
|
||||||
from sqlmodel import Session
|
from sqlmodel import Session
|
||||||
|
|
@ -400,14 +400,20 @@ 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(x.designed_boardgames), reverse=True)
|
all_designers.sort(key=lambda x: len(list(filter(lambda y: y.owned_info != None,x.designed_boardgames))), reverse=True)
|
||||||
|
|
||||||
top_bought_designers = all_designers[0:top_amount]
|
top_bought_designers = all_designers[0:top_amount]
|
||||||
|
|
||||||
|
temp_top_bought_designers = []
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
statistic_dict = {
|
statistic_dict = {
|
||||||
'name': statistic_name,
|
'name': statistic_name,
|
||||||
'result': top_bought_designers
|
'result': temp_top_bought_designers
|
||||||
}
|
}
|
||||||
|
|
||||||
statistic_to_return = statistic_classes.PeopleStatistic.model_validate(statistic_dict)
|
statistic_to_return = statistic_classes.PeopleStatistic.model_validate(statistic_dict)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue