1.5.0: Clutch fully recovered.
This commit is contained in:
@@ -1342,5 +1342,94 @@ def save_match(cursor, m: MatchData):
|
||||
m.match_id, r.round_num, pe.steam_id_64, pe.side, pe.start_money, pe.equipment_value, pe.main_weapon, pe.has_helmet, pe.has_defuser, pe.round_performance_score
|
||||
))
|
||||
|
||||
# 6. Calculate & Save Clutch Attempts
|
||||
_calculate_and_save_clutch_attempts(cursor, m.match_id, m.round_list_raw)
|
||||
|
||||
def _calculate_and_save_clutch_attempts(cursor, match_id, round_list_raw):
|
||||
if not round_list_raw:
|
||||
return
|
||||
|
||||
try:
|
||||
round_list = json.loads(round_list_raw)
|
||||
except:
|
||||
return
|
||||
|
||||
player_attempts = {}
|
||||
|
||||
for round_data in round_list:
|
||||
all_kills = round_data.get('all_kill', [])
|
||||
if not all_kills:
|
||||
continue
|
||||
|
||||
team_members = {1: set(), 2: set()}
|
||||
|
||||
# Scan for team members
|
||||
for k in all_kills:
|
||||
if k.get('attacker') and k['attacker'].get('steamid_64'):
|
||||
tid = k['attacker'].get('team')
|
||||
if tid in [1, 2]:
|
||||
team_members[tid].add(k['attacker']['steamid_64'])
|
||||
if k.get('victim') and k['victim'].get('steamid_64'):
|
||||
tid = k['victim'].get('team')
|
||||
if tid in [1, 2]:
|
||||
team_members[tid].add(k['victim']['steamid_64'])
|
||||
|
||||
if not team_members[1] or not team_members[2]:
|
||||
continue
|
||||
|
||||
alive = {1: team_members[1].copy(), 2: team_members[2].copy()}
|
||||
clutch_triggered_players = set()
|
||||
|
||||
# Sort kills by time
|
||||
sorted_kills = sorted(all_kills, key=lambda x: x.get('pasttime', 0))
|
||||
|
||||
for k in sorted_kills:
|
||||
victim = k.get('victim')
|
||||
if not victim: continue
|
||||
|
||||
v_sid = victim.get('steamid_64')
|
||||
v_team = victim.get('team')
|
||||
|
||||
if v_team not in [1, 2] or v_sid not in alive[v_team]:
|
||||
continue
|
||||
|
||||
alive[v_team].remove(v_sid)
|
||||
|
||||
if len(alive[v_team]) == 1:
|
||||
survivor_sid = list(alive[v_team])[0]
|
||||
if survivor_sid not in clutch_triggered_players:
|
||||
opponent_team = 3 - v_team
|
||||
opponents_alive_count = len(alive[opponent_team])
|
||||
|
||||
if opponents_alive_count >= 1:
|
||||
if survivor_sid not in player_attempts:
|
||||
player_attempts[survivor_sid] = {'1v1': 0, '1v2': 0, '1v3': 0, '1v4': 0, '1v5': 0}
|
||||
|
||||
n = min(opponents_alive_count, 5)
|
||||
key = f'1v{n}'
|
||||
player_attempts[survivor_sid][key] += 1
|
||||
clutch_triggered_players.add(survivor_sid)
|
||||
|
||||
# Save to DB
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS fact_match_clutch_attempts (
|
||||
match_id TEXT,
|
||||
steam_id_64 TEXT,
|
||||
attempt_1v1 INTEGER DEFAULT 0,
|
||||
attempt_1v2 INTEGER DEFAULT 0,
|
||||
attempt_1v3 INTEGER DEFAULT 0,
|
||||
attempt_1v4 INTEGER DEFAULT 0,
|
||||
attempt_1v5 INTEGER DEFAULT 0,
|
||||
PRIMARY KEY (match_id, steam_id_64)
|
||||
)
|
||||
""")
|
||||
|
||||
for pid, att in player_attempts.items():
|
||||
cursor.execute("""
|
||||
INSERT OR REPLACE INTO fact_match_clutch_attempts
|
||||
(match_id, steam_id_64, attempt_1v1, attempt_1v2, attempt_1v3, attempt_1v4, attempt_1v5)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
""", (match_id, pid, att['1v1'], att['1v2'], att['1v3'], att['1v4'], att['1v5']))
|
||||
|
||||
if __name__ == "__main__":
|
||||
process_matches()
|
||||
|
||||
Reference in New Issue
Block a user