Skip to content

Instantly share code, notes, and snippets.

@liezl200
Last active December 11, 2015 21:57
Show Gist options
  • Save liezl200/ce4b55b13af7b359f6f1 to your computer and use it in GitHub Desktop.
Save liezl200/ce4b55b13af7b359f6f1 to your computer and use it in GitHub Desktop.
def convertTime(s):
'''
Takes a string s in the form 'MM:SS' and converts it to a float MM.xx... which represents number of minutes.
'''
first = s.partition(':')
return float(first[0]) + float(first[2]) / 60.0
for i in range(53, len(stats)):
game = stats[i]
homeTeam = game['home_team']
awayTeam = game['away_team']
homeStats = master_scraper.getLastNGameStats(stats, 5, homeTeam, i)
awayStats = master_scraper.getLastNGameStats(stats, 5, awayTeam, i)
if len(homeStats) == 0 or len(awayStats) == 0:
continue
print 'home stats for games', i-5, 'to', i, homeStats
print 'away stats for games', i-5, 'to', i, awayStats
# convert minutes
for stat in homeStats:
print 'stat', stat
stat['time_played'] = convertTime(stat['time_played'])
for stat in awayStats:
stat['time_played'] = convertTime(stat['time_played'])
homeStats = sorted(homeStats, key=attrgetter('time_played'))
awayStats = sorted(awayStats, key=attrgetter('time_played'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment