Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undo type ignores #384

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ark_nova_stats/api/gql/types/game_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def submit_game_logs(
f"Log is invalid: there must be exactly one table_id per game log, found: {table_ids}"
)

log = GameLogModel(bga_table_id=list(table_ids)[0], log=args["logs"]) # type: ignore

log = GameLogModel(bga_table_id=list(table_ids)[0], log=args["logs"])
if app.config["TESTING"] == True:
log.id = 1
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ def upgrade():
parsed_log = BGAGameLog(**json.loads(log_model.log))
for player in parsed_log.data.players:
if player.id not in players:
players[player.id] = UserModel( # type: ignore
players[player.id] = UserModel(
bga_id=player.id, name=player.name, avatar=player.avatar
)
session.add(players[player.id])

session.add(
GameParticipationModel( # type: ignore
GameParticipationModel(
user=players[player.id],
color=player.color,
game_log_id=parsed_log.data.logs[0].table_id,
Expand Down
26 changes: 12 additions & 14 deletions ark_nova_stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ark_nova_stats.config import db


class GameParticipation(db.Model): # type: ignore
class GameParticipation(db.Model):
__tablename__ = "game_participations"
user_id: Mapped[int] = mapped_column(ForeignKey("users.bga_id"), primary_key=True)
game_log_id: Mapped[int] = mapped_column(
Expand All @@ -25,7 +25,7 @@ class GameParticipation(db.Model): # type: ignore
game_log: Mapped["GameLog"] = relationship(back_populates="user_participations")


class GameLog(db.Model): # type: ignore
class GameLog(db.Model):
__tablename__ = "game_logs"

id: Mapped[int] = mapped_column(primary_key=True)
Expand Down Expand Up @@ -54,7 +54,7 @@ class GameLog(db.Model): # type: ignore

card_plays: Mapped[list["CardPlay"]] = relationship(back_populates="game_log")

def create_related_objects(self, parsed_logs: ParsedGameLog) -> db.Model: # type: ignore
def create_related_objects(self, parsed_logs: ParsedGameLog) -> db.Model:
# Add users if not present.
present_users = User.query.filter(
User.bga_id.in_([user.id for user in parsed_logs.data.players])
Expand All @@ -67,7 +67,7 @@ def create_related_objects(self, parsed_logs: ParsedGameLog) -> db.Model: # typ
]

for user in users_to_create:
bga_id_to_user[user.id] = User( # type: ignore
bga_id_to_user[user.id] = User(
bga_id=user.id,
name=user.name,
avatar=user.avatar,
Expand All @@ -77,7 +77,7 @@ def create_related_objects(self, parsed_logs: ParsedGameLog) -> db.Model: # typ
# Now create a game participation for each user.
for bga_user in parsed_logs.data.players:
log_user = next(u for u in parsed_logs.data.players if u.id == bga_user.id)
yield GameParticipation( # type: ignore
yield GameParticipation(
user=bga_id_to_user[bga_user.id],
color=log_user.color,
game_log=self,
Expand All @@ -86,32 +86,30 @@ def create_related_objects(self, parsed_logs: ParsedGameLog) -> db.Model: # typ
for c in self.create_card_and_plays(parsed_logs):
yield c

def create_card_and_plays(self, parsed_logs: ParsedGameLog) -> db.Model: # type: ignore
def create_card_and_plays(self, parsed_logs: ParsedGameLog) -> db.Model:
cards = {}
# Now create a card & card play.
for play in parsed_logs.data.card_plays:
if play.card.id not in cards:
# Check to see if it exists.
find_card = Card.query.where(Card.bga_id == play.card.id).limit(1).all()
if not find_card:
card = Card( # type: ignore
name=play.card.name, bga_id=play.card.id
)
card = Card(name=play.card.name, bga_id=play.card.id)
yield card
else:
card = find_card[0]

cards[card.bga_id] = card

yield CardPlay( # type: ignore
yield CardPlay(
game_log=self,
card=cards[play.card.id],
user_id=play.player.id,
move=play.move,
)


class User(db.Model): # type: ignore
class User(db.Model):
__tablename__ = "users"

id: Mapped[int] = mapped_column(primary_key=True)
Expand Down Expand Up @@ -169,7 +167,7 @@ class GameLogArchiveType(enum.IntEnum):
RAW_BGA_JSONL = 1


class GameLogArchive(db.Model): # type: ignore
class GameLogArchive(db.Model):
__tablename__ = "game_log_archives"

id: Mapped[int] = mapped_column(primary_key=True)
Expand All @@ -189,7 +187,7 @@ class GameLogArchive(db.Model): # type: ignore
last_game_log: Mapped[GameLog] = relationship(back_populates="archives")


class Card(db.Model): # type: ignore
class Card(db.Model):
__tablename__ = "cards"

id: Mapped[int] = mapped_column(primary_key=True)
Expand Down Expand Up @@ -228,7 +226,7 @@ def recent_users(self) -> list["User"]:
return [cp.user for cp in self.recent_plays]


class CardPlay(db.Model): # type: ignore
class CardPlay(db.Model):
__tablename__ = "game_log_cards"

game_log_id: Mapped[int] = mapped_column(
Expand Down