sportradar 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 202921746ff050363217329a5111ba933f8f6cf5
4
- data.tar.gz: aae5ca8f2adef22476692a130e321b24514822dc
3
+ metadata.gz: d618af8c09b32a16644cd1673b14d728bbedbf05
4
+ data.tar.gz: 1aba7b631b32a205df2391746fc96eb1021393c7
5
5
  SHA512:
6
- metadata.gz: 933fdaecc9a801adc7c694cad788d686c284f029a9077707ea641569d76bc261fcecf6f6773fe20f6a0eba62b2b4e2fde5bc25a5c23084ffa61b0013ab28fdaa
7
- data.tar.gz: 8c59229af0c8f3d938380aa2d1bf25db50733c6fbfeba051aa5e4b6866ef89ae54a36ef26f63d4026bd6c68561ea82b71559fe2b9b6367406f02491995bc128b
6
+ metadata.gz: ec6e864fab845c50b3f52fd21988b384c63801872f6acd95cf7c92ae39007a768af3241c0d5cd9e9b78f536899a71d663137d32d6518430119ecfc86ca3020ce
7
+ data.tar.gz: 4e4f27be1b02dd699d46b7fcc5b2eaba33b18f31173a393abe461d1e4a6ebd6235f0187f16ba814da23e6cbfbf1d4bc78bbfeb40014c0ca5f477d55f595f5936
data/lib/sportradar.rb CHANGED
@@ -52,6 +52,8 @@ require 'sportradar/mlb/team_rosters'
52
52
  require 'sportradar/mlb/team_statistics'
53
53
  require 'sportradar/mlb/venues'
54
54
 
55
+ require 'sportradar/nba/parsers/boxscore_parser'
56
+
55
57
  require 'sportradar/nba/daily_schedule'
56
58
  require 'sportradar/nba/league_hierarchy'
57
59
  require 'sportradar/nba/league_schedule'
@@ -0,0 +1,225 @@
1
+ module Sportradar
2
+ module Nba
3
+ module Parsers
4
+ class BoxscoreParser
5
+ def initialize(json: {})
6
+ @json = json['game'] || json
7
+ end
8
+
9
+ def game_id
10
+ json['id']
11
+ end
12
+
13
+ def attendance
14
+ json['attendance']
15
+ end
16
+
17
+ def period
18
+ json['quarter'].to_i
19
+ end
20
+
21
+ def scheduled_at
22
+ json['scheduled'] && json['scheduled'].to_datetime
23
+ end
24
+ alias_method :started_at, :scheduled_at
25
+
26
+ def ended_at
27
+ if over?
28
+ scheduled_at + duration_secs.seconds
29
+ end
30
+ end
31
+ alias_method :completed, :ended_at
32
+
33
+ def over?
34
+ status == 'closed'
35
+ end
36
+
37
+ def status
38
+ json['status']
39
+ end
40
+
41
+ def lead_changes
42
+ json['lead_changes'] || 0
43
+ end
44
+
45
+ def times_tied
46
+ json['times_tied'] || 0
47
+ end
48
+
49
+ def clock
50
+ json['clock']
51
+ end
52
+
53
+ def clock_attributes
54
+ {
55
+ clock: clock,
56
+ clock_secs: clock_secs,
57
+ duration: duration_secs,
58
+ period: period,
59
+ ended_at: ended_at,
60
+ status: status,
61
+ lead_changes: lead_changes,
62
+ times_tied: times_tied,
63
+ }.compact
64
+ end
65
+
66
+ def clock_secs
67
+ begin
68
+ if clock && clock.include?(':')
69
+ mins, secs = clock.split(':').map(&:to_i)
70
+ Time.parse("00:#{mins}:#{secs}").
71
+ seconds_since_midnight.to_i
72
+ end
73
+ rescue => e
74
+ puts e
75
+ return 0
76
+ end
77
+ end
78
+
79
+ def duration
80
+ json['duration']
81
+ end
82
+
83
+ def duration_secs
84
+ begin
85
+ if duration && duration.include?(':')
86
+ hours, mins = duration.split(':').map(&:to_i)
87
+ Time.parse("#{hours}:#{mins}:00").
88
+ seconds_since_midnight.to_i
89
+ end
90
+ rescue => e
91
+ return 0
92
+ end
93
+ end
94
+
95
+ def home_team_json
96
+ json['home'] || {}
97
+ end
98
+
99
+ def home_team_id
100
+ home_team_json['id']
101
+ end
102
+
103
+ def home_team_scoring_data
104
+ home_team_json['scoring'] || []
105
+ end
106
+
107
+ def home_team_scoring
108
+ {
109
+ points_scored_total: home_team_json['points'],
110
+ }.merge(home_team_scoring_quarters).
111
+ compact
112
+ end
113
+
114
+ def home_team_scoring_quarters
115
+ team_scoring_quarters(data: home_team_scoring_data)
116
+ end
117
+
118
+ def away_team_json
119
+ json['away'] || {}
120
+ end
121
+
122
+ def away_team_id
123
+ away_team_json['id']
124
+ end
125
+
126
+ def away_team_scoring_data
127
+ away_team_json['scoring'] || []
128
+ end
129
+
130
+ def away_team_scoring
131
+ {
132
+ points_scored_total: away_team_json['points'],
133
+ }.merge(away_team_scoring_quarters).
134
+ compact
135
+ end
136
+
137
+ def away_team_scoring_quarters
138
+ team_scoring_quarters(data: away_team_scoring_data)
139
+ end
140
+
141
+ def team_scoring_quarters(data:)
142
+ {}.tap do |scoring_quarters|
143
+ overtime_points = 0
144
+ scoring_quarters[:points_overtime] = overtime_points
145
+
146
+ data.map do |scoring_data|
147
+ if quarter = scoring_data['number'].to_i
148
+ if quarter > 0 && quarter <= 4
149
+ key = "points_quarter_#{quarter}".to_sym
150
+ scoring_quarters[key] =
151
+ scoring_data['points'].to_i
152
+ elsif quarter > 4
153
+ quarter_type = (scoring_data['type'] || 'quarter').downcase
154
+ if quarter_type == 'overtime'
155
+ key = "points_#{quarter_type}_#{scoring_data['number'].to_i}".to_sym
156
+ scoring_quarters[key] =
157
+ scoring_data['points'].to_i
158
+ overtime_points += scoring_data['points'].to_i
159
+ scoring_quarters[:points_overtime] = overtime_points
160
+ end
161
+ end
162
+ end
163
+ end
164
+ scoring_quarters[:points_overtime] = overtime_points
165
+ end
166
+ end
167
+
168
+ def game_scoring_attributes
169
+ {
170
+ attendance: attendance,
171
+ home_team_outcome: home_team_outcome,
172
+ home_team_score: home_team_score,
173
+ away_team_outcome: away_team_outcome,
174
+ away_team_score: away_team_score,
175
+ }
176
+ end
177
+
178
+ def home_team_score
179
+ home_team_scoring[:points_scored_total] || 0
180
+ end
181
+
182
+ def home_team_outcome
183
+ if over?
184
+ if home_team_score > away_team_score
185
+ 'win'
186
+ elsif home_team_score < away_team_score
187
+ 'loss'
188
+ else
189
+ 'tie'
190
+ end
191
+ else
192
+ 'undecided'
193
+ end
194
+ end
195
+
196
+ def away_team_score
197
+ away_team_scoring[:points_scored_total] || 0
198
+ end
199
+
200
+ def away_team_outcome
201
+ if over?
202
+ if home_team_score < away_team_score
203
+ 'win'
204
+ elsif home_team_score > away_team_score
205
+ 'loss'
206
+ else
207
+ 'tie'
208
+ end
209
+ else
210
+ 'undecided'
211
+ end
212
+ end
213
+
214
+ def game_attributes
215
+ clock_attributes.merge(game_scoring_attributes).
216
+ compact
217
+ end
218
+
219
+ private
220
+
221
+ attr_reader :json
222
+ end
223
+ end
224
+ end
225
+ end
@@ -138,7 +138,7 @@ module Sportradar
138
138
  scoring_periods[:goals_shootout] = 0
139
139
 
140
140
  data.map do |scoring_data|
141
- if period = scoring_data['sequence'].to_i
141
+ if period = scoring_data['number'].to_i
142
142
  if period > 0 && period <= 3
143
143
  key = "goals_period_#{period}".to_sym
144
144
  scoring_periods[key] =
@@ -1,3 +1,3 @@
1
1
  module Sportradar
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportradar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stattleship
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-10-14 00:00:00.000000000 Z
12
+ date: 2016-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -206,6 +206,7 @@ files:
206
206
  - lib/sportradar/nba/injuries.rb
207
207
  - lib/sportradar/nba/league_hierarchy.rb
208
208
  - lib/sportradar/nba/league_schedule.rb
209
+ - lib/sportradar/nba/parsers/boxscore_parser.rb
209
210
  - lib/sportradar/nba/play_by_play.rb
210
211
  - lib/sportradar/nba/team_roster.rb
211
212
  - lib/sportradar/nba/team_rosters.rb