1.5.0: Clutch fully recovered.

This commit is contained in:
2026-01-27 17:53:09 +08:00
parent 0be68a86f6
commit 50428ae2ac
5 changed files with 187 additions and 29 deletions

View File

@@ -627,6 +627,52 @@ class StatsService:
if target_steam_id not in stats_map:
stats_map[target_steam_id] = {}
# --- New: Enrich with L2 Clutch/Multi Stats for Distribution ---
l2_placeholders = ','.join('?' for _ in active_roster_ids)
sql_l2 = f"""
SELECT
p.steam_id_64,
SUM(p.clutch_1v1) as c1, SUM(p.clutch_1v2) as c2, SUM(p.clutch_1v3) as c3, SUM(p.clutch_1v4) as c4, SUM(p.clutch_1v5) as c5,
SUM(a.attempt_1v1) as att1, SUM(a.attempt_1v2) as att2, SUM(a.attempt_1v3) as att3, SUM(a.attempt_1v4) as att4, SUM(a.attempt_1v5) as att5,
SUM(p.kill_2) as k2, SUM(p.kill_3) as k3, SUM(p.kill_4) as k4, SUM(p.kill_5) as k5,
SUM(p.many_assists_cnt2) as a2, SUM(p.many_assists_cnt3) as a3, SUM(p.many_assists_cnt4) as a4, SUM(p.many_assists_cnt5) as a5,
SUM(p.round_total) as total_rounds
FROM fact_match_players p
LEFT JOIN fact_match_clutch_attempts a ON p.match_id = a.match_id AND p.steam_id_64 = a.steam_id_64
WHERE CAST(p.steam_id_64 AS TEXT) IN ({l2_placeholders})
GROUP BY p.steam_id_64
"""
l2_rows = query_db('l2', sql_l2, active_roster_ids)
for r in l2_rows:
sid = str(r['steam_id_64'])
if sid not in stats_map:
stats_map[sid] = {}
# Clutch Rates
for i in range(1, 6):
c = r[f'c{i}'] or 0
att = r[f'att{i}'] or 0
rate = (c / att) if att > 0 else 0
stats_map[sid][f'clutch_rate_1v{i}'] = rate
# Multi-Kill Rates
rounds = r['total_rounds'] or 1 # Avoid div by 0
total_mk = 0
for i in range(2, 6):
k = r[f'k{i}'] or 0
total_mk += k
stats_map[sid][f'multikill_rate_{i}k'] = k / rounds
stats_map[sid]['total_multikill_rate'] = total_mk / rounds
# Multi-Assist Rates
total_ma = 0
for i in range(2, 6):
a = r[f'a{i}'] or 0
total_ma += a
stats_map[sid][f'multiassist_rate_{i}a'] = a / rounds
stats_map[sid]['total_multiassist_rate'] = total_ma / rounds
# 3. Calculate Distribution for ALL metrics
# Define metrics list (must match Detailed Panel keys)
metrics = [
@@ -658,7 +704,12 @@ class StatsService:
# New: Rating Distribution
'rating_dist_carry_rate', 'rating_dist_normal_rate', 'rating_dist_sacrifice_rate', 'rating_dist_sleeping_rate',
# New: ELO Stratification
'elo_lt1200_rating', 'elo_1200_1400_rating', 'elo_1400_1600_rating', 'elo_1600_1800_rating', 'elo_1800_2000_rating', 'elo_gt2000_rating'
'elo_lt1200_rating', 'elo_1200_1400_rating', 'elo_1400_1600_rating', 'elo_1600_1800_rating', 'elo_1800_2000_rating', 'elo_gt2000_rating',
# New: Clutch & Multi (Real Calculation)
'clutch_rate_1v1', 'clutch_rate_1v2', 'clutch_rate_1v3', 'clutch_rate_1v4', 'clutch_rate_1v5',
'multikill_rate_2k', 'multikill_rate_3k', 'multikill_rate_4k', 'multikill_rate_5k',
'multiassist_rate_2a', 'multiassist_rate_3a', 'multiassist_rate_4a', 'multiassist_rate_5a',
'total_multikill_rate', 'total_multiassist_rate'
]
# Mapping for L2 legacy calls (if any) - mainly map 'rating' to 'basic_avg_rating' etc if needed