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(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 test_with_default(self): self.assertIsNone(str_to_float("", default=None))
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 test_stringified_number_with_trailing_whitespace_is_converted(self): self.assertEqual(str_to_float("1.234 "), 1.234)
def test_stringified_number_is_converted(self): self.assertEqual(str_to_float("1.234"), 1.234)
def test_whitespace_is_zero(self): self.assertEqual(str_to_float(" "), 0.0)
def test_empty_string_is_zero(self): self.assertEqual(str_to_float(""), 0.0)
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()), }