3.0.1: fix

This commit is contained in:
2026-01-29 03:17:24 +08:00
parent 04ee957af6
commit 066a0ce719
10 changed files with 294 additions and 132 deletions

View File

@@ -27,6 +27,7 @@ def api_analyze():
total_kd = 0
total_adr = 0
count = 0
radar_vectors = []
for p in players:
p_dict = dict(p)
@@ -37,10 +38,25 @@ def api_analyze():
player_data.append(p_dict)
if stats:
total_rating += stats.get('basic_avg_rating', 0) or 0
total_kd += stats.get('basic_avg_kd', 0) or 0
total_adr += stats.get('basic_avg_adr', 0) or 0
rating_val = stats.get('core_avg_rating2')
if rating_val is None:
rating_val = stats.get('core_avg_rating')
if rating_val is None:
rating_val = stats.get('basic_avg_rating')
total_rating += rating_val or 0
total_kd += stats.get('core_avg_kd', stats.get('basic_avg_kd', 0)) or 0
total_adr += stats.get('core_avg_adr', stats.get('basic_avg_adr', 0)) or 0
count += 1
radar_vectors.append([
float(stats.get('score_aim') or 0),
float(stats.get('score_defense') or 0),
float(stats.get('score_utility') or 0),
float(stats.get('score_clutch') or 0),
float(stats.get('score_economy') or 0),
float(stats.get('score_pace') or 0),
float(stats.get('score_pistol') or 0),
float(stats.get('score_stability') or 0)
])
# 2. Shared Matches
shared_matches = StatsService.get_shared_matches(steam_ids)
@@ -53,6 +69,23 @@ def api_analyze():
'adr': total_adr / count if count else 0
}
chemistry = 0
if len(radar_vectors) >= 2:
def cosine_sim(a, b):
dot = sum(x * y for x, y in zip(a, b))
na = sum(x * x for x in a) ** 0.5
nb = sum(y * y for y in b) ** 0.5
if na == 0 or nb == 0:
return 0
return dot / (na * nb)
sims = []
for i in range(len(radar_vectors)):
for j in range(i + 1, len(radar_vectors)):
sims.append(cosine_sim(radar_vectors[i], radar_vectors[j]))
if sims:
chemistry = sum(sims) / len(sims) * 100
# 4. Map Stats Calculation
map_stats = {} # {map_name: {'count': 0, 'wins': 0}}
total_shared_matches = len(shared_matches)
@@ -85,7 +118,8 @@ def api_analyze():
'shared_matches': [dict(m) for m in shared_matches],
'avg_stats': avg_stats,
'map_stats': map_stats_list,
'total_shared_matches': total_shared_matches
'total_shared_matches': total_shared_matches,
'chemistry': chemistry
})
# API: Save Board