from __future__ import annotations from dataclasses import dataclass SUPPORTED_COLLECTION_TYPES = {"team", "stadium", "match", "sticker", "memory"} COLLECTION_POINTS = { "team": 20, "stadium": 25, "match": 15, "sticker": 5, "memory": 10, } QUIZ_POINTS_BY_DIFFICULTY = { "easy": 10, "medium": 15, "hard": 25, } PREDICTION_PARTICIPATION_POINTS = 5 PREDICTION_OUTCOME_POINTS = 35 PREDICTION_EXACT_SCORE_POINTS = 80 GIANT_KILLING_BONUS_POINTS = 120 @dataclass(frozen=True) class PredictionScoreBreakdown: total: int participation_points: int outcome_points: int exact_score_points: int giant_killing_points: int predicted_outcome: str actual_outcome: str def collection_points(item_type: str) -> int: return COLLECTION_POINTS.get(item_type, 0) def quiz_points(difficulty: str, is_correct: bool) -> int: if not is_correct: return 0 return QUIZ_POINTS_BY_DIFFICULTY.get(difficulty.lower(), QUIZ_POINTS_BY_DIFFICULTY["medium"]) def outcome_from_score(home_score: int, away_score: int) -> str: if home_score > away_score: return "home" if away_score > home_score: return "away" return "draw" def score_prediction( *, predicted_home_score: int, predicted_away_score: int, giant_killing_pick: bool, actual_home_score: int, actual_away_score: int, actual_giant_killing: bool, ) -> PredictionScoreBreakdown: predicted_outcome = outcome_from_score(predicted_home_score, predicted_away_score) actual_outcome = outcome_from_score(actual_home_score, actual_away_score) participation = PREDICTION_PARTICIPATION_POINTS outcome_points = PREDICTION_OUTCOME_POINTS if predicted_outcome == actual_outcome else 0 exact_points = ( PREDICTION_EXACT_SCORE_POINTS if predicted_home_score == actual_home_score and predicted_away_score == actual_away_score else 0 ) giant_points = ( GIANT_KILLING_BONUS_POINTS if giant_killing_pick and actual_giant_killing and predicted_outcome == actual_outcome else 0 ) total = participation + outcome_points + exact_points + giant_points return PredictionScoreBreakdown( total=total, participation_points=participation, outcome_points=outcome_points, exact_score_points=exact_points, giant_killing_points=giant_points, predicted_outcome=predicted_outcome, actual_outcome=actual_outcome, )