Skip to content

Commit

Permalink
In Emu Cup archives, correctly skip logs that don't belong in archive (
Browse files Browse the repository at this point in the history
  • Loading branch information
shaldengeki authored Oct 1, 2024
1 parent 5b78874 commit 7d2fa4b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ark_nova_stats/worker/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ def __init__(
def archive_type(self) -> GameLogArchiveType:
raise NotImplementedError

def should_include_game_log(self, game_log: GameLog) -> bool:
return True

def process_game_log(self, game_log: GameLog) -> None:
if not self.should_include_game_log(game_log):
return

self.num_logs += 1
game_users: list[User] = game_log.users
self.users.update(set([u.name for u in game_users]))
Expand Down Expand Up @@ -377,6 +383,9 @@ def csv_field_names(self) -> list[str]:

def process_game_log(self, game_log: GameLog) -> None:
super(TopLevelStatsCsvArchiveCreator, self).process_game_log(game_log)
if not self.should_include_game_log(game_log):
return

rows: list[dict] = []
for user in game_log.users:
row = {k: None for k in self.csv_field_names}
Expand Down Expand Up @@ -499,3 +508,25 @@ def game_logs(self) -> "sqlalchemy.orm.query.Query[GameLog]":
return GameLog.query.where(
GameLog.bga_table_id.in_(EMU_CUP_GAME_TABLE_IDS)
).yield_per(10)

def should_include_game_log(self, game_log: GameLog) -> bool:
if not super().should_include_game_log(game_log):
return False

return bool(game_log.bga_table_id in EMU_CUP_GAME_TABLE_IDS)

def should_create_archive(self) -> bool:
if not super().should_create_archive():
return False

last_archive: Optional[GameLogArchive] = (
GameLogArchive.query.filter(
GameLogArchive.archive_type == self.archive_type
)
.order_by(desc(GameLogArchive.last_game_log_id))
.first()
)
if last_archive is None:
return True

return bool(max(EMU_CUP_GAME_TABLE_IDS) > last_archive.last_game_log.id)

0 comments on commit 7d2fa4b

Please sign in to comment.