Skip to content

Instantly share code, notes, and snippets.

@brittanydionigi
Last active January 1, 2016 14:19
Show Gist options
  • Save brittanydionigi/8156661 to your computer and use it in GitHub Desktop.
Save brittanydionigi/8156661 to your computer and use it in GitHub Desktop.
get play-by-play event strength
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