Skip to content

Commit

Permalink
football end situation
Browse files Browse the repository at this point in the history
  • Loading branch information
phoffer committed Jul 10, 2017
1 parent 6bbe28b commit 95f70f9
Show file tree
Hide file tree
Showing 11 changed files with 4,003 additions and 19 deletions.
1 change: 1 addition & 0 deletions lib/sportradar/api/football.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require "sportradar/api/football/quarter"
require "sportradar/api/football/drive"
require "sportradar/api/football/play"
require "sportradar/api/football/situation"
require "sportradar/api/football/event"

require "sportradar/api/football/ncaafb"
Expand Down
3 changes: 0 additions & 3 deletions lib/sportradar/api/football/ncaafb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ def division(code_name)
def conferences
divisions.flat_map(&:conferences)
end
def teams
conferences.flat_map(&:teams)
end

def schedule
get_schedule if games.empty?
Expand Down
6 changes: 3 additions & 3 deletions lib/sportradar/api/football/play.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def update(data, **opts)
@away_points = data['away_points'] if data['away_points']
@home_points = data['home_points'] if data['home_points']

# @end_situation = Sportradar::Api::Nfl::Situation.new data["end_situation"] if data["end_situation"]
@end_situation = Sportradar::Api::Football::Situation.new(data["end_situation"]) if data["end_situation"]
@start_situation = Sportradar::Api::Football::Situation.new(data["start_situation"]) if data["start_situation"]

@team_id = end_situation.team_id if end_situation
@home_points = data["home_points"]
@play_clock = data["play_clock"]
@reference = data["reference"]
@score = data["score"]
Expand All @@ -43,7 +44,6 @@ def update(data, **opts)
@sequence = data["sequence"] if data["sequence"]


# @start_situation = Sportradar::Api::Nfl::Situation.new data["start_situation"] if data["start_situation"]
# @statistics = Sportradar::Api::Nfl::PlayStatistics.new data["statistics"] if data["statistics"]
# parse_player if @statistics
@wall_clock = data["wall_clock"]
Expand Down
20 changes: 20 additions & 0 deletions lib/sportradar/api/football/situation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Sportradar
module Api
module Football
class Situation < Data
attr_accessor :response, :clock, :down, :yfd, :possession, :location, :team_id

def initialize(data)
@response = data
@clock = data["clock"]
@down = data["down"]
@yfd = data["yfd"]
@possession = OpenStruct.new(data["possession"]) if data["possession"]
@location = OpenStruct.new(data["location"]) if data["location"]
@team_id = possession.id if possession
end

end
end
end
end
45 changes: 45 additions & 0 deletions test/sportradar/api/football/ncaafb/game_extended_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class Sportradar::Api::Football::Ncaafb::GameExtendedTest < Minitest::Test

# ESPN box: http://www.espn.com/college-football/boxscore?gameId=400869167
# ESPN pbp: http://www.espn.com/college-football/playbyplay?gameId=400869167
def setup
data = {"id"=>"f8ac7454-980d-496a-99af-5824d5f3eea2",
"scheduled"=>"2016-11-26T02:30:00+00:00",
"coverage"=>"full",
"home_rotation"=>"",
"away_rotation"=>"",
"home"=>"ARI",
"away"=>"ASU",
"year"=>2016,
"type"=>'REG',
"week_number"=>13,
}
@game = Sportradar::Api::Football::Ncaafb::Game.new(data)
VCR.use_cassette("ncaafb/game/extended_regulation") do
@game.get_extended_box
@home_id = @game.home_alias
@away_id = @game.away_alias
end
end

# def test_ncaafb_game_summary
# assert_equal 4, @game.quarters.size
# assert_equal 34, @game.drives.size
# assert_equal 228, @game.plays.size
# end

# def test_ncaafb_game_play_timing
# assert @game.plays.all?(&:clock)
# end

# def test_ncaafb_game_plays_have_required_attributes
# assert @game.plays.all?(&:description)
# end

def test_ncaafb_game_has_score
assert_equal ({"ARI"=>56, "ASU"=>35}), @game.score
end

end
45 changes: 45 additions & 0 deletions test/sportradar/api/football/ncaafb/game_summary_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'test_helper'

class Sportradar::Api::Football::Ncaafb::GameSummaryTest < Minitest::Test

# ESPN box: http://www.espn.com/college-football/boxscore?gameId=400869167
# ESPN pbp: http://www.espn.com/college-football/playbyplay?gameId=400869167
def setup
data = {"id"=>"f8ac7454-980d-496a-99af-5824d5f3eea2",
"scheduled"=>"2016-11-26T02:30:00+00:00",
"coverage"=>"full",
"home_rotation"=>"",
"away_rotation"=>"",
"home"=>"ARI",
"away"=>"ASU",
"year"=>2016,
"type"=>'REG',
"week_number"=>13,
}
@game = Sportradar::Api::Football::Ncaafb::Game.new(data)
VCR.use_cassette("ncaafb/game/summary_regulation") do
@game.get_summary
@home_id = @game.home_alias
@away_id = @game.away_alias
end
end

# def test_ncaafb_game_summary
# assert_equal 4, @game.quarters.size
# assert_equal 34, @game.drives.size
# assert_equal 228, @game.plays.size
# end

# def test_ncaafb_game_play_timing
# assert @game.plays.all?(&:clock)
# end

# def test_ncaafb_game_plays_have_required_attributes
# assert @game.plays.all?(&:description)
# end

def test_ncaafb_game_has_score
assert_equal ({"ARI"=>56, "ASU"=>35}), @game.score
end

end
62 changes: 49 additions & 13 deletions test/sportradar/api/football/ncaafb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,79 @@ class Sportradar::Api::Football::NcaafbTest < Minitest::Test

def setup
@ncaafb = Sportradar::Api::Football::Ncaafb.new
VCR.use_cassette("ncaafb/league") do
@ncaafb.get_hierarchy
# @ncaafb.get_schedule
# @ncaafb.get_standings
end
end

def test_it_has_divisions
VCR.use_cassette("ncaafb/league/hierarchy") do
@ncaafb.get_hierarchy
end
assert_equal 1, @ncaafb.divisions.size
assert_instance_of Sportradar::Api::Football::Ncaafb::Division, @ncaafb.divisions.first
end

def test_it_has_conferences
VCR.use_cassette("ncaafb/league/hierarchy") do
@ncaafb.get_hierarchy
end
assert_equal 11, @ncaafb.conferences.size
assert_instance_of Sportradar::Api::Football::Ncaafb::Conference, @ncaafb.conferences.first
end

def test_it_has_teams
VCR.use_cassette("ncaafb/league/hierarchy") do
@ncaafb.get_hierarchy
end
assert_equal 130, @ncaafb.teams.size
assert_instance_of Sportradar::Api::Football::Ncaafb::Team, @ncaafb.teams.first
end

# def test_it_has_games
# assert_equal 256, @ncaafb.games.size
# assert_instance_of Sportradar::Api::Football::Ncaafb::Game, @ncaafb.games.first
# end
def test_it_retrieves_teams_if_necessary
VCR.use_cassette("ncaafb/league/hierarchy") do
assert_equal 0, @ncaafb.divisions.size
assert_equal 0, @ncaafb.conferences.size
assert_equal 130, @ncaafb.teams.size
assert_equal 1, @ncaafb.divisions.size
assert_equal 11, @ncaafb.conferences.size
end
end

def test_it_has_games
@ncaafb.update('season' => 2016)
VCR.use_cassette("ncaafb/league/schedule_2016") do
@ncaafb.get_schedule
end
assert_equal 1561, @ncaafb.games.size
assert_instance_of Sportradar::Api::Football::Ncaafb::Game, @ncaafb.games.first
end

# def test_it_has_weeks
# assert_equal 17, @ncaafb.weeks.size
# assert_instance_of Sportradar::Api::Football::Ncaafb::Week, @ncaafb.weeks.first
# end
def test_it_retrieves_games_if_necessary
VCR.use_cassette("ncaafb/league/schedule_2016") do
assert_equal 0, @ncaafb.weeks.size
assert_equal 1561, @ncaafb.games.size
assert_equal 20, @ncaafb.weeks.size
end
end

def test_it_has_weeks
@ncaafb.update('season' => 2016)
VCR.use_cassette("ncaafb/league/schedule_2016") do
@ncaafb.get_schedule
end
assert_equal 20, @ncaafb.weeks.size
assert_instance_of Sportradar::Api::Football::Ncaafb::Week, @ncaafb.weeks.first
end

def test_teams_have_venues
VCR.use_cassette("ncaafb/league/hierarchy") do
@ncaafb.get_hierarchy
end
assert_instance_of Sportradar::Api::Football::Venue, @ncaafb.teams.first.venue
end

def test_teams_have_required_attributes
VCR.use_cassette("ncaafb/league/hierarchy") do
@ncaafb.get_hierarchy
end
attributes = %i[id name market full_name]
assert @ncaafb.teams.all? { |team| attributes.all? { |att| team.send(att)} }
end
Expand Down
89 changes: 89 additions & 0 deletions test/vcr/cassettes/ncaafb/game/extended_regulation.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 95f70f9

Please sign in to comment.