Add events

This commit is contained in:
2025-12-15 03:22:29 +07:00
parent 1a882fb2e0
commit 4239ea8516
31 changed files with 7288 additions and 75 deletions

View File

@@ -1,3 +1,6 @@
from app.models import Event, EventType
class PointsService:
"""Service for calculating points and penalties"""
@@ -17,39 +20,77 @@ class PointsService:
}
MAX_DROP_PENALTY = 50
# Event point multipliers
EVENT_MULTIPLIERS = {
EventType.GOLDEN_HOUR.value: 1.5,
EventType.DOUBLE_RISK.value: 0.5,
EventType.JACKPOT.value: 3.0,
EventType.REMATCH.value: 0.5,
}
def calculate_completion_points(
self,
base_points: int,
current_streak: int
) -> tuple[int, int]:
current_streak: int,
event: Event | None = None,
) -> tuple[int, int, int]:
"""
Calculate points earned for completing a challenge.
Args:
base_points: Base points for the challenge
current_streak: Current streak before this completion
event: Active event (optional)
Returns:
Tuple of (total_points, streak_bonus)
Tuple of (total_points, streak_bonus, event_bonus)
"""
multiplier = self.STREAK_MULTIPLIERS.get(
# Apply event multiplier first
event_multiplier = 1.0
if event:
event_multiplier = self.EVENT_MULTIPLIERS.get(event.type, 1.0)
adjusted_base = int(base_points * event_multiplier)
event_bonus = adjusted_base - base_points
# Then apply streak bonus
streak_multiplier = self.STREAK_MULTIPLIERS.get(
current_streak,
self.MAX_STREAK_MULTIPLIER
)
bonus = int(base_points * multiplier)
return base_points + bonus, bonus
streak_bonus = int(adjusted_base * streak_multiplier)
def calculate_drop_penalty(self, consecutive_drops: int) -> int:
total_points = adjusted_base + streak_bonus
return total_points, streak_bonus, event_bonus
def calculate_drop_penalty(
self,
consecutive_drops: int,
event: Event | None = None
) -> int:
"""
Calculate penalty for dropping a challenge.
Args:
consecutive_drops: Number of drops since last completion
event: Active event (optional)
Returns:
Penalty points to subtract
"""
# Double risk event = free drops
if event and event.type == EventType.DOUBLE_RISK.value:
return 0
return self.DROP_PENALTIES.get(
consecutive_drops,
self.MAX_DROP_PENALTY
)
def apply_event_multiplier(self, base_points: int, event: Event | None) -> int:
"""Apply event multiplier to points"""
if not event:
return base_points
multiplier = self.EVENT_MULTIPLIERS.get(event.type, 1.0)
return int(base_points * multiplier)