def prune_hit(event, description_raw, game_personnel): hit_anchor = description_raw.index('HIT') delim_anchors = Operations.substring_index(description_raw, ',') assert hit_anchor != -1, "ERROR - Anchor not found" if delim_anchors == []: # No zone entered in nhl report hit_name = (" ".join( description_raw[hit_anchor + 3:])).strip (',') else: name_anchor = delim_anchors[0] + 1 hit_name = (" ".join( description_raw[hit_anchor + 3: name_anchor])).strip (',') hit_team = description_raw[hit_anchor + 1] hit_num = description_raw[hit_anchor + 2].strip('#') if hit_team == event.home_acronym: hitting_on_ice = event.away_on_ice hitting_roster = game_personnel.away_roster hit_on_ice = event.home_on_ice hit_roster = game_personnel.home_roster elif hit_team == event.away_acronym: hitting_on_ice = event.home_on_ice hitting_roster = game_personnel.home_roster hit_on_ice = event.away_on_ice hit_roster = game_personnel.away_roster else: assert False, 'ERROR: hit_team(%s) doesnt match home (%s) or away\ (%s) team'%(hit_team, event.away_acronym, event.home_acronym) if hit_anchor >= 3: hitting_team = description_raw[0] hitting_num = description_raw[1].strip('#') hitting_name = " ".join(description_raw[2:hit_anchor]) hitting_player = clone_rosterplayer( hitting_num, hitting_name, hitting_roster) else:# NHL f****d up; loaded a blank hitter if hit_team == event.away_acronym: hitting_team = event.home_acronym elif hit_team == event.home_acronym: hitting_team = event.home_acronym hitting_player = Roster.return_null_player() hit_player = clone_rosterplayer(hit_num, hit_name, hit_roster) return Hit( event.num, event.period_num, event.strength, event.time, event.event_type, event.zone, event.description, event.away_acronym, event.home_acronym, event.away_on_ice, event.home_on_ice, hitting_player, hit_player, hitting_team, hit_team)
def prune_block(event, description_raw, game_personnel): block_anchor = Operations.substring_index(description_raw, 'BLOCKED')[0] delim_index = Operations.substring_index(description_raw, ',')[0] + 1 assert block_anchor != -1 and delim_index != 0, "ERROR - Anchor not found" assert 'Zone' in description_raw, "ERROR - 'Zone' not found" shot_type = description_raw[-3].strip(',') blocking_team = description_raw[block_anchor + 2] blocking_num = description_raw[block_anchor + 3].strip('#') blocking_name = ( " ".join(description_raw[block_anchor + 4: delim_index])).strip (',') if blocking_team == event.home_acronym: shooting_on_ice = event.away_on_ice shooting_roster = game_personnel.away_roster blocking_on_ice = event.home_on_ice blocking_roster = game_personnel.home_roster elif blocking_team == event.away_acronym: shooting_on_ice = event.home_on_ice shooting_roster = game_personnel.home_roster blocking_on_ice = event.away_on_ice blocking_roster = game_personnel.away_roster else: assert False, 'ERROR: shooting_team(%s) doesnt match home (%s) or away\ (%s) team'%(shooting_team, event.away_acronym, event.home_acronym) if block_anchor >= 3: shooting_name = " ".join(description_raw[2:block_anchor]) shooting_team = description_raw[0] shooting_num = description_raw[1].strip('#') shooting_player = clone_rosterplayer( shooting_num, shooting_name, shooting_roster) else: # NHL f****d up; loaded a blank shooter if blocking_team == event.away_acronym: shooting_team = event.home_acronym elif blocking_team == event.home_acronym: shooting_team = event.home_acronym shooting_player = Roster.return_null_player() blocking_player = clone_rosterplayer( blocking_num, blocking_name, blocking_roster) return Block( event.num, event.period_num, event.strength, event.time, event.event_type, event.zone, event.description, event.away_acronym, event.home_acronym, event.away_on_ice, event.home_on_ice, shot_type, shooting_player, blocking_player, shooting_team, blocking_team)
def prune_miss(event, description_raw, game_personnel): delim_anchors = Operations.substring_index(description_raw, ',') delim_anchor = delim_anchors[0] + 1 assert delim_anchor != 0, "ERROR - Anchor not found" if len(delim_anchors) < 4: # Part of info is missing-usually shot/miss type shot_type = None miss_type = None else: shot_type = description_raw[-8].strip(',') miss_type = (" ".join(description_raw[delim_anchor + 1:-4])).strip(',') distance = description_raw[-2] shooting_team = description_raw[0] shooting_num = description_raw[1].strip('#') shooting_name = (" ".join(description_raw[2:delim_anchor])).strip(',') shooting_player = (shooting_num, shooting_name) if shooting_team == event.away_acronym: shooting_on_ice = event.away_on_ice shooting_roster = game_personnel.away_roster blocking_on_ice = event.home_on_ice blocking_team = event.home_acronym blocking_roster = game_personnel.home_roster elif shooting_team == event.home_acronym: shooting_on_ice = event.home_on_ice shooting_roster = game_personnel.home_roster blocking_on_ice = event.away_on_ice blocking_team = event.away_acronym blocking_roster = game_personnel.away_roster else: assert False, 'ERROR: shooting_team doesnt match home or away team' for player in blocking_on_ice: blocking_player = Roster.return_null_player() if player.pos == 'G': blocking_player = player shooting_player = clone_rosterplayer( shooting_num, shooting_name, shooting_roster) return Miss( event.num, event.period_num, event.strength, event.time, event.event_type, event.zone, event.description, event.away_acronym, event.home_acronym, event.away_on_ice, event.home_on_ice, shot_type, miss_type, distance, shooting_player, blocking_player, shooting_team, blocking_team)
def prune_stop(event, description_raw, event_index, event_list, game_personnel): stopping_player = Roster.return_null_player() stopping_team = None zone = None tv_timeout = 0 timeout_caller = None description_raw = re.split('\W+', event.description) description_parsed = " ".join(description_raw) # Parse out 'TV TIMEOUT if not only item if 'TV' in description_raw: tv_timeout = 1 if len(description_raw) != 2: index = description_raw.index("TV") description_raw.pop (index) description_raw.pop (index) description_parsed = " ".join(description_raw) if 'HOME' in description_raw: timeout_caller = game_personnel.home_coach.full_name() elif 'VISITOR' in description_raw: timeout_caller = game_personnel.away_coach.full_name() if "GOALIE" in description_raw or 'FROZEN' in description_raw: stopping_team, stopping_on_ice = Operations.team_responsible( event_index, event_list) for player in stopping_on_ice: if player.pos == 'Goalie': stopping_player = player elif "ICING" in description_raw: stopping_team, stopping_on_ice = Operations.team_responsible( event_index, event_list) return Stop( event.num, event.period_num, event.strength, event.time, event.event_type, zone, event.description, event.away_acronym, event.home_acronym, event.away_on_ice, event.home_on_ice, description_parsed, stopping_player, stopping_team, tv_timeout, timeout_caller)
def prune_penl(event, description_raw, event_index, event_list, game_personnel): penalized_team_acronym = description_raw[0] if penalized_team_acronym == event.home_acronym: drawing_team = event.away_acronym drawing_on_ice = event.away_on_ice drawing_roster = game_personnel.away_roster penalized_on_ice = event.home_on_ice penalized_roster = game_personnel.home_roster elif penalized_team_acronym == event.away_acronym: drawing_team = event.home_acronym drawing_roster = game_personnel.home_roster drawing_on_ice = event.home_on_ice penalized_on_ice = event.away_on_ice penalized_roster = game_personnel.away_roster # Grabbing player information using normal split procedure # Grabbing penalized player if description_raw[1] == 'TEAM': # No penalized player penalized_player = Roster.return_null_player() else: for index, item in enumerate(description_raw[2:]): if not str(item).isupper(): name_anchor = index + 2 # Because start index for loop is 2 break penalized_num = description_raw[1].strip('#') penalized_name = " ".join(description_raw[2:name_anchor]) penalized_player = clone_rosterplayer( penalized_num, penalized_name, penalized_roster) # Grabbing drawing player try: drawing_anchor = description_raw.index('Drawn') + 2 drawing_num = description_raw [drawing_anchor + 1].strip('#') drawing_name = " ".join(description_raw [drawing_anchor + 2:]) drawing_player = clone_rosterplayer( drawing_num, drawing_name, drawing_roster) except ValueError: drawing_player = Roster.return_null_player() # Grabbing serving player try: serving_anchor = description_raw.index('Served') + 2 serving_num = description_raw [serving_anchor].strip('#') # Default end of serving name is last index in description_raw serving_name = " ".join(description_raw[serving_anchor + 1:]) # However, zone information may be present at end of description_raw for index, item in enumerate(description_raw[serving_anchor + 1:]): if item.isupper() == False: # Because start index for loop is serving_anchor + 1 end_serving_name = index + serving_anchor + 1 serving_name = " ".join(description_raw[serving_anchor + 1: end_serving_name]).strip(',') break serving_player = clone_rosterplayer( serving_num, serving_name, penalized_roster) except ValueError: serving_player = Roster.return_null_player() # Grab other info using regex splitting procedure regex_split = re.split('\W+', event.description) for index, item in enumerate(regex_split[2:]): if not str(item).isupper(): penalty_start = index + 2 break penalty_end = regex_split.index('min') - 1 length = regex_split[penalty_end] penalty_type = " ".join(regex_split[penalty_start:penalty_end]) return Penalty( event.num, event.period_num, event.strength, event.time, event.event_type, event.zone, event.description, event.away_acronym, event.home_acronym, event.away_on_ice, event.home_on_ice, penalty_type, length, penalized_player, serving_player, drawing_player, penalized_team_acronym, drawing_team)
def prune_goal(event, description_raw, game_personnel): prim_assist_player = Roster.return_null_player() sec_assist_player = Roster.return_null_player() scoring_team = description_raw[0] scoring_num = description_raw[1].strip('#') if scoring_team == event.away_acronym: scoring_on_ice = event.away_on_ice scoring_roster = game_personnel.away_roster defending_on_ice = event.home_on_ice defending_roster = game_personnel.away_roster defending_team = event.away_acronym elif scoring_team == event.home_acronym: scoring_on_ice = event.home_on_ice scoring_roster = game_personnel.home_roster defending_on_ice = event.away_on_ice defending_roster = game_personnel.home_roster defending_team = event.home_acronym name_anchor = Operations.substring_index(description_raw, ',')[0] + 1 shot_anchor = Operations.substring_index( description_raw[name_anchor:], ',')[0] + name_anchor + 1 distance_anchor = Operations.substring_index(description_raw, 'ft.')[0] scoring_name_raw = " ".join(description_raw[2:name_anchor]) scoring_name = prune_name(scoring_name_raw) scoring_player = clone_rosterplayer( scoring_num, scoring_name, scoring_roster) shot_type = (" ".join(description_raw[name_anchor:shot_anchor])).strip(',') distance = description_raw[distance_anchor - 1] if 'Assist:' in description_raw: assist_anchor = Operations.substring_index( description_raw, 'Assist:')[0] + 1 prim_assist_num = description_raw[assist_anchor].strip('#') prim_assist_name_raw = " ".join(description_raw[assist_anchor + 1:]) prim_assist_name = prune_name(prim_assist_name_raw) prim_assist_player = clone_rosterplayer( prim_assist_num, prim_assist_name, scoring_roster) elif 'Assists:' in description_raw: assist_anchor = Operations.substring_index( description_raw, 'Assists:')[0] + 1 sec_assist_anchor = Operations.substring_index( description_raw, ';')[0] + 1 prim_assist_num = description_raw[assist_anchor].strip('#') prim_assist_name_raw = ( " ".join(description_raw[assist_anchor + 1:sec_assist_anchor])) prim_assist_name = prune_name(prim_assist_name_raw) prim_assist_player = clone_rosterplayer( prim_assist_num, prim_assist_name, scoring_roster) sec_assist_num = description_raw[sec_assist_anchor].strip('#') sec_assist_name_raw = " ".join(description_raw[sec_assist_anchor + 1:]) sec_assist_name = prune_name(sec_assist_name_raw) sec_assist_player = clone_rosterplayer( sec_assist_num, sec_assist_name, scoring_roster) for player in defending_on_ice: # For EN goals, no goalie is on the ice goalie = Roster.return_null_player() if player.pos == 'Goalie': goalie = player return Goal( event.num, event.period_num, event.strength, event.time, event.event_type, event.zone, event.description, event.away_acronym, event.home_acronym, event.away_on_ice, event.home_on_ice, shot_type, distance, scoring_player, scoring_team, prim_assist_player, sec_assist_player, goalie, defending_team)