-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParseSoupData.py
71 lines (54 loc) · 2.37 KB
/
ParseSoupData.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from ReadFile import read_json_data
import objects.MatchEvent as MatchEvent
import objects.MatchInfo as Info
from JsonObjectNames import GoalObject as GoalObject
from JsonObjectNames import MatchInfoObject as MatchObject
from JsonObjectNames import PenaltyObject as PenaltyObject
def extract_match_info(all_data):
info = all_data['info'][0]
match_date = info[MatchObject.MatchDate]
arena = info[MatchObject.Arena]
home_team = info[MatchObject.HomeTeam]
away_team = info[MatchObject.AwayTeam]
end_result = info[MatchObject.Results]
match_info = Info.MatchInfo(match_date, arena, home_team, away_team, end_result)
return match_info
def extract_goals(all_data):
goals = []
for entry in all_data['goals']:
for goal in entry['goalsInOrder']:
scorer = goal[GoalObject.Scorer]
assist = goal[GoalObject.Assist]
partial_result = goal[GoalObject.PartialResult]
team_name = goal[GoalObject.TeamName]
time = goal[GoalObject.Time]
if time == 'Str':
scorer = "Penalty shootout"
time = "3 - 20:00"
current = MatchEvent.Goal(scorer, assist, partial_result, team_name, time)
goals.append(current)
return goals
def extract_penalties(all_data):
all_penalties = []
for penalty in all_data['pens']:
home_team = penalty[PenaltyObject.HomeTeam]
away_team = penalty[PenaltyObject.AwayTeam]
match_penalties = penalty[PenaltyObject.Penalties]
for match_penalty in match_penalties:
home_time = match_penalty[PenaltyObject.HomeTime]
home_penalty = match_penalty[PenaltyObject.HomePenalty]
away_time = match_penalty[PenaltyObject.AwayTime]
away_penalty = match_penalty[PenaltyObject.AwayPenalty]
if home_time != "":
current = MatchEvent.Penalty(home_team, home_time, home_penalty)
all_penalties.append(current)
if away_time != "":
current = MatchEvent.Penalty(away_team, away_time, away_penalty)
all_penalties.append(current)
return all_penalties
def get_data_from_file(path):
all_data = read_json_data(path)
match_info = extract_match_info(all_data)
goals = extract_goals(all_data)
penalties = extract_penalties(all_data)
return match_info, goals, penalties