Skip to content

Instantly share code, notes, and snippets.

@zsiec
Created February 25, 2011 01:19
Show Gist options
  • Save zsiec/843247 to your computer and use it in GitHub Desktop.
Save zsiec/843247 to your computer and use it in GitHub Desktop.
def self.calcStat(player, team, gameData)
playerIn = false
totalTimeIn = 0
inTime = 0
inDiff = 0
totalPointDiff = 0
otherTeam = team == :home ? :visitor : :home
gameData.each do |state|
if state[team][:players].has_value?(player)
if not playerIn
playerIn = true
inTime = state[:time]
inDiff = state[team][:score] - state[otherTeam][:score]
end
end
if state == gameData[gameData.count - 1] || !state[team][:players].has_value?(player)
if playerIn
playerIn = false
totalTimeIn += state[:time] - inTime
totalPointDiff += (state[team][:score] - state[otherTeam][:score]) + inDiff
end
end
end
return (totalTimeIn.to_f / totalPointDiff.to_f)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment