def create_player(player_xml): if (player_xml.get('num') and player_xml.get('num') != '--' and player_xml.get('num') != '-' and player_xml.get('num') != ' ' and player_xml.get('num') != '?' and player_xml.get('num') != 'null'): player_num = int(player_xml.get('num')) else: player_num = None new_player = Player(player_xml.get('last'), player_xml.get('first'), int(player_xml.get('id')), None, None, player_num) new_player.bat_side = player_xml.get('bats') new_player.pitch_hand = player_xml.get('rl') return new_player
def create_player(player_xml): if (player_xml.get('num') and player_xml.get('num') != '--' and player_xml.get('num') != '-' and player_xml.get('num') != 'null'): player_num = int(player_xml.get('num')) else: player_num = None return Player(player_xml.get('last'), player_xml.get('first'), int(player_xml.get('id')), None, None, player_num)
def initialize_team(team_name, team_code, batter_xml_list): this_team = Team(team_name, team_code) for batter in batter_xml_list: if batter.tag == 'batter': player_id = int(batter.get('id')) if batter.get('obp'): player_obp = float(batter.get('obp')) else: player_obp = None if batter.get('slg'): player_slg = float(batter.get('slg')) else: player_slg = None player_position_str = batter.get('pos').split('-')[0] player_position_num = get_position_number(player_position_str) player_first_name, player_last_name = parse_name(batter) if batter.get('bo'): player_order = int(batter.get('bo')[0]) else: player_order = None this_player = Player(player_last_name, player_first_name, player_id, player_obp, player_slg, None) this_team.append(this_player) this_player_appearance_list = init_player_list( this_player, player_position_num) if player_order: if not this_team.batting_order_list_list[player_order - 1]: this_team.batting_order_list_list[player_order - 1] = ( this_player_appearance_list) return this_team
def set_player_list(team_dict, gamedata_dict, team): digit_list = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] for player_id, this_player_dict in team_dict['players'].items(): gamedata_player_dict = gamedata_dict['players'][player_id] jersey_number = '' if ('jerseyNumber' in this_player_dict and this_player_dict.get('jerseyNumber')): if all([ character in digit_list for character in this_player_dict.get('jerseyNumber') ]): jersey_number = int(this_player_dict.get('jerseyNumber')) (first_name, last_name) = parse_name(this_player_dict['person']['fullName']) new_player = Player( last_name, first_name, this_player_dict['person']['id'], float(this_player_dict['seasonStats']['batting']['obp']), float(this_player_dict['seasonStats']['batting']['slg']), jersey_number) new_player.pitch_hand = gamedata_player_dict['pitchHand']['code'] new_player.bat_side = gamedata_player_dict['batSide']['code'] if this_player_dict['seasonStats']['pitching']['era'] != '-.--': this_era = float( this_player_dict['seasonStats']['pitching']['era']) if this_era != 0.0: new_player.era = this_era else: new_player.era = '' else: new_player.era = '' team.append(new_player)