Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def prune_give_take(event, description_raw, game_personnel):

	givetake_team = description_raw[0]
	givetake_num = description_raw[3].strip('#')

	delim_anchor = Operations.substring_index(description_raw, ',')[0] + 1

	assert delim_anchor != 0, "ERROR - Anchor not found"

	givetake_name = (" ".join(description_raw[4:delim_anchor])).strip(',')

	if givetake_team == event.away_acronym:
		givetake_on_ice = event.away_on_ice
		givetake_roster = game_personnel.away_roster	
	elif givetake_team == event.home_acronym:
		givetake_on_ice = event.home_on_ice
		givetake_roster = game_personnel.home_roster	
	else:
		assert False, "ERROR: Which team(%s) gave/took away??"%(givetake_team)
		
	givetake_player = clone_rosterplayer(
		givetake_num, givetake_name, givetake_roster)

	if event.event_type == 'GIVE':
		return Give(
			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, 
			givetake_player, givetake_team)
	elif event.event_type == 'TAKE':
		return Take(
			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, 
			givetake_player, givetake_team)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
def prune_shot(event, description_raw, game_personnel):
	
	distance = description_raw[-2]
	shot_type = description_raw[-5].strip(',')
	shooting_team = description_raw[0]
	shooting_num = description_raw[3].strip('#')

	delim_anchor = Operations.substring_index(description_raw, ',')[0] + 1

	assert delim_anchor != 0, "ERROR - Anchor not found"

	shooting_name = (" ".join(description_raw[4:delim_anchor])).strip(',')

	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
	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
		
	for player in blocking_on_ice:
		if player.pos == 'G':
			blocking_player = player

	shooting_player = clone_rosterplayer(
		shooting_num, shooting_name, shooting_roster)
	
	return Shot(
		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, shooting_player, 
		blocking_player, shooting_team, blocking_team)
Exemplo n.º 6
0
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)