Last active
January 1, 2016 14:19
-
-
Save brittanydionigi/8156661 to your computer and use it in GitHub Desktop.
get play-by-play event strength
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_strength_transitions(teams, events): | |
strength = [{"start_time": 0, "advantage": None }] | |
originalAdvantage = None | |
for ind, event in enumerate(events): | |
if len(event["strength"]) == 2: | |
timeExpired = parseGameTime(event["total_time_expired"]) | |
eventStrength = event["strength"] | |
teamAdvantage = None | |
if event["strength"] == "SH": | |
teamAdvantage = teams["away_team"] | |
if event["strength"] == "PP": | |
teamAdvantage = teams["home_team"] | |
# if there has been a change in strength | |
if originalAdvantage != teamAdvantage: | |
originalAdvantage = teamAdvantage | |
startTime = timeExpired | |
# update the previous strength entry with an end time | |
strength[-1]["end_time"] = startTime - 1 | |
# append a new strength entry to the list | |
strength.append({ "start_time": startTime, "advantage": teamAdvantage }) | |
return strength |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment