def parse(self, totals):
     return [
         {
             "slug": str(total.slug),
             "name": str(total.name).rstrip("*"),
             "positions": self.position_abbreviation_parser.from_abbreviations(total.position_abbreviations),
             "age": str_to_int(total.age, default=None),
             "team": self.team_abbreviation_parser.from_abbreviation(total.team_abbreviation),
             "games_played": str_to_int(total.games_played),
             "minutes_played": str_to_int(total.minutes_played),
             "player_efficiency_rating": str_to_float(total.player_efficiency_rating),
             "true_shooting_percentage": str_to_float(total.true_shooting_percentage),
             "three_point_attempt_rate": str_to_float(total.three_point_attempt_rate),
             "free_throw_attempt_rate": str_to_float(total.free_throw_attempt_rate),
             "offensive_rebound_percentage": str_to_float(total.offensive_rebound_percentage),
             "defensive_rebound_percentage": str_to_float(total.defensive_rebound_percentage),
             "total_rebound_percentage": str_to_float(total.total_rebound_percentage),
             "assist_percentage": str_to_float(total.assist_percentage),
             "steal_percentage": str_to_float(total.steal_percentage),
             "block_percentage": str_to_float(total.block_percentage),
             "turnover_percentage": str_to_float(total.turnover_percentage),
             "usage_percentage": str_to_float(total.usage_percentage),
             "offensive_win_shares": str_to_float(total.offensive_win_shares),
             "defensive_win_shares": str_to_float(total.defensive_win_shares),
             "win_shares": str_to_float(total.win_shares),
             "win_shares_per_48_minutes": str_to_float(total.win_shares_per_48_minutes),
             "offensive_box_plus_minus": str_to_float(total.offensive_plus_minus),
             "defensive_box_plus_minus": str_to_float(total.defensive_plus_minus),
             "box_plus_minus": str_to_float(total.plus_minus),
             "value_over_replacement_player": str_to_float(total.value_over_replacement_player),
             "is_combined_totals": total.is_combined_totals,
         } for total in totals
     ]
def parse_player_advanced_season_total(row):
    return {
        "slug": str(row[1].get("data-append-csv")),
        "name": str(row[1].text_content()),
        "positions": parse_positions(row[2].text_content()),
        "age": str_to_int(row[3].text_content(), default=None),
        "team": TEAM_ABBREVIATIONS_TO_TEAM.get(row[4].text_content()),
        "games_played": str_to_int(row[5].text_content()),
        "minutes_played": str_to_int(row[6].text_content()),
        "player_efficiency_rating": str_to_float(row[7].text_content()),
        "true_shooting_percentage": str_to_float(row[8].text_content()),
        "three_point_attempt_rate": str_to_float(row[9].text_content()),
        "free_throw_attempt_rate": str_to_float(row[10].text_content()),
        "offensive_rebound_percentage": str_to_float(row[11].text_content()),
        "defensive_rebound_percentage": str_to_float(row[12].text_content()),
        "total_rebound_percentage": str_to_float(row[13].text_content()),
        "assist_percentage": str_to_float(row[14].text_content()),
        "steal_percentage": str_to_float(row[15].text_content()),
        "block_percentage": str_to_float(row[16].text_content()),
        "turnover_percentage": str_to_float(row[17].text_content()),
        "usage_percentage": str_to_float(row[18].text_content()),
        "offensive_win_shares": str_to_float(row[20].text_content()),
        "defensive_win_shares": str_to_float(row[21].text_content()),
        "win_shares": str_to_float(row[22].text_content()),
        "win_shares_per_48_minutes": str_to_float(row[23].text_content()),
        "offensive_box_plus_minus": str_to_float(row[25].text_content()),
        "defensive_box_plus_minus": str_to_float(row[26].text_content()),
        "box_plus_minus": str_to_float(row[27].text_content()),
        "value_over_replacement_player": str_to_float(row[28].text_content()),
    }
Exemple #3
0
def parse_game(row):
    start_time = parse_start_time(formatted_date=row[0].text_content(), formatted_time_of_day=row[1].text_content())
    return {
        "start_time": start_time,
        "away_team": TEAM_NAME_TO_TEAM.get(row[2].text_content().upper()),
        "home_team": TEAM_NAME_TO_TEAM.get(row[4].text_content().upper()),
        "away_team_score": str_to_int(row[3].text_content(), default=None),
        "home_team_score": str_to_int(row[5].text_content(), default=None),
    }
 def parse_games(self, games):
     return [
         {
             "start_time": self.start_time_parser.parse_start_time(
                 formatted_date=game.start_date,
                 formatted_time_of_day=game.start_time_of_day,
             ),
             "away_team": self.team_name_parser.parse_team_name(team_name=game.away_team_name),
             "home_team": self.team_name_parser.parse_team_name(team_name=game.home_team_name),
             "away_team_score": str_to_int(value=game.away_team_score, default=None),
             "home_team_score": str_to_int(value=game.home_team_score, default=None),
         }
         for game in games
     ]
 def parse(self, box_scores):
     return [
         {
             "date": datetime.strptime(str(box_score.date), "%Y-%m-%d").date(),
             "team": self.team_abbreviation_parser.from_abbreviation(box_score.team_abbreviation),
             "location": self.location_abbreviation_parser.from_abbreviation(box_score.location_abbreviation),
             "opponent": self.team_abbreviation_parser.from_abbreviation(box_score.opponent_abbreviation),
             "outcome": self.outcome_parser.parse_outcome(formatted_outcome=box_score.outcome),
             "seconds_played": self.seconds_played_parser.parse(box_score.playing_time),
             "made_field_goals": str_to_int(box_score.made_field_goals),
             "attempted_field_goals": str_to_int(box_score.attempted_field_goals),
             "made_three_point_field_goals": str_to_int(box_score.made_three_point_field_goals),
             "attempted_three_point_field_goals": str_to_int(box_score.attempted_three_point_field_goals),
             "made_free_throws": str_to_int(box_score.made_free_throws),
             "attempted_free_throws": str_to_int(box_score.attempted_free_throws),
             "offensive_rebounds": str_to_int(box_score.offensive_rebounds),
             "defensive_rebounds": str_to_int(box_score.defensive_rebounds),
             "assists": str_to_int(box_score.assists),
             "steals": str_to_int(box_score.steals),
             "blocks": str_to_int(box_score.blocks),
             "turnovers": str_to_int(box_score.turnovers),
             "personal_fouls": str_to_int(box_score.personal_fouls),
             "points_scored": str_to_int(box_score.points_scored),
             "game_score": str_to_float(box_score.game_score),
             "plus_minus": str_to_int(box_score.plus_minus),
         } for box_score in box_scores
         if box_score.is_active
     ]
 def parse(self, box_scores):
     return [
         {
             "slug": str(box_score.slug),
             "name": str(box_score.name).rstrip("*"),
             "team": self.team_abbreviation_parser.from_abbreviation(box_score.team_abbreviation),
             "location": self.location_abbreviation_parser.from_abbreviation(box_score.location_abbreviation),
             "opponent": self.team_abbreviation_parser.from_abbreviation(box_score.opponent_abbreviation),
             "outcome": self.outcome_abbreviation_parser.from_abbreviation(box_score.outcome),
             "seconds_played": self.seconds_played_parser.parse(box_score.playing_time),
             "made_field_goals": str_to_int(box_score.made_field_goals),
             "attempted_field_goals": str_to_int(box_score.attempted_field_goals),
             "made_three_point_field_goals": str_to_int(box_score.made_three_point_field_goals),
             "attempted_three_point_field_goals": str_to_int(box_score.attempted_three_point_field_goals),
             "made_free_throws": str_to_int(box_score.made_free_throws),
             "attempted_free_throws": str_to_int(box_score.attempted_free_throws),
             "offensive_rebounds": str_to_int(box_score.offensive_rebounds),
             "defensive_rebounds": str_to_int(box_score.defensive_rebounds),
             "assists": str_to_int(box_score.assists),
             "steals": str_to_int(box_score.steals),
             "blocks": str_to_int(box_score.blocks),
             "turnovers": str_to_int(box_score.turnovers),
             "personal_fouls": str_to_int(box_score.personal_fouls),
             "game_score": str_to_float(box_score.game_score),
         } for box_score in box_scores
     ]
    def parse_totals(self, team_totals, opposing_team_totals):
        current_team = self.team_abbreviation_parser.from_abbreviation(team_totals.team_abbreviation)

        if str_to_int(team_totals.points) > str_to_int(opposing_team_totals.points):
            outcome = Outcome.WIN
        elif str_to_int(team_totals.points) < str_to_int(opposing_team_totals.points):
            outcome = Outcome.LOSS
        else:
            outcome = None

        return {
            "team": current_team,
            "outcome": outcome,
            "minutes_played": str_to_int(team_totals.minutes_played),
            "made_field_goals": str_to_int(team_totals.made_field_goals),
            "attempted_field_goals": str_to_int(team_totals.attempted_field_goals),
            "made_three_point_field_goals": str_to_int(team_totals.made_three_point_field_goals),
            "attempted_three_point_field_goals": str_to_int(team_totals.attempted_three_point_field_goals),
            "made_free_throws": str_to_int(team_totals.made_free_throws),
            "attempted_free_throws": str_to_int(team_totals.attempted_free_throws),
            "offensive_rebounds": str_to_int(team_totals.offensive_rebounds),
            "defensive_rebounds": str_to_int(team_totals.defensive_rebounds),
            "assists": str_to_int(team_totals.assists),
            "steals": str_to_int(team_totals.steals),
            "blocks": str_to_int(team_totals.blocks),
            "turnovers": str_to_int(team_totals.turnovers),
            "personal_fouls": str_to_int(team_totals.personal_fouls),
            "points": str_to_int(team_totals.points),
        }
 def parse(self, totals):
     return [
         {
             "slug": str(total.slug),
             "name": str(total.name).rstrip("*"),
             "positions": self.position_abbreviation_parser.from_abbreviations(total.position_abbreviations),
             "age": str_to_int(total.age, default=None),
             "team": self.team_abbreviation_parser.from_abbreviation(total.team_abbreviation),
             "games_played": str_to_int(total.games_played),
             "games_started": str_to_int(total.games_started),
             "minutes_played": str_to_int(total.minutes_played),
             "made_field_goals": str_to_int(total.made_field_goals),
             "attempted_field_goals": str_to_int(total.attempted_field_goals),
             "made_three_point_field_goals": str_to_int(total.made_three_point_field_goals),
             "attempted_three_point_field_goals": str_to_int(total.attempted_three_point_field_goals),
             "made_free_throws": str_to_int(total.made_free_throws),
             "attempted_free_throws": str_to_int(total.attempted_free_throws),
             "offensive_rebounds": str_to_int(total.offensive_rebounds),
             "defensive_rebounds": str_to_int(total.defensive_rebounds),
             "assists": str_to_int(total.assists),
             "steals": str_to_int(total.steals),
             "blocks": str_to_int(total.blocks),
             "turnovers": str_to_int(total.turnovers),
             "personal_fouls": str_to_int(total.personal_fouls),
             "points": str_to_int(total.points),
         } for total in totals
     ]
Exemple #9
0
def parse_player_season_totals(row):
    return {
        "slug": str(row[1].get("data-append-csv")),
        "name": str(row[1].text_content()),
        "positions": parse_positions(row[2].text_content()),
        "age": str_to_int(row[3].text_content(), default=None),
        "team": TEAM_ABBREVIATIONS_TO_TEAM.get(row[4].text_content()),
        "games_played": str_to_int(row[5].text_content()),
        "games_started": str_to_int(row[6].text_content()),
        "minutes_played": str_to_int(row[7].text_content()),
        "made_field_goals": str_to_int(row[8].text_content()),
        "attempted_field_goals": str_to_int(row[9].text_content()),
        "made_three_point_field_goals": str_to_int(row[11].text_content()),
        "attempted_three_point_field_goals":
        str_to_int(row[12].text_content()),
        "made_free_throws": str_to_int(row[18].text_content()),
        "attempted_free_throws": str_to_int(row[19].text_content()),
        "offensive_rebounds": str_to_int(row[21].text_content()),
        "defensive_rebounds": str_to_int(row[22].text_content()),
        "assists": str_to_int(row[24].text_content()),
        "steals": str_to_int(row[25].text_content()),
        "blocks": str_to_int(row[26].text_content()),
        "turnovers": str_to_int(row[27].text_content()),
        "personal_fouls": str_to_int(row[28].text_content()),
    }
Exemple #10
0
def parse_team_total(footer, team):
    cells = footer.xpath('tr/td')
    return {
        "team": team,
        "minutes_played": str_to_int(cells[0].text_content()),
        "made_field_goals": str_to_int(cells[1].text_content()),
        "attempted_field_goals": str_to_int(cells[2].text_content()),
        "made_three_point_field_goals": str_to_int(cells[4].text_content()),
        "attempted_three_point_field_goals":
        str_to_int(cells[5].text_content()),
        "made_free_throws": str_to_int(cells[7].text_content()),
        "attempted_free_throws": str_to_int(cells[8].text_content()),
        "offensive_rebounds": str_to_int(cells[10].text_content()),
        "defensive_rebounds": str_to_int(cells[11].text_content()),
        "assists": str_to_int(cells[13].text_content()),
        "steals": str_to_int(cells[14].text_content()),
        "blocks": str_to_int(cells[15].text_content()),
        "turnovers": str_to_int(cells[16].text_content()),
        "personal_fouls": str_to_int(cells[17].text_content()),
    }
Exemple #11
0
 def test_whitespace_is_zero(self):
     self.assertEqual(str_to_int("    "), 0)
Exemple #12
0
 def test_empty_string_is_zero(self):
     self.assertEqual(str_to_int(""), 0)
Exemple #13
0
 def test_with_default(self):
     self.assertIsNone(str_to_int("", default=None))
Exemple #14
0
 def test_stringified_number_with_trailing_whitespace_is_converted(self):
     self.assertEqual(str_to_int("10    "), 10)
Exemple #15
0
 def test_stringified_number_is_converted(self):
     self.assertEqual(str_to_int("10"), 10)