Update main.py

This commit is contained in:
ilyastar9999
2025-12-03 14:04:41 +03:00
parent d1368b1877
commit be8174ceea

View File

@@ -201,20 +201,31 @@ async def socketio_listener():
round_num = event_data.get('round', 0)
round_start = event_data.get('round_start', 0)
team_tasks = event_data.get('team_tasks', [])
teams_data = event_data.get('teams', [])
print(f"📊 Round {round_num} - Processing {len(team_tasks)} team updates")
conn = await db_pool.acquire()
try:
# Store team scores
for team in teams_data:
team_id = team.get('id')
# Store team scores from team_tasks (score field = FP for this service)
# Aggregate scores per team
team_fp_totals = {}
for team_task in team_tasks:
team_id = team_task.get('team_id')
fp_score = team_task.get('score', 0)
if team_id not in team_fp_totals:
team_fp_totals[team_id] = 0
team_fp_totals[team_id] += fp_score
# Store aggregated scores
for team_id, total_fp in team_fp_totals.items():
await conn.execute("""
INSERT INTO team_scores (team_id, team_name, total_score, flag_points, round, timestamp)
VALUES ($1, $2, $3, $4, $5, NOW())
""", team_id, team_names.get(team_id, f'Team {team_id}'),
team.get('score', 0), team.get('flag_points', 0), round_num)
total_fp, total_fp, round_num)
# Process each team_task for attack detection
for team_task in team_tasks:
team_id = team_task.get('team_id')
task_id = team_task.get('task_id')