Skip to content

Instantly share code, notes, and snippets.

@gacha
Created January 3, 2010 21:48
Show Gist options
  • Save gacha/268145 to your computer and use it in GitHub Desktop.
Save gacha/268145 to your computer and use it in GitHub Desktop.
def avg_speed
avg_speed = Event.sum(:avg_speed,:conditions => {:bike_id => self.id})
event_count = Event.count(:all,:conditions => ["bike_id = ? AND avg_speed > 0",self.id])
(avg_speed > 0)? avg_speed / event_count : 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment