diff --git a/bot/main.py b/bot/main.py index 26effb4..9edf3e2 100644 --- a/bot/main.py +++ b/bot/main.py @@ -74,59 +74,81 @@ async def handle_webapp_data(message: types.Message): db.end_game(game_id) logger.info(f"Game {game_id} completed with {len(throws)} throws") - # Обновляем подсчет статистики + # Анализ комбинаций + combinations = {} + for throw in throws: + dice = sorted([throw['dice'][0], throw['dice'][1]]) + key = f"{dice[0]}-{dice[1]}" + combinations[key] = combinations.get(key, 0) + 1 + + # Сортируем комбинации по частоте + sorted_combinations = sorted( + combinations.items(), + key=lambda x: (-x[1], x[0]) # Сортировка по убыванию частоты, потом по комбинации + ) + + # Подсчет статистики total_throws = len(throws) total_base_sum = sum((t['dice'][0] + t['dice'][1]) * 2 if t['dice'][0] == t['dice'][1] else t['dice'][0] + t['dice'][1] for t in throws) total_final_sum = sum(calculate_throw_sum(t) for t in throws) - -# Обновляем подсчет статистики - total_throws = len(throws) avg_sum = total_base_sum / total_throws if total_throws > 0 else 0 avg_sum_with_minus = total_final_sum / total_throws if total_throws > 0 else 0 doubles = sum(1 for t in throws if t['dice'][0] == t['dice'][1]) - # Находим максимальный и минимальный броски с учетом дублей + # Находим максимальный и минимальный броски throws_with_sums = [(t, calculate_throw_sum(t)) for t in throws] max_throw = max(throws_with_sums, key=lambda x: x[1]) min_throw = min(throws_with_sums, key=lambda x: x[1]) - # Формируем сообщение - response = "🎯 Игра завершена!\n\n" - response += f"📊 Статистика игры:\n" - response += f"• Всего бросков: {total_throws}\n" - response += f"• Общая сумма: {total_final_sum}\n" - + response = "🎲 Итоги игры\n\n" + + # Основная статистика + response += "📊 Общая статистика:\n" + response += f"• Бросков: {total_throws}\n" + response += f"• Сумма очков: {total_final_sum}" + if total_base_sum != total_final_sum: unused_sum = total_base_sum - total_final_sum - response += f" (без минусов: {total_base_sum})\n" - response += f"• Неиспользовано: {unused_sum}\n" + response += f" (потенциал: {total_base_sum})\n" + response += f"• Неиспользовано: {unused_sum} очков\n" response += f"• Эффективность: {(total_final_sum / total_base_sum * 100):.1f}%\n" - response += f"• Средняя сумма: {avg_sum_with_minus:.1f} \n" - response += f" (без минусов: {avg_sum:.1f})\n" else: response += "\n" - response += f"• Средняя сумма: {avg_sum:.1f}\n" - - response += f"• Дублей выпало: {doubles}\n" - - # Добавляем последние броски + response += f"• Дублей: {doubles} ({(doubles/total_throws*100):.1f}%)\n" + + # Средние значения + response += "\n📈 Средние значения:\n" + response += f"• За бросок: {avg_sum_with_minus:.1f}" + if total_base_sum != total_final_sum: + response += f" (макс. {avg_sum:.1f})\n" + else: + response += "\n" + + # Топ комбинаций + response += "\n🎯 Частые комбинации:\n" + for combo, count in sorted_combinations[:5]: # Показываем топ-5 комбинаций + percentage = (count / total_throws) * 100 + is_double = combo[0] == combo[2] # Проверяем, дубль ли это + response += f"• {combo} {'🎯' if is_double else ''}: {count}x ({percentage:.1f}%)\n" + + # Последние броски response += "\n🎲 Последние броски:\n" for i, throw in enumerate(throws[:5]): sum_value = calculate_throw_sum(throw) is_double = throw['dice'][0] == throw['dice'][1] unused = throw.get('unusedPoints', 0) - base_sum = (throw['dice'][0] + throw['dice'][1]) * 2 if is_double else throw['dice'][0] + throw['dice'][1] response += f"{i+1}. {throw['dice'][0]}-{throw['dice'][1]}" - response += f" {'🎯' if is_double else ''}" + if is_double: + response += " 🎯" if unused > 0: response += f" = {sum_value} (-{unused})" else: response += f" = {sum_value}" response += "\n" - + if total_throws > 5: response += f"... и ещё {total_throws - 5} бросков"