Alvaro commited on
Commit
b38f690
·
1 Parent(s): a49cbb2
.gitignore DELETED
@@ -1 +0,0 @@
1
- ufc_events_detailed.json
 
 
output/ufc_events_detailed.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:efffe902c81d1ab870852e9dd6d192e3b203e11b1a99a36c7ea97be451d197d6
3
+ size 15088727
output/ufc_fights.csv ADDED
The diff for this file is too large to render. See raw diff
 
src/analyze.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ ufc_events = json.load(open('ufc_events_detailed.json'))
4
+
5
+ unique_fighters = set()
6
+
7
+ for event in ufc_events:
8
+ for fight in event['fights']:
9
+ unique_fighters.add(fight['fighter_1'])
10
+ unique_fighters.add(fight['fighter_2'])
11
+
12
+ print(len(unique_fighters))
13
+
14
+
15
+
main.py → src/scrape_fights.py RENAMED
File without changes
src/to_csv.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import csv
3
+
4
+ def json_to_csv(json_file_path, csv_file_path):
5
+ try:
6
+ with open(json_file_path, 'r', encoding='utf-8') as json_file:
7
+ data = json.load(json_file)
8
+ except FileNotFoundError:
9
+ print(f"Error: The file {json_file_path} was not found.")
10
+ return
11
+ except json.JSONDecodeError:
12
+ print(f"Error: Could not decode JSON from {json_file_path}.")
13
+ return
14
+
15
+ # Define the headers for the CSV file
16
+ headers = [
17
+ 'event_name', 'event_date', 'event_location', 'fighter_1', 'fighter_2',
18
+ 'weight_class', 'method', 'round', 'time',
19
+ 'f1_kd', 'f1_sig_str', 'f1_sig_str_percent', 'f1_total_str', 'f1_td',
20
+ 'f1_td_percent', 'f1_sub_att', 'f1_rev', 'f1_ctrl',
21
+ 'f1_sig_str_head', 'f1_sig_str_body', 'f1_sig_str_leg', 'f1_sig_str_distance',
22
+ 'f1_sig_str_clinch', 'f1_sig_str_ground',
23
+ 'f2_kd', 'f2_sig_str', 'f2_sig_str_percent', 'f2_total_str', 'f2_td',
24
+ 'f2_td_percent', 'f2_sub_att', 'f2_rev', 'f2_ctrl',
25
+ 'f2_sig_str_head', 'f2_sig_str_body', 'f2_sig_str_leg', 'f2_sig_str_distance',
26
+ 'f2_sig_str_clinch', 'f2_sig_str_ground'
27
+ ]
28
+
29
+ with open(csv_file_path, 'w', newline='', encoding='utf-8') as csv_file:
30
+ writer = csv.writer(csv_file)
31
+ writer.writerow(headers)
32
+
33
+ for event in data:
34
+ for fight in event.get('fights', []):
35
+ details = fight.get('details')
36
+
37
+ # Create a dictionary for easier and safer access to stats
38
+ f1_stats = details.get('fighter_1_stats', {}) if details else {}
39
+ f2_stats = details.get('fighter_2_stats', {}) if details else {}
40
+
41
+ row = [
42
+ event.get('name', ''),
43
+ event.get('date', ''),
44
+ event.get('location', ''),
45
+ fight.get('fighter_1', ''),
46
+ fight.get('fighter_2', ''),
47
+ fight.get('weight_class', ''),
48
+ fight.get('method', ''),
49
+ fight.get('round', ''),
50
+ fight.get('time', ''),
51
+ f1_stats.get('kd', ''),
52
+ f1_stats.get('sig_str', ''),
53
+ f1_stats.get('sig_str_percent', ''),
54
+ f1_stats.get('total_str', ''),
55
+ f1_stats.get('td', ''),
56
+ f1_stats.get('td_percent', ''),
57
+ f1_stats.get('sub_att', ''),
58
+ f1_stats.get('rev', ''),
59
+ f1_stats.get('ctrl', ''),
60
+ f1_stats.get('sig_str_head', ''),
61
+ f1_stats.get('sig_str_body', ''),
62
+ f1_stats.get('sig_str_leg', ''),
63
+ f1_stats.get('sig_str_distance', ''),
64
+ f1_stats.get('sig_str_clinch', ''),
65
+ f1_stats.get('sig_str_ground', ''),
66
+ f2_stats.get('kd', ''),
67
+ f2_stats.get('sig_str', ''),
68
+ f2_stats.get('sig_str_percent', ''),
69
+ f2_stats.get('total_str', ''),
70
+ f2_stats.get('td', ''),
71
+ f2_stats.get('td_percent', ''),
72
+ f2_stats.get('sub_att', ''),
73
+ f2_stats.get('rev', ''),
74
+ f2_stats.get('ctrl', ''),
75
+ f2_stats.get('sig_str_head', ''),
76
+ f2_stats.get('sig_str_body', ''),
77
+ f2_stats.get('sig_str_leg', ''),
78
+ f2_stats.get('sig_str_distance', ''),
79
+ f2_stats.get('sig_str_clinch', ''),
80
+ f2_stats.get('sig_str_ground', '')
81
+ ]
82
+ writer.writerow(row)
83
+
84
+ print(f"Successfully converted {json_file_path} to {csv_file_path}")
85
+
86
+ if __name__ == '__main__':
87
+ json_to_csv('ufc_events_detailed.json', 'ufc_fights.csv')