Added playercount votes to boardgames

This commit is contained in:
Yarne Coppens 2024-10-14 18:33:24 +02:00
parent e70481b664
commit 9f5aa4a927
2 changed files with 40 additions and 1 deletions

View file

@ -15,6 +15,19 @@ class BoardgameType(Enum):
PREORDEREDBOARDGAME = 'preorderedboargame' PREORDEREDBOARDGAME = 'preorderedboargame'
PREORDEREDBOARDGAMEEXPANSION = 'preorderedboargameexpansion' PREORDEREDBOARDGAMEEXPANSION = 'preorderedboargameexpansion'
class PlayerCountVotesBase(SQLModel):
playercount: str
best: int
recommended: int
not_recommended: int
class PlayerCountVotes(PlayerCountVotesBase, table=True):
id: int = Field(primary_key=True)
boardgame_id: int = Field(default=None, foreign_key="boardgame.id")
boardgame: "BoardGame" = Relationship(back_populates='playercount_votes')
class PlayerCountVotesPublic(PlayerCountVotesBase):
pass
class BoardGameBase(SQLModel): class BoardGameBase(SQLModel):
name: str name: str
@ -49,6 +62,8 @@ class BoardGame(BoardGameBase, table=True):
plays: list["Play"] = Relationship(back_populates='boardgame') plays: list["Play"] = Relationship(back_populates='boardgame')
playercount_votes: list[PlayerCountVotes] = Relationship(back_populates="boardgame")
model_config = { model_config = {
'arbitrary_types_allowed':True 'arbitrary_types_allowed':True
} }
@ -61,6 +76,7 @@ class BoardGamePublic(BoardGameBase):
owned_info: Optional["OwnedInfoPublicNoGame"] owned_info: Optional["OwnedInfoPublicNoGame"]
wishlist_info: Optional["WishlistInfoPublicNoGame"] wishlist_info: Optional["WishlistInfoPublicNoGame"]
preordered_info: Optional["PreorderedInfoPublicNoGame"] preordered_info: Optional["PreorderedInfoPublicNoGame"]
playercount_votes: list[PlayerCountVotesPublic]
plays: list["PlayPublicNoGame"] plays: list["PlayPublicNoGame"]
class BoardGamePublicNoPlays(BoardGameBase): class BoardGamePublicNoPlays(BoardGameBase):
@ -71,6 +87,7 @@ class BoardGamePublicNoPlays(BoardGameBase):
owned_info: Optional["OwnedInfoPublicNoGame"] owned_info: Optional["OwnedInfoPublicNoGame"]
wishlist_info: Optional["WishlistInfoPublicNoGame"] wishlist_info: Optional["WishlistInfoPublicNoGame"]
preordered_info: Optional["PreorderedInfoPublicNoGame"] preordered_info: Optional["PreorderedInfoPublicNoGame"]
playercount_votes: list[PlayerCountVotesPublic]
class ExpansionInfo(SQLModel, table=True): class ExpansionInfo(SQLModel, table=True):

View file

@ -108,6 +108,27 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> boardgame_classes.Boa
else: else:
thumbnail_url = "https://cf.geekdo-images.com/zxVVmggfpHJpmnJY9j-k1w__thumb/img/Tse35rOD2Z8Pv9EOUj4TfeMuNew=/fit-in/200x150/filters:strip_icc()/pic1657689.jpg" thumbnail_url = "https://cf.geekdo-images.com/zxVVmggfpHJpmnJY9j-k1w__thumb/img/Tse35rOD2Z8Pv9EOUj4TfeMuNew=/fit-in/200x150/filters:strip_icc()/pic1657689.jpg"
playercount_poll = boardgame_xml.find('poll')
playercount_votes_list = []
for playercount_vote_results in playercount_poll.findall('results'):
playercount = playercount_vote_results.get('numplayers')
best_votes = 0
recommended_votes = 0
not_recommended_votes = 0
for playercount_vote_result in playercount_vote_results:
if playercount_vote_result.get('value') == "Best":
best_votes = playercount_vote_result.get('numvotes')
elif playercount_vote_result.get('value') == "Recommended":
recommended_votes = playercount_vote_result.get('numvotes')
elif playercount_vote_result.get('value') == "Not Recommended":
not_recommended_votes = playercount_vote_result.get('numvotes')
playercount_votes = boardgame_classes.PlayerCountVotes(boardgame_id=int(boardgame_xml.get('id')), playercount=playercount, best=best_votes, recommended=recommended_votes, not_recommended=not_recommended_votes)
playercount_votes_list.append(playercount_votes)
boardgame_dict = { boardgame_dict = {
"id" : int(boardgame_xml.get('id')), "id" : int(boardgame_xml.get('id')),
@ -123,7 +144,8 @@ def convert_xml_to_boardgame(boardgame_xml: ET.Element) -> boardgame_classes.Boa
"max_playing_time" : int(boardgame_xml.find('maxplaytime').get('value')), "max_playing_time" : int(boardgame_xml.find('maxplaytime').get('value')),
"min_age" : int(boardgame_xml.find('minage').get('value')), "min_age" : int(boardgame_xml.find('minage').get('value')),
"designers" : designers, "designers" : designers,
"artists" : artists "artists" : artists,
"playercount_votes" : playercount_votes_list
} }
boardgame = boardgame_classes.BoardGame(**boardgame_dict) boardgame = boardgame_classes.BoardGame(**boardgame_dict)