Exemplo n.º 1
0
 def pa(cls, ab, game, rosters, inning_number, inning_id, out_ct, hit_location):
     """
     plate appearance data
     :param ab: at bat object(type:Beautifulsoup)
     :param game: MLBAM Game object
     :param rosters: Game Rosters
     :param inning_number: Inning Number
     :param inning_id: Inning Id(0:home 1:away)
     :param pitch_list: Pitching
     :param out_ct: out count
     :param hit_location: Hitlocation data(dict)
     :return: pa value(dict)
     """
     ab_des = MlbamUtil.get_attribute_stats(ab, 'des', str, MlbamConst.UNKNOWN_FULL)
     event_tx = MlbamUtil.get_attribute_stats(ab, 'event', str, MlbamConst.UNKNOWN_FULL)
     event_cd = RetroSheet.event_cd(event_tx, ab_des)
     event_outs_ct = MlbamUtil.get_attribute_stats(ab, 'o', int, 0)
     start_bases, end_bases = cls._get_bases(ab)
     pit_mlbid = MlbamUtil.get_attribute_stats(ab, 'pitcher', str, MlbamConst.UNKNOWN_FULL)
     bat_mlbid = MlbamUtil.get_attribute_stats(ab, 'batter', str, MlbamConst.UNKNOWN_FULL)
     pit_player = rosters.get(pit_mlbid)
     bat_player = rosters.get(bat_mlbid)
     location_key = Inning.HITLOCATION_KEY_FORMAT.format(
         inning=inning_number,
         des=event_tx,
         pitcher=pit_mlbid,
         batter=bat_mlbid,
     )
     location = hit_location.get(location_key, {})
     atbat = OrderedDict()
     atbat['retro_game_id'] = game.retro_game_id
     atbat['year'] = game.timestamp.year
     atbat['month'] = game.timestamp.month
     atbat['day'] = game.timestamp.day
     atbat['st_fl'] = game.st_fl
     atbat['regseason_fl'] = game.regseason_fl
     atbat['playoff_fl'] = game.playoff_fl
     atbat['game_type'] = game.game_type
     atbat['game_type_des'] = game.game_type_des
     atbat['local_game_time'] = game.local_game_time
     atbat['game_id'] = game.game_id
     atbat['home_team_id'] = game.home_team_id
     atbat['away_team_id'] = game.away_team_id
     atbat['home_team_lg'] = game.home_team_lg
     atbat['away_team_lg'] = game.away_team_lg
     atbat['interleague_fl'] = game.interleague_fl
     atbat['park_id'] = game.park_id
     atbat['park_name'] = game.park_name
     atbat['park_location'] = game.park_loc
     atbat['inning_number'] = inning_number
     atbat['bat_home_id'] = inning_id
     atbat['outs_ct'] = out_ct
     atbat['pit_mlbid'] = pit_mlbid
     atbat['pit_first_name'] = pit_player.first
     atbat['pit_last_name'] = pit_player.last
     atbat['pit_box_name'] = pit_player.box_name
     atbat['pit_hand_cd'] = MlbamUtil.get_attribute_stats(ab, 'p_throws', str, MlbamConst.UNKNOWN_FULL)
     atbat['bat_mlbid'] = bat_mlbid
     atbat['bat_first_name'] = bat_player.first
     atbat['bat_last_name'] = bat_player.last
     atbat['bat_box_name'] = bat_player.box_name
     atbat['bat_hand_cd'] = MlbamUtil.get_attribute_stats(ab, 'stand', str, MlbamConst.UNKNOWN_FULL)
     atbat['ab_number'] = MlbamUtil.get_attribute_stats(ab, 'num', int, None)
     atbat['start_bases'] = start_bases
     atbat['end_bases'] = end_bases
     atbat['event_outs_ct'] = event_outs_ct
     atbat['ab_des'] = ab_des
     atbat['event_tx'] = event_tx
     atbat['event_cd'] = event_cd
     atbat['hit_x'] = location.get('hit_x', None)
     atbat['hit_y'] = location.get('hit_y', None)
     return atbat
Exemplo n.º 2
0
    def test_event_cd(self):
        """
        Get Event code
        """
        # Generic out
        self.assertEqual(RetroSheet.event_cd('Flyout', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Fly Out', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Sac Fly', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Sac Fly DP', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Lineout', 'hoge line out'), 2)
        self.assertEqual(RetroSheet.event_cd('Line Out', 'hoge line out'), 2)
        self.assertEqual(RetroSheet.event_cd('Bunt Lineout', 'hoge line out'),
                         2)
        self.assertEqual(RetroSheet.event_cd('Pop Out', 'hoge pop out'), 2)
        self.assertEqual(RetroSheet.event_cd('Pop out', 'hoge pop out'), 2)
        self.assertEqual(RetroSheet.event_cd('Bunt Pop out', 'hoge pop out'),
                         2)
        self.assertEqual(RetroSheet.event_cd('Groundout', 'hoge ground out'),
                         2)
        self.assertEqual(RetroSheet.event_cd('Ground Out', 'hoge ground out'),
                         2)
        self.assertEqual(RetroSheet.event_cd('Sac Bunt', 'hoge ground out'), 2)
        self.assertEqual(
            RetroSheet.event_cd('Bunt Groundout', 'hoge ground out'), 2)
        self.assertEqual(
            RetroSheet.event_cd('Grounded Into DP', 'hoge ground into dp'), 2)
        self.assertEqual(RetroSheet.event_cd('Forceout', 'hoge force out'), 2)
        self.assertEqual(RetroSheet.event_cd('Double Play', 'hoge dp'), 2)
        self.assertEqual(RetroSheet.event_cd('Triple Play', 'hoge tp'), 2)
        self.assertEqual(
            RetroSheet.event_cd('Sacrifice Bunt D', 'hoge bunt dp'), 2)

        # Strike out
        self.assertEqual(RetroSheet.event_cd('Strikeout', 'hoge strike out'),
                         3)
        self.assertEqual(
            RetroSheet.event_cd('Strikeout - DP', 'hoge strike out dp'), 3)

        # walk, intent walk ,hit by pitch
        self.assertEqual(RetroSheet.event_cd('Walk', 'hoge walk'), 14)
        self.assertEqual(
            RetroSheet.event_cd('Intent Walk', 'hoge intent walk'), 15)
        self.assertEqual(
            RetroSheet.event_cd('Hit By Pitch', 'hoge hit by pitch'), 16)

        # Interference
        self.assertEqual(
            RetroSheet.event_cd('hoge interference', 'hoge interference'), 17)
        self.assertEqual(
            RetroSheet.event_cd('Interference fuga', 'hoge interference'), 17)

        # Error
        self.assertEqual(RetroSheet.event_cd('hoge error', 'hoge error'), 18)
        self.assertEqual(RetroSheet.event_cd('fuga Error', 'fuga error'), 18)
        # Not Error
        self.assertEqual(RetroSheet.event_cd('error fuga', 'fuga not error'),
                         0)

        # Fielder's Choice
        self.assertEqual(
            RetroSheet.event_cd('Fielders Choice Out', 'hoge fielders choice'),
            19)
        self.assertEqual(
            RetroSheet.event_cd('Fielders Choice', 'hoge fielders choice'), 19)

        # Single, 2B, 3B, HR
        self.assertEqual(RetroSheet.event_cd('Single', 'hoge Single'), 20)
        self.assertEqual(RetroSheet.event_cd('Double', 'hoge 2B'), 21)
        self.assertEqual(RetroSheet.event_cd('Triple', 'hoge 3B'), 22)
        self.assertEqual(RetroSheet.event_cd('Home Run', 'hoge home run'), 23)

        # Runner Out
        self.assertEqual(
            RetroSheet.event_cd('Runner Out', 'hoge caught stealing'), 6)
        self.assertEqual(RetroSheet.event_cd('Runner Out', 'hoge picks off'),
                         8)

        # Unknown Event
        self.assertEqual(RetroSheet.event_cd('bar', 'hoge picks off'), 0)
        self.assertEqual(RetroSheet.event_cd('Runner Out', 'hoge fuga'), 0)
Exemplo n.º 3
0
    def test_event_cd(self):
        """
        Get Event code
        """
        # Generic out
        self.assertEqual(RetroSheet.event_cd('Flyout', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Fly Out', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Sac Fly', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Sac Fly DP', 'hoge fly out'), 2)
        self.assertEqual(RetroSheet.event_cd('Lineout', 'hoge line out'), 2)
        self.assertEqual(RetroSheet.event_cd('Line Out', 'hoge line out'), 2)
        self.assertEqual(RetroSheet.event_cd('Bunt Lineout', 'hoge line out'), 2)
        self.assertEqual(RetroSheet.event_cd('Pop Out', 'hoge pop out'), 2)
        self.assertEqual(RetroSheet.event_cd('Pop out', 'hoge pop out'), 2)
        self.assertEqual(RetroSheet.event_cd('Bunt Pop out', 'hoge pop out'), 2)
        self.assertEqual(RetroSheet.event_cd('Groundout', 'hoge ground out'), 2)
        self.assertEqual(RetroSheet.event_cd('Ground Out', 'hoge ground out'), 2)
        self.assertEqual(RetroSheet.event_cd('Sac Bunt', 'hoge ground out'), 2)
        self.assertEqual(RetroSheet.event_cd('Bunt Groundout', 'hoge ground out'), 2)
        self.assertEqual(RetroSheet.event_cd('Grounded Into DP', 'hoge ground into dp'), 2)
        self.assertEqual(RetroSheet.event_cd('Forceout', 'hoge force out'), 2)
        self.assertEqual(RetroSheet.event_cd('Double Play', 'hoge dp'), 2)
        self.assertEqual(RetroSheet.event_cd('Triple Play', 'hoge tp'), 2)
        self.assertEqual(RetroSheet.event_cd('Sacrifice Bunt D', 'hoge bunt dp'), 2)

        # Strike out
        self.assertEqual(RetroSheet.event_cd('Strikeout', 'hoge strike out'), 3)
        self.assertEqual(RetroSheet.event_cd('Strikeout - DP', 'hoge strike out dp'), 3)

        # walk, intent walk ,hit by pitch
        self.assertEqual(RetroSheet.event_cd('Walk', 'hoge walk'), 14)
        self.assertEqual(RetroSheet.event_cd('Intent Walk', 'hoge intent walk'), 15)
        self.assertEqual(RetroSheet.event_cd('Hit By Pitch', 'hoge hit by pitch'), 16)

        # Interference
        self.assertEqual(RetroSheet.event_cd('hoge interference', 'hoge interference'), 17)
        self.assertEqual(RetroSheet.event_cd('Interference fuga', 'hoge interference'), 17)

        # Error
        self.assertEqual(RetroSheet.event_cd('hoge error', 'hoge error'), 18)
        self.assertEqual(RetroSheet.event_cd('fuga Error', 'fuga error'), 18)
        # Not Error
        self.assertEqual(RetroSheet.event_cd('error fuga', 'fuga not error'), 0)

        # Fielder's Choice
        self.assertEqual(RetroSheet.event_cd('Fielders Choice Out', 'hoge fielders choice'), 19)
        self.assertEqual(RetroSheet.event_cd('Fielders Choice', 'hoge fielders choice'), 19)

        # Single, 2B, 3B, HR
        self.assertEqual(RetroSheet.event_cd('Single', 'hoge Single'), 20)
        self.assertEqual(RetroSheet.event_cd('Double', 'hoge 2B'), 21)
        self.assertEqual(RetroSheet.event_cd('Triple', 'hoge 3B'), 22)
        self.assertEqual(RetroSheet.event_cd('Home Run', 'hoge home run'), 23)

        # Runner Out
        self.assertEqual(RetroSheet.event_cd('Runner Out', 'hoge caught stealing'), 6)
        self.assertEqual(RetroSheet.event_cd('Runner Out', 'hoge picks off'), 8)

        # Unknown Event
        self.assertEqual(RetroSheet.event_cd('bar', 'hoge picks off'), 0)
        self.assertEqual(RetroSheet.event_cd('Runner Out', 'hoge fuga'), 0)
Exemplo n.º 4
0
 def pa(cls, ab, game, rosters, inning_number, inning_id, out_ct,
        hit_location):
     """
     plate appearance data
     :param ab: at bat object(type:Beautifulsoup)
     :param game: MLBAM Game object
     :param rosters: Game Rosters
     :param inning_number: Inning Number
     :param inning_id: Inning Id(0:home 1:away)
     :param pitch_list: Pitching
     :param out_ct: out count
     :param hit_location: Hitlocation data(dict)
     :return: {
         'retro_game_id': Retrosheet Game id
         'game_type': Game Type(S/R/F/D/L/W)
         'game_type_des': Game Type Description
         (Spring Training or Regular Season or Wild-card Game or Divisional Series or LCS or World Series)
         'st_fl': Spring Training FLAG(T or F)
         'regseason_fl': Regular Season FLAG(T or F)
         'playoff_fl': Play Off Flag(T or F)
         'local_game_time': Game Time(UTC -5)
         'game_id': Game Id
         'home_team_id': Home Team Id
         'home_team_lg': Home Team league(AL or NL)
         'away_team_id': Away Team Id
         'away_team_lg': Away Team league(AL or NL)
         'home_team_name': Home Team Name
         'away_team_name': Away Team Name
         'home_team_name_full': Home Team Name(Full Name)
         'away_team_name_full': Away Team Name(Full Name)
         'interleague_fl': Inter League Flag(T or F)
         'park_id': Park Id
         'park_name': Park Name
         'park_loc': Park Location
         'inning_number': Inning Number
         'bat_home_id': Batter Id
         'outs_ct': Out count
         'pit_mlbid': Pitcher Id
         'pit_first_name': Pitcher First Name
         'pit_last_name': Pitcher Last Name
         'pit_box_name': Pitcher Box name
         'pit_hand_cd': Pitcher Throw Hand(R or L)
         'bat_first_name': Batter First Name
         'bat_last_name': Batter Last Name
         'bat_box_name': Batter Box name
         'ab_number': At Bat Sequence Number in Game
         'start_bases': Bases(Before At Bat)
         (___, 1__, 12_, 123, etc...)
         'end_bases': Bases(After At Bat)
         (___, 1__, 12_, 123, etc...)
         'event_outs_ct': Event Out Count
         'ab_des': At Bat Description
         'event_tx': Event Text
         'event_cd': Event Code for Retrosheet http://www.retrosheet.org/datause.txt
         'hit_x': Hit Location(x)
         'hit_y': Hit Location(y)
         'event_num': Event Sequence Number(atbat, pitch, action)
         'home_team_runs': Score(Home)
         'away_team_runs': Score(Away)
     }
     """
     ab_des = MlbamUtil.get_attribute_stats(ab, 'des', str,
                                            MlbamConst.UNKNOWN_FULL)
     event_tx = MlbamUtil.get_attribute_stats(ab, 'event', str,
                                              MlbamConst.UNKNOWN_FULL)
     event_cd = RetroSheet.event_cd(event_tx, ab_des)
     event_outs_ct = MlbamUtil.get_attribute_stats(ab, 'o', int, 0)
     start_bases, end_bases = cls._get_bases(ab)
     pit_mlbid = MlbamUtil.get_attribute_stats(ab, 'pitcher', str,
                                               MlbamConst.UNKNOWN_FULL)
     bat_mlbid = MlbamUtil.get_attribute_stats(ab, 'batter', str,
                                               MlbamConst.UNKNOWN_FULL)
     pit_player = rosters.get(pit_mlbid)
     bat_player = rosters.get(bat_mlbid)
     location_key = Inning.HITLOCATION_KEY_FORMAT.format(
         inning=inning_number,
         des=event_tx,
         pitcher=pit_mlbid,
         batter=bat_mlbid,
     )
     location = hit_location.get(location_key, {})
     atbat = OrderedDict()
     atbat['retro_game_id'] = game.retro_game_id
     atbat['year'] = game.timestamp.year
     atbat['month'] = game.timestamp.month
     atbat['day'] = game.timestamp.day
     atbat['st_fl'] = game.st_fl
     atbat['regseason_fl'] = game.regseason_fl
     atbat['playoff_fl'] = game.playoff_fl
     atbat['game_type'] = game.game_type
     atbat['game_type_des'] = game.game_type_des
     atbat['local_game_time'] = game.local_game_time
     atbat['game_id'] = game.game_id
     atbat['home_team_id'] = game.home_team_id
     atbat['away_team_id'] = game.away_team_id
     atbat['home_team_lg'] = game.home_team_lg
     atbat['away_team_lg'] = game.away_team_lg
     atbat['interleague_fl'] = game.interleague_fl
     atbat['park_id'] = game.park_id
     atbat['park_name'] = game.park_name
     atbat['park_location'] = game.park_loc
     atbat['inning_number'] = inning_number
     atbat['bat_home_id'] = inning_id
     atbat['outs_ct'] = out_ct
     atbat['pit_mlbid'] = pit_mlbid
     atbat['pit_first_name'] = pit_player.first
     atbat['pit_last_name'] = pit_player.last
     atbat['pit_box_name'] = pit_player.box_name
     atbat['pit_hand_cd'] = MlbamUtil.get_attribute_stats(
         ab, 'p_throws', str, MlbamConst.UNKNOWN_FULL)
     atbat['bat_mlbid'] = bat_mlbid
     atbat['bat_first_name'] = bat_player.first
     atbat['bat_last_name'] = bat_player.last
     atbat['bat_box_name'] = bat_player.box_name
     atbat['bat_hand_cd'] = MlbamUtil.get_attribute_stats(
         ab, 'stand', str, MlbamConst.UNKNOWN_FULL)
     atbat['ab_number'] = MlbamUtil.get_attribute_stats(
         ab, 'num', int, None)
     atbat['start_bases'] = start_bases
     atbat['end_bases'] = end_bases
     atbat['event_outs_ct'] = event_outs_ct
     atbat['ab_des'] = ab_des
     atbat['event_tx'] = event_tx
     atbat['event_cd'] = event_cd
     atbat['hit_x'] = location.get('hit_x', None)
     atbat['hit_y'] = location.get('hit_y', None)
     atbat['event_num'] = MlbamUtil.get_attribute_stats(
         ab, 'event_num', int, -1)
     atbat['home_team_runs'] = MlbamUtil.get_attribute_stats(
         ab, 'home_team_runs', int, 0)
     atbat['away_team_runs'] = MlbamUtil.get_attribute_stats(
         ab, 'away_team_runs', int, 0)
     return atbat