-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer_analysis.py
More file actions
53 lines (43 loc) · 1.69 KB
/
player_analysis.py
File metadata and controls
53 lines (43 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json
from collections import defaultdict
# Carichiamo nuovamente il JSON
with open("jungler_network_noobs.json", "r") as f:
data_fixed = json.load(f)
# Contiamo nuovamente i campioni più giocati da ciascun giocatore
champion_count_fixed = defaultdict(lambda: defaultdict(int))
for player, player_data in data_fixed.items():
for match_list_key in ["OUT", "IN"]:
if match_list_key in player_data:
for match in player_data[match_list_key]:
champion = match.get("champion")
if champion:
champion_count_fixed[player][champion] += 1
def extract_player_info(player_id, data):
player_data = data.get(player_id, {})
if not player_data:
return {"error": f"Giocatore {player_id} non trovato nel JSON."}
# Estrai Rank, Tier e LP
info = player_data.get("INFO", {})
rank = info.get("rank", "N/A")
tier = info.get("tier", "N/A")
lp = info.get("LP", "N/A")
# Estrai il numero totale di partite giocate
out_matches = player_data.get("OUT", [])
in_matches = player_data.get("IN", [])
total_matches = len(out_matches) + len(in_matches)
# Estrai il campione preferito
most_played_champion = max(
champion_count_fixed[player_id],
key=champion_count_fixed[player_id].get,
default="N/A",
)
return {
"Rank": rank,
"Tier": tier,
"LP": lp,
"Total Matches": total_matches,
"Most Played Champion": most_played_champion,
}
# Testiamo nuovamente lo script con il giocatore "LuvFlakkedCheeks"
example_output = extract_player_info("STAND NAME", data_fixed)
print(example_output)