RPU v2, promo/bank система, админка, оптимизации
— RPU v2: бюджет удачи, потолок (ceiling), комбек после проигрышей, hot/cold анализ, интеграция с promo-фазами — Bank API: mock-банк для карты (депозит/вывод с балансом 1000₽) — Promo-сервис: автогенерация промокодов каждый час, типы (card_to_site, luck_boost, ceiling_boost, free_case, reset_streak) — Promo-фазы: LUCKY/NEUTRAL/UNLUCKY, переключение каждые 1-6ч — Admin: история транзакций (user_history), управление промокодами, управление promo-фазами, API фильтров/коллекций, RPU info — Database: WAL mode, новые поля RPU v2, TransactionLog, карточный баланс, статистики (streaks, ceiling, budget) — Frontend: /deposit, /promo/activate, /withdraw, /card-balance, /online-count, /rpu-info, lifespan вместо startup event — UI: user_history.html, улучшения профиля, кейсов, навигации — Cases: обновление cases.json (1892 строки новых данных) — Achievements: кэш коллекций, оптимизация is_custom проверок — Sounds: дополнительные звуковые эффекты — Upgrade: интеграция с RPU (множители, streaks) — .gitignore: исключены .db, .bak, __pycache__
This commit is contained in:
+47
-7
@@ -4,16 +4,22 @@ from datetime import datetime
|
||||
from sqlalchemy.orm import Session
|
||||
from database import User, UpgradeRPU, Upgrade
|
||||
|
||||
MAX_WIN_STREAK = 3
|
||||
MAX_LOSE_STREAK = 5
|
||||
|
||||
|
||||
def get_upgrade_rpu(db: Session, user_id: int) -> UpgradeRPU:
|
||||
"""Получает или создает настройки РПУ апгрейдов"""
|
||||
rpu = db.query(UpgradeRPU).filter(UpgradeRPU.user_id == user_id).first()
|
||||
if not rpu:
|
||||
rpu = UpgradeRPU(user_id=user_id)
|
||||
db.add(rpu)
|
||||
db.commit()
|
||||
from rpu import _rpu_commit_or_flush
|
||||
_rpu_commit_or_flush(db)
|
||||
db.refresh(rpu)
|
||||
return rpu
|
||||
|
||||
|
||||
def calculate_upgrade_probability(input_price: float, target_price: float) -> float:
|
||||
if input_price <= 0 or target_price <= 0:
|
||||
return 50.0
|
||||
@@ -31,16 +37,28 @@ def get_adjusted_upgrade_probability(db: Session, user_id: int, base_probability
|
||||
return -1.0
|
||||
|
||||
rpu = get_upgrade_rpu(db, user_id)
|
||||
|
||||
# Базовая корректировка от множителя
|
||||
adjusted = base_probability * rpu.upgrade_multiplier
|
||||
|
||||
# Корректировка на серии
|
||||
if rpu.current_win_streak >= MAX_WIN_STREAK:
|
||||
# Слишком много побед подряд — режем шанс
|
||||
penalty = (rpu.current_win_streak - MAX_WIN_STREAK + 1) * 0.15
|
||||
adjusted *= (1.0 - penalty)
|
||||
elif rpu.current_lose_streak >= MAX_LOSE_STREAK:
|
||||
# Слишком много поражений подряд — повышаем шанс
|
||||
boost = (rpu.current_lose_streak - MAX_LOSE_STREAK + 1) * 0.2
|
||||
adjusted *= (1.0 + boost)
|
||||
|
||||
return max(1.0, min(75.0, adjusted))
|
||||
|
||||
|
||||
def spin_upgrade_wheel(success_probability: float) -> tuple[bool, float, int, float]:
|
||||
raw_angle = random.uniform(0, 360)
|
||||
|
||||
half_green = (success_probability / 100) * 180
|
||||
|
||||
# Green zone: [180 - half_green, 180 + half_green] — centered at 180° (bottom)
|
||||
# Матчим CSS конусный градиент: from calc(180deg - prob * 3.6deg / 2)
|
||||
success = 180 - half_green <= raw_angle <= 180 + half_green
|
||||
|
||||
margin = max(3, half_green * 0.12)
|
||||
@@ -73,19 +91,41 @@ def spin_upgrade_wheel(success_probability: float) -> tuple[bool, float, int, fl
|
||||
|
||||
return success, final_angle, rotations, raw_angle
|
||||
|
||||
|
||||
def update_upgrade_stats(db: Session, user_id: int, success: bool, input_price: float):
|
||||
rpu = get_upgrade_rpu(db, user_id)
|
||||
rpu.total_attempts += 1
|
||||
|
||||
if success:
|
||||
rpu.total_success += 1
|
||||
rpu.current_win_streak += 1
|
||||
rpu.current_lose_streak = 0
|
||||
if rpu.current_win_streak > rpu.best_win_streak:
|
||||
rpu.best_win_streak = rpu.current_win_streak
|
||||
else:
|
||||
rpu.total_spent_value += input_price
|
||||
rpu.current_lose_streak += 1
|
||||
rpu.current_win_streak = 0
|
||||
if rpu.current_lose_streak > rpu.worst_lose_streak:
|
||||
rpu.worst_lose_streak = rpu.current_lose_streak
|
||||
|
||||
if rpu.auto_adjust and rpu.total_attempts >= 15:
|
||||
# Авто-подкрутка
|
||||
if rpu.auto_adjust and rpu.total_attempts >= 10:
|
||||
# Анализ серии побед
|
||||
if rpu.current_win_streak >= MAX_WIN_STREAK:
|
||||
rpu.upgrade_multiplier = max(0.3, rpu.upgrade_multiplier - 0.15)
|
||||
|
||||
# Анализ серии поражений
|
||||
if rpu.current_lose_streak >= MAX_LOSE_STREAK:
|
||||
rpu.upgrade_multiplier = min(2.5, rpu.upgrade_multiplier + 0.2)
|
||||
|
||||
# Общий процент побед
|
||||
rate = rpu.total_success / rpu.total_attempts
|
||||
if rate < 0.2:
|
||||
rpu.upgrade_multiplier = min(2.0, rpu.upgrade_multiplier + 0.1)
|
||||
rpu.upgrade_multiplier = min(2.5, rpu.upgrade_multiplier + 0.1)
|
||||
elif rate > 0.6:
|
||||
rpu.upgrade_multiplier = max(0.5, rpu.upgrade_multiplier - 0.1)
|
||||
rpu.upgrade_multiplier = max(0.3, rpu.upgrade_multiplier - 0.1)
|
||||
|
||||
from rpu import _rpu_commit_or_flush
|
||||
_rpu_commit_or_flush(db)
|
||||
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user