[Eva] Ева, прочитай .gitignore #33

Merged
Drobysh merged 7 commits from eva/chat-c3088d-backend into main 2026-10-13 11:23:16 +00:00
+11 -24
View File
@@ -35,15 +35,6 @@ GAMES = ["wordsearch", "choose", "sentence", "bubbles"]
# Множитель игры дня
FEATURED_MULTIPLIER = 1.5
# Базовая ставка: 1 звезда = 20 XP
POINTS_PER_STAR = 20
# Максимум звёзд за уровень
MAX_STARS = 5
# Минимум звёзд за пройденный уровень
MIN_STARS = 1
# Коэффициенты баланса (настроить после первых 1000 сессий)
# Применяются к base_points ДО множителя игры дня.
GAME_XP_COEF: dict[str, float] = {
@@ -192,7 +183,7 @@ async def award_xp(
conn,
user_id: int,
game: str,
stars: int,
points: int,
) -> dict:
"""
Единая функция начисления опыта.
@@ -201,11 +192,10 @@ async def award_xp(
conn: asyncpg connection (уже acquired)
user_id: telegram_id (может быть отрицательным для Pleily)
game: 'wordsearch' | 'choose' | 'sentence' | 'bubbles'
stars: 1..5
points: готовые очки за уровень (20–110), формула считается до вызова
Returns:
{
"stars": int,
"base_points": int,
"multiplier": float,
"points": int,
@@ -219,18 +209,16 @@ async def award_xp(
}
"""
# 1. Валидация
stars = max(MIN_STARS, min(MAX_STARS, int(stars)))
if game not in GAME_XP_COEF:
raise ValueError(f"Unknown game: {game}")
# 2. База
base = stars * POINTS_PER_STAR
base = int(round(base * GAME_XP_COEF.get(game, 1.0)))
# 2. База с коэффициентом игры (для баланса)
base_points = int(round(points * GAME_XP_COEF.get(game, 1.0)))
# 3. Множитель игры дня
is_featured = (game == featured_game())
multiplier = FEATURED_MULTIPLIER if is_featured else 1.0
points = int(round(base * multiplier))
final_points = int(round(base_points * multiplier))
# 4. Читаем текущий total_xp
row = await conn.fetchrow(
@@ -259,11 +247,11 @@ async def award_xp(
INSERT INTO xp_log (user_id, game, stars, base_points, multiplier, points)
VALUES ($1, $2, $3, $4, $5, $6)
""",
user_id, game, stars, base, multiplier, points,
user_id, game, 0, base_points, multiplier, final_points,
)
# 6. Обновляем user_profile
new_total = old_total + points
new_total = old_total + final_points
await conn.execute(
"""
UPDATE user_profile
@@ -272,7 +260,7 @@ async def award_xp(
updated_at = NOW()
WHERE user_id = $1
""",
user_id, points,
user_id, final_points,
)
# 7. Считаем новый уровень
@@ -287,14 +275,13 @@ async def award_xp(
}
logger.info(
"[xp] user=%s level_up %s → %s (%s), +%s xp",
user_id, old_level, new_level, rank_key, points,
user_id, old_level, new_level, rank_key, final_points,
)
return {
"stars": stars,
"base_points": base,
"base_points": base_points,
"multiplier": multiplier,
"points": points,
"points": final_points,
"featured": is_featured,
"level_up": level_up,
"total_xp": new_total,