Files
filwordspl-backend/services/waves.py
T

59 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Волновая структура филвордов.
Волна = 20 уровней. Волны бесконечные.
Размер сетки задаётся блоками глобальных уровней (совпадает с БД):
| Уровни | Размер |
|-----------|--------|
| 1–25 | 5×5 |
| 26–75 | 6×6 |
| 76–275 | 7×7 |
| 276+ | 8×8 |
"""
from __future__ import annotations
def wave_for_level(global_level: int) -> int:
"""Какая волна содержит этот глобальный уровень (1-based)."""
if global_level < 1:
return 1
return (global_level - 1) // 20 + 1
def level_in_wave(global_level: int) -> int:
"""Позиция уровня внутри волны (1..20)."""
return ((global_level - 1) % 20) + 1
def grid_size_for(global_level: int) -> int:
"""Размер сетки для глобального уровня (блоками: 25×5, 50×6, 200×7, 300×8)."""
if global_level <= 25:
return 5
if global_level <= 75:
return 6
if global_level <= 275:
return 7
return 8
def max_stars_for_wave() -> int:
"""Максимум звёзд за волну (20 уровней × 5 звёзд)."""
return 20 * 5
def wave_medal(stars_earned: int) -> str:
"""
Медаль волны по доле звёзд.
Пороги: gold >= 90%, silver >= 70%, bronze >= 50%, else 'none'.
"""
total = max_stars_for_wave()
pct = stars_earned / total if total > 0 else 0
if pct >= 0.90:
return "gold"
if pct >= 0.70:
return "silver"
if pct >= 0.50:
return "bronze"
return "none"