fix: address review feedback (#207)
- Move all lazy imports in refractor_service.py to module top level (CLAUDE.md: no lazy imports; no circular import risk exists) - Restore animated_url in evaluate_game tier-up response for T3/T4 (regression from stale branch base predating PR #208 merge) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e8b1091d8a
commit
c61e7c1bd1
@ -1,5 +1,7 @@
|
||||
from datetime import date
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
import logging
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from ..db_engine import model_to_dict, BattingCard, PitchingCard
|
||||
@ -424,7 +426,16 @@ async def evaluate_game(game_id: int, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
variants_created = result.get("variants_created") or []
|
||||
if variants_created:
|
||||
tier_up_entry["variant_created"] = variants_created[-1]
|
||||
variant_num = variants_created[-1]
|
||||
tier_up_entry["variant_created"] = variant_num
|
||||
card_type = state.track.card_type if state.track else None
|
||||
if new_tier >= 3 and variant_num and card_type:
|
||||
d = date.today().strftime("%Y-%m-%d")
|
||||
api_base = os.environ.get("API_BASE_URL", "").rstrip("/")
|
||||
tier_up_entry["animated_url"] = (
|
||||
f"{api_base}/api/v2/players/{player_id}/{card_type}card"
|
||||
f"/{d}/{variant_num}/animated"
|
||||
)
|
||||
|
||||
tier_ups.append(tier_up_entry)
|
||||
|
||||
|
||||
@ -8,6 +8,10 @@ same boost orchestration logic without requiring HTTP round-trips in tests.
|
||||
import logging
|
||||
import os
|
||||
|
||||
from app.db_engine import RefractorCardState, BattingCard, PitchingCard
|
||||
from app.services.refractor_boost import apply_tier_boost, compute_variant_hash
|
||||
from app.services.refractor_evaluator import evaluate_card
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -45,7 +49,7 @@ def ensure_variant_cards(
|
||||
apply_tier_boost for each newly created variant.
|
||||
"""
|
||||
if _state_model is None:
|
||||
from app.db_engine import RefractorCardState as _state_model # noqa: PLC0415
|
||||
_state_model = RefractorCardState
|
||||
|
||||
state = _state_model.get_or_none(
|
||||
(_state_model.player_id == player_id) & (_state_model.team_id == team_id)
|
||||
@ -88,16 +92,8 @@ def ensure_variant_cards(
|
||||
"boost_results": [],
|
||||
}
|
||||
|
||||
from app.services.refractor_boost import ( # noqa: PLC0415
|
||||
apply_tier_boost,
|
||||
compute_variant_hash,
|
||||
)
|
||||
|
||||
is_batter = resolved_card_type == "batter"
|
||||
if is_batter:
|
||||
from app.db_engine import BattingCard as CardModel # noqa: PLC0415
|
||||
else:
|
||||
from app.db_engine import PitchingCard as CardModel # noqa: PLC0415
|
||||
CardModel = BattingCard if is_batter else PitchingCard
|
||||
|
||||
variants_created = []
|
||||
boost_results = []
|
||||
@ -169,8 +165,6 @@ def evaluate_and_boost(
|
||||
Raises:
|
||||
ValueError: If no RefractorCardState exists for (player_id, team_id).
|
||||
"""
|
||||
from app.services.refractor_evaluator import evaluate_card # noqa: PLC0415
|
||||
|
||||
eval_kwargs: dict = {"dry_run": True}
|
||||
if _state_model is not None:
|
||||
eval_kwargs["_state_model"] = _state_model
|
||||
|
||||
Loading…
Reference in New Issue
Block a user