fix: auto-initialize RefractorCardState in evaluate-game #178
@ -6,6 +6,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from ..db_engine import model_to_dict
|
from ..db_engine import model_to_dict
|
||||||
from ..dependencies import oauth2_scheme, valid_token
|
from ..dependencies import oauth2_scheme, valid_token
|
||||||
|
from ..services.refractor_init import initialize_card_refractor, _determine_card_type
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -302,8 +303,9 @@ async def evaluate_game(game_id: int, token: str = Depends(oauth2_scheme)):
|
|||||||
|
|
||||||
Finds all unique (player_id, team_id) pairs from the game's StratPlay rows,
|
Finds all unique (player_id, team_id) pairs from the game's StratPlay rows,
|
||||||
then for each pair that has a RefractorCardState, re-computes the refractor
|
then for each pair that has a RefractorCardState, re-computes the refractor
|
||||||
tier. Pairs without a state row are silently skipped. Per-player errors are
|
tier. Pairs without a state row are auto-initialized on-the-fly via
|
||||||
logged but do not abort the batch.
|
initialize_card_refractor (idempotent). Per-player errors are logged but
|
||||||
|
do not abort the batch.
|
||||||
"""
|
"""
|
||||||
if not valid_token(token):
|
if not valid_token(token):
|
||||||
logging.warning("Bad Token: [REDACTED]")
|
logging.warning("Bad Token: [REDACTED]")
|
||||||
@ -334,7 +336,17 @@ async def evaluate_game(game_id: int, token: str = Depends(oauth2_scheme)):
|
|||||||
& (RefractorCardState.team_id == team_id)
|
& (RefractorCardState.team_id == team_id)
|
||||||
)
|
)
|
||||||
if state is None:
|
if state is None:
|
||||||
continue
|
try:
|
||||||
|
player = Player.get_by_id(player_id)
|
||||||
|
card_type = _determine_card_type(player)
|
||||||
|
state = initialize_card_refractor(player_id, team_id, card_type)
|
||||||
|
except Exception:
|
||||||
|
logger.warning(
|
||||||
|
f"Refractor auto-init failed for player={player_id} "
|
||||||
|
f"team={team_id} — skipping"
|
||||||
|
)
|
||||||
|
if state is None:
|
||||||
|
continue
|
||||||
|
|
||||||
old_tier = state.current_tier
|
old_tier = state.current_tier
|
||||||
# Use dry_run=True so that current_tier is NOT written here.
|
# Use dry_run=True so that current_tier is NOT written here.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user