Class: Sportradar::Api::Football::Nfl

Inherits:
Data
  • Object
show all
Defined in:
lib/sportradar/api/football/nfl.rb,
lib/sportradar/api/football/nfl/api.rb,
lib/sportradar/api/football/nfl/game.rb,
lib/sportradar/api/football/nfl/play.rb,
lib/sportradar/api/football/nfl/team.rb,
lib/sportradar/api/football/nfl/week.rb,
lib/sportradar/api/football/nfl/drive.rb,
lib/sportradar/api/football/nfl/event.rb,
lib/sportradar/api/football/nfl/player.rb,
lib/sportradar/api/football/nfl/quarter.rb,
lib/sportradar/api/football/nfl/division.rb,
lib/sportradar/api/football/nfl/conference.rb,
lib/sportradar/api/football/nfl/depth_chart.rb,
lib/sportradar/api/football/nfl/team_depth_chart.rb,
lib/sportradar/api/football/nfl/league_depth_chart.rb

Defined Under Namespace

Classes: Api, Conference, DepthChart, Division, Drive, Event, Game, LeagueDepthChart, Play, Player, Quarter, Team, TeamDepthChart, Week

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Data

#attributes, #create_data, #parse_into_array, #parse_into_array_with_options, #parse_out_hashes, #structure_links, #update_data

Constructor Details

#initialize(data = {}, **opts) ⇒ Nfl

Returns a new instance of Nfl.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sportradar/api/football/nfl.rb', line 10

def initialize(data = {}, **opts)
  # @response = data
  @api  = opts[:api]
  @id   = data['id']
  @season = opts[:year]
  @type   = opts[:type]

  @conferences_hash   = {}
  @weeks_hash         = {}
  @depth_charts_hash  = {}
  # @injuries_hash      = {}
  @games_hash         = {}
  @teams_hash         = {}

end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



5
6
7
# File 'lib/sportradar/api/football/nfl.rb', line 5

def alias
  @alias
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sportradar/api/football/nfl.rb', line 5

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sportradar/api/football/nfl.rb', line 5

def name
  @name
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/sportradar/api/football/nfl.rb', line 5

def response
  @response
end

#season=(value) ⇒ Object

Sets the attribute season

Parameters:

  • value

    the value to set the attribute season to.



5
6
7
# File 'lib/sportradar/api/football/nfl.rb', line 5

def season=(value)
  @season = value
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/sportradar/api/football/nfl.rb', line 5

def type
  @type
end

Class Method Details

.sim_apiObject

def queue_venues

url, headers, options, timeout = api.get_request_info(path_venues)
{url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_venues)}

end



288
289
290
# File 'lib/sportradar/api/football/nfl.rb', line 288

def self.sim_api
  Sportradar::Api::Football::Nfl::Api.new.sim!
end

.simulationObject



291
292
293
# File 'lib/sportradar/api/football/nfl.rb', line 291

def self.simulation
  new({}, api: sim_api, year: 2015, type: 'reg')
end

.simulationsObject



294
295
296
297
298
299
# File 'lib/sportradar/api/football/nfl.rb', line 294

def self.simulations
  api = sim_api
  ['f45b4a31-b009-4039-8394-42efbc6d5532', '5a7042cb-fe7a-4838-b93f-6b8c167ec384', '7f761bb5-7963-43ea-a01b-baf4f5d50fe3'].map do |game_id|
    Game.new({'id' => game_id}).sim!
  end
end

Instance Method Details

#all_attributesObject



6
7
8
# File 'lib/sportradar/api/football/nfl.rb', line 6

def all_attributes
  [:name, :alias, :leagues, :divisions, :teams]
end

#apiObject

api stuff



125
126
127
# File 'lib/sportradar/api/football/nfl.rb', line 125

def api
  @api || Sportradar::Api::Football::Nfl::Api.new
end

#conferencesObject



71
72
73
# File 'lib/sportradar/api/football/nfl.rb', line 71

def conferences
  @conferences_hash.values
end

#default_dateObject



132
133
134
# File 'lib/sportradar/api/football/nfl.rb', line 132

def default_date
  Date.today
end

#default_seasonObject



135
136
137
# File 'lib/sportradar/api/football/nfl.rb', line 135

def default_season
  'reg'
end

#default_yearObject



129
130
131
# File 'lib/sportradar/api/football/nfl.rb', line 129

def default_year
  (Date.today - 60).year
end

#divisionsObject

def conference(code_name)

conferences_by_name[code_name]

end private def conferences_by_name

@conferences_by_name ||= conferences.map { |d| [d.alias, d] }.to_h

end



80
81
82
# File 'lib/sportradar/api/football/nfl.rb', line 80

def divisions
  conferences.flat_map(&:divisions)
end

#gamesObject



102
103
104
105
# File 'lib/sportradar/api/football/nfl.rb', line 102

def games
  get_schedule if @weeks_hash.empty?
  weeks.flat_map(&:games)
end

#get_depth_chartsObject

depth_charts



239
240
241
242
# File 'lib/sportradar/api/football/nfl.rb', line 239

def get_depth_charts
  data = api.get_data(path_depth_charts).to_h
  ingest_depth_charts(data)
end

#get_hierarchyObject

hierarchy



222
223
224
225
# File 'lib/sportradar/api/football/nfl.rb', line 222

def get_hierarchy
  data = api.get_data(path_hierarchy).to_h
  ingest_hierarchy(data)
end

#get_scheduleObject

schedule



174
175
176
177
# File 'lib/sportradar/api/football/nfl.rb', line 174

def get_schedule
  data = api.get_data(path_schedule).to_h
  ingest_schedule(data)
end

#get_standingsObject

standings



255
256
257
258
# File 'lib/sportradar/api/football/nfl.rb', line 255

def get_standings
  data = api.get_data(path_standings).to_h
  ingest_standings(data)
end

#get_weekly_schedule(nfl_season_week = 1) ⇒ Object

weekly schedule



190
191
192
193
# File 'lib/sportradar/api/football/nfl.rb', line 190

def get_weekly_schedule(nfl_season_week = 1)
  data = api.get_data(path_weekly_schedule(nfl_season_week)).to_h
  ingest_weekly_schedule(data)
end

#hierarchyObject



97
98
99
100
# File 'lib/sportradar/api/football/nfl.rb', line 97

def hierarchy
  get_hierarchy if divisions.empty?
  self
end

#ingest_depth_charts(data) ⇒ Object



244
245
246
247
# File 'lib/sportradar/api/football/nfl.rb', line 244

def ingest_depth_charts(data)
  update(data, source: :teams)
  data
end

#ingest_hierarchy(data) ⇒ Object



227
228
229
230
231
# File 'lib/sportradar/api/football/nfl.rb', line 227

def ingest_hierarchy(data)
  # create_data(@divisions_hash, data, klass: Division,  hierarchy: self, api: api)
  update(data, source: :teams)
  data
end

#ingest_schedule(data) ⇒ Object



179
180
181
182
# File 'lib/sportradar/api/football/nfl.rb', line 179

def ingest_schedule(data)
  update(data, source: :weeks)
  data
end

#ingest_standings(data) ⇒ Object



260
261
262
263
# File 'lib/sportradar/api/football/nfl.rb', line 260

def ingest_standings(data)
  update(data, source: :teams)
  data
end

#ingest_weekly_schedule(data) ⇒ Object



195
196
197
198
199
# File 'lib/sportradar/api/football/nfl.rb', line 195

def ingest_weekly_schedule(data)
  # update(data, source: :weeks)
  create_data(@weeks_hash, data['week'], klass: Week, hierarchy: self, api: api)
  data
end

#nfl_seasonObject Also known as: season



142
143
144
# File 'lib/sportradar/api/football/nfl.rb', line 142

def nfl_season
  @type || default_season
end

#path_baseObject

url paths



149
150
151
# File 'lib/sportradar/api/football/nfl.rb', line 149

def path_base
  "league"
end

#path_hierarchyObject



152
153
154
# File 'lib/sportradar/api/football/nfl.rb', line 152

def path_hierarchy
  "league/hierarchy"
end

#path_scheduleObject



155
156
157
# File 'lib/sportradar/api/football/nfl.rb', line 155

def path_schedule
  "games/#{season_year}/#{nfl_season}/schedule"
end

#path_standingsObject



167
168
169
# File 'lib/sportradar/api/football/nfl.rb', line 167

def path_standings
  "seasontd/#{season_year}/standings"
end

#path_weekly_depth_charts(nfl_season_week) ⇒ Object



161
162
163
# File 'lib/sportradar/api/football/nfl.rb', line 161

def path_weekly_depth_charts(nfl_season_week)
  "seasontd/#{season_year}/#{nfl_season}/#{nfl_season_week}/depth_charts"
end

#path_weekly_depth_injuries(nfl_season_week) ⇒ Object



164
165
166
# File 'lib/sportradar/api/football/nfl.rb', line 164

def path_weekly_depth_injuries(nfl_season_week)
  "seasontd/#{season_year}/#{nfl_season}/#{nfl_season_week}/injuries"
end

#path_weekly_schedule(nfl_season_week) ⇒ Object



158
159
160
# File 'lib/sportradar/api/football/nfl.rb', line 158

def path_weekly_schedule(nfl_season_week)
  "games/#{season_year}/#{nfl_season}/#{nfl_season_week}/schedule"
end

#queue_depth_chartsObject



249
250
251
252
# File 'lib/sportradar/api/football/nfl.rb', line 249

def queue_depth_charts
  url, headers, options, timeout = api.get_request_info(path_depth_charts)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_depth_charts)}
end

#queue_hierarchyObject



233
234
235
236
# File 'lib/sportradar/api/football/nfl.rb', line 233

def queue_hierarchy
  url, headers, options, timeout = api.get_request_info(path_hierarchy)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_hierarchy)}
end

#queue_scheduleObject



184
185
186
187
# File 'lib/sportradar/api/football/nfl.rb', line 184

def queue_schedule
  url, headers, options, timeout = api.get_request_info(path_schedule)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_schedule)}
end

#queue_standingsObject



265
266
267
268
# File 'lib/sportradar/api/football/nfl.rb', line 265

def queue_standings
  url, headers, options, timeout = api.get_request_info(path_standings)
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_standings)}
end

#queue_weekly_schedule(nfl_season_week = 1) ⇒ Object



201
202
203
204
# File 'lib/sportradar/api/football/nfl.rb', line 201

def queue_weekly_schedule(nfl_season_week = 1)
  url, headers, options, timeout = api.get_request_info(path_weekly_schedule(nfl_season_week))
  {url: url, headers: headers, params: options, timeout: timeout, callback: method(:ingest_weekly_schedule)}
end

#scheduleObject



87
88
89
90
# File 'lib/sportradar/api/football/nfl.rb', line 87

def schedule
  get_schedule if games.empty?
  self
end

#season_yearObject Also known as: year



138
139
140
# File 'lib/sportradar/api/football/nfl.rb', line 138

def season_year
  @season || default_year
end

#standingsObject



92
93
94
95
# File 'lib/sportradar/api/football/nfl.rb', line 92

def standings
  get_standings if divisions.empty? || teams.first&.record.nil?
  self
end

#team(team_id) ⇒ Object



120
121
122
# File 'lib/sportradar/api/football/nfl.rb', line 120

def team(team_id)
  teams.detect { |team| team.id == team_id }
end

#teamsObject



83
84
85
# File 'lib/sportradar/api/football/nfl.rb', line 83

def teams
  divisions.flat_map(&:teams)
end

#update(data, source: nil, **opts) ⇒ Object



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
# File 'lib/sportradar/api/football/nfl.rb', line 26

def update(data, source: nil, **opts)
  # update stuff
  @id     = data['id'] if data['id']
  if data['season'].is_a?(Hash)
    @season = data.dig('season', 'year')  if data.dig('season', 'year')
    @type   = data.dig('season', 'type')  if data.dig('season', 'type')
  else
    @season = data['season']  if data['season']
    @type   = data['type']    if data['type']
  end
  # @name     = data.dig('league', 'name')  if data.dig('league', 'name')
  # @alias    = data.dig('league', 'alias') if data.dig('league', 'alias')

  # @year     = data.dig('season', 'year')  if data.dig('season', 'year')
  # @type     = data.dig('season', 'type')  if data.dig('season', 'type')

  create_data(@conferences_hash,  data['conferences'],  klass: Conference,  hierarchy: self, api: api) if data['conferences']
  create_data(@teams_hash,        data['teams'],        klass: Team,        hierarchy: self, api: api) if data['teams']

  if data['weeks']
    create_data(@weeks_hash, data['weeks'], klass: Week, hierarchy: self, api: @api)
  end
  if data['league']
    @id    = data['id']
    @name  = data['name']
    @alias = data['alias']
  end

  if data['games']
    if data['games'].first.keys == ['game']
      data['games'].map! { |hash| hash['game'] }
    end
    create_data(@games_hash, data['games'],   klass: Game,   hierarchy: self, api: api)
  end

  self
end

#weekly_depth_charts(week_number) ⇒ Object



64
65
66
# File 'lib/sportradar/api/football/nfl.rb', line 64

def weekly_depth_charts(week_number)
  @depth_charts_hash[week_number] ||= get_weekly_depth_charts(week_number)
end

#weeksObject



68
69
70
# File 'lib/sportradar/api/football/nfl.rb', line 68

def weeks
  @weeks_hash.values
end