ahl_scraper 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +85 -0
- data/.ruby-version +1 -0
- data/.solargraph.yml +15 -0
- data/.travis.yml +6 -0
- data/.vscode/settings.json +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +114 -0
- data/LICENSE.txt +21 -0
- data/README.md +235 -0
- data/Rakefile +8 -0
- data/ahl_scraper.gemspec +27 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/lib/ahl_scraper.rb +55 -0
- data/lib/ahl_scraper/fetchers/division_data_fetcher.rb +19 -0
- data/lib/ahl_scraper/fetchers/game_data_fetcher.rb +29 -0
- data/lib/ahl_scraper/fetchers/game_event_data_fetcher.rb +19 -0
- data/lib/ahl_scraper/fetchers/player_data_fetcher.rb +25 -0
- data/lib/ahl_scraper/fetchers/player_games/data_fetcher.rb +30 -0
- data/lib/ahl_scraper/fetchers/playoff_bracket_data_fetcher.rb +19 -0
- data/lib/ahl_scraper/fetchers/season_data_fetcher.rb +15 -0
- data/lib/ahl_scraper/fetchers/season_end_date_fetcher.rb +34 -0
- data/lib/ahl_scraper/fetchers/season_game_ids_fetcher.rb +21 -0
- data/lib/ahl_scraper/fetchers/season_start_date_fetcher.rb +30 -0
- data/lib/ahl_scraper/fetchers/season_type_fetcher.rb +33 -0
- data/lib/ahl_scraper/fetchers/team_data_fetcher.rb +19 -0
- data/lib/ahl_scraper/fetchers/team_games/data_fetcher.rb +22 -0
- data/lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb +67 -0
- data/lib/ahl_scraper/fixed_games/1001050.json +2182 -0
- data/lib/ahl_scraper/fixed_games/1018774.json +2573 -0
- data/lib/ahl_scraper/fixed_games/1020527.json +2483 -0
- data/lib/ahl_scraper/games.rb +46 -0
- data/lib/ahl_scraper/games/events.rb +8 -0
- data/lib/ahl_scraper/helpers/birthdate_helper.rb +27 -0
- data/lib/ahl_scraper/helpers/elapsed_time_helper.rb +24 -0
- data/lib/ahl_scraper/helpers/ice_time_helper.rb +18 -0
- data/lib/ahl_scraper/helpers/parameterize_helper.rb +35 -0
- data/lib/ahl_scraper/helpers/period_time_helper.rb +25 -0
- data/lib/ahl_scraper/helpers/season_dates_helper.rb +14 -0
- data/lib/ahl_scraper/player_games.rb +19 -0
- data/lib/ahl_scraper/players.rb +12 -0
- data/lib/ahl_scraper/playoff_brackets.rb +17 -0
- data/lib/ahl_scraper/resource.rb +38 -0
- data/lib/ahl_scraper/resources/game.rb +373 -0
- data/lib/ahl_scraper/resources/game_list_item.rb +57 -0
- data/lib/ahl_scraper/resources/games/coach.rb +23 -0
- data/lib/ahl_scraper/resources/games/events/shot.rb +10 -0
- data/lib/ahl_scraper/resources/games/goal.rb +161 -0
- data/lib/ahl_scraper/resources/games/goalie.rb +106 -0
- data/lib/ahl_scraper/resources/games/info.rb +83 -0
- data/lib/ahl_scraper/resources/games/on_ice_skater.rb +35 -0
- data/lib/ahl_scraper/resources/games/overtime.rb +48 -0
- data/lib/ahl_scraper/resources/games/penalty.rb +101 -0
- data/lib/ahl_scraper/resources/games/penalty_shot.rb +82 -0
- data/lib/ahl_scraper/resources/games/period.rb +31 -0
- data/lib/ahl_scraper/resources/games/referee.rb +23 -0
- data/lib/ahl_scraper/resources/games/shootout_attempt.rb +61 -0
- data/lib/ahl_scraper/resources/games/skater.rb +94 -0
- data/lib/ahl_scraper/resources/games/star.rb +47 -0
- data/lib/ahl_scraper/resources/games/team.rb +85 -0
- data/lib/ahl_scraper/resources/goalie_game_list_item.rb +69 -0
- data/lib/ahl_scraper/resources/player.rb +71 -0
- data/lib/ahl_scraper/resources/playoff_bracket.rb +21 -0
- data/lib/ahl_scraper/resources/playoff_brackets/game.rb +43 -0
- data/lib/ahl_scraper/resources/playoff_brackets/round.rb +31 -0
- data/lib/ahl_scraper/resources/playoff_brackets/series.rb +73 -0
- data/lib/ahl_scraper/resources/playoff_brackets/team.rb +39 -0
- data/lib/ahl_scraper/resources/roster_player.rb +71 -0
- data/lib/ahl_scraper/resources/season.rb +93 -0
- data/lib/ahl_scraper/resources/season_list_item.rb +30 -0
- data/lib/ahl_scraper/resources/seasons/team.rb +77 -0
- data/lib/ahl_scraper/resources/skater_game_list_item.rb +65 -0
- data/lib/ahl_scraper/resources/team_game_list_item.rb +64 -0
- data/lib/ahl_scraper/resources/team_list_item.rb +20 -0
- data/lib/ahl_scraper/roster_players.rb +11 -0
- data/lib/ahl_scraper/seasons.rb +31 -0
- data/lib/ahl_scraper/services/games/create_skaters_service.rb +72 -0
- data/lib/ahl_scraper/services/games/on_ice_statlines_service.rb +117 -0
- data/lib/ahl_scraper/services/games/penalty_shot_statlines_service.rb +38 -0
- data/lib/ahl_scraper/services/games/penalty_shots_service.rb +30 -0
- data/lib/ahl_scraper/services/games/penalty_statlines_service.rb +62 -0
- data/lib/ahl_scraper/services/games/scoring_statlines_service.rb +115 -0
- data/lib/ahl_scraper/services/games/shootout_statlines_service.rb +42 -0
- data/lib/ahl_scraper/services/games/team_on_ice_goals_service.rb +152 -0
- data/lib/ahl_scraper/services/games/time_splits_service.rb +70 -0
- data/lib/ahl_scraper/services/seasons/teams_service.rb +20 -0
- data/lib/ahl_scraper/team_games.rb +17 -0
- data/lib/ahl_scraper/teams.rb +11 -0
- data/lib/ahl_scraper/version.rb +5 -0
- metadata +138 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AhlScraper
|
4
|
+
class GameListItem < Resource
|
5
|
+
def initialize(raw_data)
|
6
|
+
@raw_data = raw_data
|
7
|
+
end
|
8
|
+
|
9
|
+
def id
|
10
|
+
@id ||= @raw_data[:row][:game_id].to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
def home_team_city
|
14
|
+
@home_team_city ||= @raw_data[:row][:home_team_city]
|
15
|
+
end
|
16
|
+
|
17
|
+
def home_team_score
|
18
|
+
@home_team_score ||= @raw_data[:row][:home_goal_count].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def home_team_id
|
22
|
+
@home_team_id ||= @raw_data[:prop][:home_team_city][:teamLink].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def away_team_city
|
26
|
+
@away_team_city ||= @raw_data[:row][:visiting_team_city]
|
27
|
+
end
|
28
|
+
|
29
|
+
def away_team_score
|
30
|
+
@away_team_score ||= @raw_data[:row][:visiting_goal_count].to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
def away_team_id
|
34
|
+
@away_team_id ||= @raw_data[:prop][:visiting_team_city][:teamLink].to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
def date
|
38
|
+
@date ||= @raw_data[:row][:date_with_day]
|
39
|
+
end
|
40
|
+
|
41
|
+
def status
|
42
|
+
@status ||= @raw_data[:row][:game_status]
|
43
|
+
end
|
44
|
+
|
45
|
+
def game_report_url
|
46
|
+
@game_report_url ||= @raw_data[:prop][:game_report][:link]
|
47
|
+
end
|
48
|
+
|
49
|
+
def game_sheet_url
|
50
|
+
@game_sheet_url ||= @raw_data[:prop][:game_sheet][:link]
|
51
|
+
end
|
52
|
+
|
53
|
+
def game_center_url
|
54
|
+
@game_center_url ||= "https://theahl.com/stats/game-center/#{id}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AhlScraper
|
4
|
+
module Games
|
5
|
+
class Coach < Resource
|
6
|
+
def first_name
|
7
|
+
@first_name ||= @raw_data[:firstName]
|
8
|
+
end
|
9
|
+
|
10
|
+
def last_name
|
11
|
+
@last_name ||= @raw_data[:lastName]
|
12
|
+
end
|
13
|
+
|
14
|
+
def position
|
15
|
+
@position ||= @raw_data[:role]
|
16
|
+
end
|
17
|
+
|
18
|
+
def team_id
|
19
|
+
@team_id ||= @opts[:team_id]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AhlScraper
|
4
|
+
module Games
|
5
|
+
class Goal < Resource
|
6
|
+
def id
|
7
|
+
@id ||= @raw_data[:game_goal_id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def number
|
11
|
+
@number ||= @opts[:number]
|
12
|
+
end
|
13
|
+
|
14
|
+
def period
|
15
|
+
@period ||= @raw_data[:period][:id].to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
def time
|
19
|
+
@time ||= @raw_data[:time]
|
20
|
+
end
|
21
|
+
|
22
|
+
def period_time_in_seconds
|
23
|
+
@period_time_in_seconds ||= period_time.to_sec
|
24
|
+
end
|
25
|
+
|
26
|
+
def game_time_elapsed
|
27
|
+
@game_time_elapsed ||= period_time.to_elapsed
|
28
|
+
end
|
29
|
+
|
30
|
+
def scorer_goal_number
|
31
|
+
@scorer_goal_number ||= @raw_data[:scorerGoalNumber]
|
32
|
+
end
|
33
|
+
|
34
|
+
def scored_by
|
35
|
+
@scored_by ||= {
|
36
|
+
id: @raw_data[:scoredBy][:id],
|
37
|
+
first_name: @raw_data[:scoredBy][:firstName],
|
38
|
+
last_name: @raw_data[:scoredBy][:lastName],
|
39
|
+
number: @raw_data[:scoredBy][:jerseyNumber],
|
40
|
+
position: @raw_data[:scoredBy][:position],
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def assists
|
45
|
+
@assists ||= @raw_data[:assists].map do |assist|
|
46
|
+
{
|
47
|
+
id: assist[:id],
|
48
|
+
first_name: assist[:firstName],
|
49
|
+
last_name: assist[:lastName],
|
50
|
+
number: assist[:jerseyNumber],
|
51
|
+
position: assist[:position],
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def assist_numbers
|
57
|
+
@assist_numbers ||= @raw_data[:assistNumbers]
|
58
|
+
end
|
59
|
+
|
60
|
+
def scoring_team
|
61
|
+
@scoring_team ||= @raw_data[:team]
|
62
|
+
end
|
63
|
+
|
64
|
+
def power_play?
|
65
|
+
@power_play ||= @raw_data[:properties][:isPowerPlay] == "1"
|
66
|
+
end
|
67
|
+
|
68
|
+
def short_handed?
|
69
|
+
@short_handed ||= @raw_data[:properties][:isShortHanded] == "1"
|
70
|
+
end
|
71
|
+
|
72
|
+
def empty_net?
|
73
|
+
@empty_net ||= @raw_data[:properties][:isEmptyNet] == "1"
|
74
|
+
end
|
75
|
+
|
76
|
+
def extra_skater?
|
77
|
+
@extra_skater ||= set_extra_skater
|
78
|
+
end
|
79
|
+
|
80
|
+
def penalty_shot?
|
81
|
+
@penalty_shot ||= @raw_data[:properties][:isPenaltyShot] == "1"
|
82
|
+
end
|
83
|
+
|
84
|
+
def insurance_goal?
|
85
|
+
@insurance_goal ||= @raw_data[:properties][:isInsuranceGoal] == "1"
|
86
|
+
end
|
87
|
+
|
88
|
+
def game_winner?
|
89
|
+
@game_winner ||= @raw_data[:properties][:isGameWinningGoal] == "1"
|
90
|
+
end
|
91
|
+
|
92
|
+
def plus_players
|
93
|
+
@plus_players ||= @raw_data[:plus_players].map { |player| OnIceSkater.new(player, { scoring_team: true, goal_id: id }) }
|
94
|
+
end
|
95
|
+
|
96
|
+
def minus_players
|
97
|
+
@minus_players ||= @raw_data[:minus_players].map { |player| OnIceSkater.new(player, { scoring_team: false, goal_id: id }) }
|
98
|
+
end
|
99
|
+
|
100
|
+
def situation
|
101
|
+
@situation ||=
|
102
|
+
if @raw_data[:properties][:isPowerPlay] == "1"
|
103
|
+
"PP"
|
104
|
+
elsif @raw_data[:properties][:isShortHanded] == "1"
|
105
|
+
"SH"
|
106
|
+
elsif @raw_data[:properties][:isEmptyNet] == "1"
|
107
|
+
"EN"
|
108
|
+
elsif extra_skater? == true
|
109
|
+
"EX"
|
110
|
+
elsif @raw_data[:properties][:isPenaltyShot] == "1"
|
111
|
+
"PS"
|
112
|
+
else
|
113
|
+
"EV"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def description
|
118
|
+
@description ||=
|
119
|
+
if assists.nil? || assists.empty?
|
120
|
+
goalscorer_name
|
121
|
+
elsif assists.length == 1
|
122
|
+
"#{goalscorer_name} (#{a1_name})"
|
123
|
+
else
|
124
|
+
"#{goalscorer_name} (#{a1_name}, #{a2_name})"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def special_teams?
|
129
|
+
@special_teams ||= short_handed? || power_play?
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
def set_extra_skater
|
135
|
+
return true if plus_players.length > minus_players.length && !special_teams? && !penalty_shot?
|
136
|
+
|
137
|
+
return true if plus_players.length == minus_players.length && short_handed?
|
138
|
+
|
139
|
+
return true if plus_players.length == 6
|
140
|
+
|
141
|
+
false
|
142
|
+
end
|
143
|
+
|
144
|
+
def goalscorer_name
|
145
|
+
@goalscorer_name ||= "#{scored_by[:first_name]} #{scored_by[:last_name]}"
|
146
|
+
end
|
147
|
+
|
148
|
+
def a1_name
|
149
|
+
@a1_name ||= "#{assists.dig(0, :first_name)} #{assists.dig(0, :last_name)}"
|
150
|
+
end
|
151
|
+
|
152
|
+
def a2_name
|
153
|
+
@a2_name ||= "#{assists.dig(1, :first_name)} #{assists.dig(1, :last_name)}"
|
154
|
+
end
|
155
|
+
|
156
|
+
def period_time
|
157
|
+
@period_time ||= PeriodTimeHelper.new(time, period)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AhlScraper
|
4
|
+
module Games
|
5
|
+
class Goalie < Resource
|
6
|
+
def id
|
7
|
+
@id ||= @raw_data[:info][:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def first_name
|
11
|
+
@first_name ||= @raw_data[:info][:firstName]
|
12
|
+
end
|
13
|
+
|
14
|
+
def last_name
|
15
|
+
@last_name ||= @raw_data[:info][:lastName]
|
16
|
+
end
|
17
|
+
|
18
|
+
def jersey_number
|
19
|
+
@jersey_number ||= @raw_data[:info][:jerseyNumber]
|
20
|
+
end
|
21
|
+
|
22
|
+
def team_id
|
23
|
+
@team_id ||= @opts[:team_id]
|
24
|
+
end
|
25
|
+
|
26
|
+
def home_team
|
27
|
+
@home_team ||= @opts[:home_team]
|
28
|
+
end
|
29
|
+
|
30
|
+
def position
|
31
|
+
@position ||= @raw_data[:info][:position]
|
32
|
+
end
|
33
|
+
|
34
|
+
def birthdate
|
35
|
+
@birthdate ||= valid_birthdate? ? @raw_data[:info][:birthDate] : nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def current_age
|
39
|
+
@current_age ||= valid_birthdate? ? BirthdateHelper.new(birthdate).age_on_date(@opts[:game_date]) : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def stats
|
43
|
+
@stats ||= {
|
44
|
+
goals: @raw_data[:stats][:goals],
|
45
|
+
assists: @raw_data[:stats][:assists],
|
46
|
+
points: @raw_data[:stats][:points],
|
47
|
+
penalty_minutes: @raw_data[:stats][:penaltyMinute],
|
48
|
+
toi: @raw_data[:stats][:timeOnIce],
|
49
|
+
toi_in_seconds: set_time_on_ice_in_seconds,
|
50
|
+
shots_against: @raw_data[:stats][:shotsAgainst],
|
51
|
+
goals_against: @raw_data[:stats][:goalsAgainst],
|
52
|
+
saves: @raw_data[:stats][:saves],
|
53
|
+
save_percent: @raw_data[:stats][:shotsAgainst].positive? ? set_save_percent : nil,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def starting
|
58
|
+
@starting ||= @raw_data[:starting]
|
59
|
+
end
|
60
|
+
|
61
|
+
def status
|
62
|
+
@status ||= @raw_data[:status]
|
63
|
+
end
|
64
|
+
|
65
|
+
def captaincy
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def shootout
|
70
|
+
@shootout ||= {
|
71
|
+
attempts_against: shootout_data.size,
|
72
|
+
goals_against: shootout_data.filter { |attempt| attempt[:isGoal] == true }.size,
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def penalty_shots
|
77
|
+
@penalty_shots ||= {
|
78
|
+
attempts_against: penalty_shot_data.size,
|
79
|
+
goals_against: penalty_shot_data.filter { |attempt| attempt[:isGoal] == true }.size,
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def set_save_percent
|
86
|
+
BigDecimal(@raw_data[:stats][:shotsAgainst] - @raw_data[:stats][:goalsAgainst]) / @raw_data[:stats][:shotsAgainst] * 100
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_time_on_ice_in_seconds
|
90
|
+
@raw_data[:stats][:timeOnIce].nil? ? nil : IceTimeHelper.new(@raw_data[:stats][:timeOnIce]).to_sec
|
91
|
+
end
|
92
|
+
|
93
|
+
def shootout_data
|
94
|
+
@shootout_data ||= (@opts[:shootout_data] || []).filter { |so| so[:goalie][:id] == id }
|
95
|
+
end
|
96
|
+
|
97
|
+
def penalty_shot_data
|
98
|
+
@penalty_shot_data ||= (@opts[:penalty_shot_data] || []).filter { |so| so[:goalie][:id] == id }
|
99
|
+
end
|
100
|
+
|
101
|
+
def valid_birthdate?
|
102
|
+
@valid_birthdate ||= !@raw_data.dig(:info, :birthDate).empty? && @raw_data.dig(:info, :birthDate) != "0000-00-00"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AhlScraper
|
4
|
+
module Games
|
5
|
+
class Info < Resource
|
6
|
+
def id
|
7
|
+
@id ||= @raw_data[:id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@name ||= @opts[:name]
|
12
|
+
end
|
13
|
+
|
14
|
+
def date
|
15
|
+
@date ||= @raw_data[:date]
|
16
|
+
end
|
17
|
+
|
18
|
+
def game_number
|
19
|
+
@game_number ||= @raw_data[:gameNumber].to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def venue
|
23
|
+
@venue ||= @raw_data[:venue]
|
24
|
+
end
|
25
|
+
|
26
|
+
def attendance
|
27
|
+
@attendance ||= @raw_data[:attendance].to_i
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_time
|
31
|
+
@start_time ||= @raw_data[:startTime]
|
32
|
+
end
|
33
|
+
|
34
|
+
def end_time
|
35
|
+
@end_time ||= @raw_data[:endTime]
|
36
|
+
end
|
37
|
+
|
38
|
+
def duration
|
39
|
+
@duration ||= @raw_data[:duration]
|
40
|
+
end
|
41
|
+
|
42
|
+
def game_report_url
|
43
|
+
@game_report_url ||= @raw_data[:gameReportUrl]
|
44
|
+
end
|
45
|
+
|
46
|
+
def text_boxscore_url
|
47
|
+
@text_boxscore_url ||= @raw_data[:textBoxscoreUrl]
|
48
|
+
end
|
49
|
+
|
50
|
+
def tickets_url
|
51
|
+
@tickets_url ||= @raw_data[:ticketsUrl]
|
52
|
+
end
|
53
|
+
|
54
|
+
def started
|
55
|
+
@started ||= @raw_data[:started] == "1"
|
56
|
+
end
|
57
|
+
|
58
|
+
def final
|
59
|
+
@final ||= @raw_data[:final] == "1"
|
60
|
+
end
|
61
|
+
|
62
|
+
def public_notes
|
63
|
+
@public_notes ||= @raw_data[:publicNotes]
|
64
|
+
end
|
65
|
+
|
66
|
+
def status
|
67
|
+
@status ||= @raw_data[:status]
|
68
|
+
end
|
69
|
+
|
70
|
+
def season_id
|
71
|
+
@season_id ||= @raw_data[:seasonId].to_i
|
72
|
+
end
|
73
|
+
|
74
|
+
def htv_game_id
|
75
|
+
@htv_game_id ||= @raw_data[:htvGameId]
|
76
|
+
end
|
77
|
+
|
78
|
+
def datetime
|
79
|
+
@datetime ||= @raw_data[:GameDateISO8601]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|