Ejemplo n.º 1
0
    def test_invalid_url_returns_none(self, *args, **kwargs):
        mock_id = PropertyMock(return_value='BAD')
        player = Player(None)
        type(player)._player_id = mock_id

        result = player._retrieve_html_page()

        assert result is None
Ejemplo n.º 2
0
    def test_missing_weight_returns_none(self, *args, **kwargs):
        mock_weight = PropertyMock(return_value=None)
        player = Player(None)
        type(player)._player_id = mock_weight

        result = player.weight

        assert result is None
Ejemplo n.º 3
0
    def test_attempted_passes_has_deprecation_warning(self, *args, **kwargs):
        mock_passes = PropertyMock(return_value=[32])
        mock_index = PropertyMock(return_value=0)
        player = Player(None)
        type(player)._pass_attempts = mock_passes
        type(player)._index = mock_index

        with pytest.deprecated_call():
            result = player.attempted_passes

            assert result == 32
Ejemplo n.º 4
0
    def test_ncaaf_kicker_returns_expected_kicking_stats(self):
        stats = {
            'extra_points_made': 91,
            'extra_points_attempted': 92,
            'extra_point_percentage': 98.9,
            'field_goals_made': 33,
            'field_goals_attempted': 45,
            'field_goal_percentage': 73.3,
        }

        player = Player('jd-dillinger-1')

        assert player.name == 'J.D. Dillinger'
        for attribute, value in stats.items():
            assert getattr(player, attribute) == value
Ejemplo n.º 5
0
    def setup_method(self, *args, **kwargs):
        self.results_career = {
            'adjusted_yards_per_attempt': 6.1,
            'assists_on_tackles': 1,
            'attempted_passes': 1118,
            'completed_passes': 669,
            'extra_points_made': 0,
            'field_goals_made': 0,
            'fumbles_forced': 0,
            'fumbles_recovered': 0,
            'fumbles_recovered_for_touchdown': None,
            'games': None,
            'height': '6-1',
            'interceptions': 0,
            'interceptions_returned_for_touchdown': 0,
            'interceptions_thrown': 34,
            'kickoff_return_touchdowns': 0,
            'name': 'David Blough',
            'other_touchdowns': None,
            'passes_defended': 0,
            'passing_completion': 59.8,
            'passing_touchdowns': 51,
            'passing_yards_per_attempt': 6.6,
            'player_id': 'david-blough-1',
            'plays_from_scrimmage': 222,
            'points': 72,
            'position': 'QB',
            'punt_return_touchdowns': 0,
            'quarterback_rating': 124.0,
            'receiving_touchdowns': 0,
            'receiving_yards': 41,
            'receiving_yards_per_reception': 13.7,
            'receptions': 3,
            'rush_attempts': 219,
            'rush_touchdowns': 12,
            'rush_yards': 275,
            'rush_yards_per_attempt': 1.3,
            'rushing_and_receiving_touchdowns': 12,
            'sacks': 0.0,
            'safeties': None,
            'season': 'Career',
            'solo_tackles': 1,
            'tackles_for_loss': 0.0,
            'team_abbreviation': 'Purdue',
            'total_tackles': 2,
            'total_touchdowns': 12,
            'two_point_conversions': None,
            'weight': 205,
            'yards_from_scrimmage': 316,
            'yards_from_scrimmage_per_play': 1.4,
            'yards_recovered_from_fumble': None,
            'yards_returned_from_interceptions': 0,
            'yards_returned_per_interception': None,
            'year': ''
        }

        self.results_2017 = {
            'adjusted_yards_per_attempt': 7.0,
            'assists_on_tackles': 1,
            'attempted_passes': 157,
            'completed_passes': 102,
            'extra_points_made': 0,
            'field_goals_made': 0,
            'fumbles_forced': 0,
            'fumbles_recovered': 0,
            'fumbles_recovered_for_touchdown': None,
            'games': 9,
            'height': '6-1',
            'interceptions': 0,
            'interceptions_returned_for_touchdown': 0,
            'interceptions_thrown': 4,
            'kickoff_return_touchdowns': 0,
            'name': 'David Blough',
            'other_touchdowns': None,
            'passes_defended': 0,
            'passing_completion': 65.0,
            'passing_touchdowns': 9,
            'passing_yards_per_attempt': 7.0,
            'player_id': 'david-blough-1',
            'plays_from_scrimmage': 43,
            'points': 12,
            'position': 'QB',
            'punt_return_touchdowns': 0,
            'quarterback_rating': 137.8,
            'receiving_touchdowns': 0,
            'receiving_yards': 24,
            'receiving_yards_per_reception': 24.0,
            'receptions': 1,
            'rush_attempts': 42,
            'rush_touchdowns': 2,
            'rush_yards': 103,
            'rush_yards_per_attempt': 2.5,
            'rushing_and_receiving_touchdowns': 2,
            'sacks': 0.0,
            'safeties': None,
            'season': '2017',
            'solo_tackles': 0,
            'tackles_for_loss': 0.0,
            'team_abbreviation': 'Purdue',
            'total_tackles': 1,
            'total_touchdowns': 2,
            'two_point_conversions': None,
            'weight': 205,
            'yards_from_scrimmage': 127,
            'yards_from_scrimmage_per_play': 3.0,
            'yards_recovered_from_fumble': None,
            'yards_returned_from_interceptions': 0,
            'yards_returned_per_interception': None,
            'year': 'JR'
        }

        self.player = Player('david-blough-1')
Ejemplo n.º 6
0
    def test_ncaaf_404_returns_none_for_different_season(self):
        player = Player('bad')
        player = player('2017')

        assert player.name is None
        assert player.dataframe is None
Ejemplo n.º 7
0
    def test_ncaaf_404_returns_none_with_no_errors(self):
        player = Player('bad')

        assert player.name is None
        assert player.dataframe is None
Ejemplo n.º 8
0
    def test_ncaaf_tight_end_skips_passing_without_errors(self):
        player = Player('brycen-hopkins-1')

        assert player.name == 'Brycen Hopkins'
        assert player.dataframe is not None
Ejemplo n.º 9
0
from sportsreference.ncaaf.roster import Player

import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt

#Create each player based on the player class through each Player's player_id
TLawrence = Player('trevor-lawrence-1')
JFields = Player('justin-fields-2')
SEhlinger = Player('sam-ehlinger-1')
SHowell = Player('sam-howell-1')
JDaniels = Player('jayden-daniels-1')

#Set the previous season (This can be adjusted to current season while in mid season)
TLawrence('2019')
JFields('2019')
SEhlinger('2019')
SHowell('2019')
JDaniels('2019')

#Calculate the players touchdown efficiency rate
TLawTDperPA = float(TLawrence.passing_touchdowns)/float(TLawrence.attempted_passes)
JFieTDperPA = float(JFields.passing_touchdowns)/float(JFields.attempted_passes)
SEhlTDperPA = float(SEhlinger.passing_touchdowns)/float(SEhlinger.attempted_passes)
SHowTDperPA = float(SHowell.passing_touchdowns)/float(SHowell.attempted_passes)
JDanTDperPA = float(JDaniels.passing_touchdowns)/float(JDaniels.attempted_passes)


#Display the Players and their stats
print ("Player Name| Touchdowns | Pass attempts | Touchdown per Pass attempt")
print(TLawrence.name, TLawrence.passing_touchdowns, TLawrence.attempted_passes, "{:10.4f}".format(TLawTDperPA))
from sportsreference.ncaaf.roster import Player
import pandas
     #dataframe that stores info from csv file
df = pandas.read_csv('../data/all_qb_names.csv')

for index, row in df.iterrows():
    num = 1
    name = (row['Name'])
    #string manipulation
    name = name.lower()
    name = name.replace(" ", "-")
    name = name + "-" + str(num)
    player = Player(name)
    while True:

        try:
            if (player.position == "QB"):
                #write player to csv file
                player.dataframe.to_csv("dataFolder/NCAA_player_csv/" + player.name + ".csv")
                print("wriiten")
                break
            else:
                num = num + 1
                name = (row['Name'])
                # string manipulation
                name = name.lower()
                name = name.replace(" ", "-")
                name = name + "-" + str(num)
                player = Player(name)
        except:
              print("Player does not have dataFrame")