Class: RaceParticipation
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- RaceParticipation
- Defined in:
- lib/opensprints-core/race_participation.rb
Constant Summary collapse
- METERS_PER_MILLISECOND_TO_MILES_PER_HOUR =
2236.93629
- METERS_PER_MILLISECOND_TO_KILOMETERS_PER_HOUR =
3600.0
Instance Attribute Summary collapse
-
#ticks ⇒ Object
Returns the value of attribute ticks.
Instance Method Summary collapse
- #color ⇒ Object
- #distance ⇒ Object
- #finished? ⇒ Boolean
- #percent_complete ⇒ Object
-
#speed(time) ⇒ Object
yikes.
- #unit_conversion ⇒ Object
Instance Attribute Details
#ticks ⇒ Object
Returns the value of attribute ticks.
9 10 11 |
# File 'lib/opensprints-core/race_participation.rb', line 9 def ticks @ticks end |
Instance Method Details
#color ⇒ Object
5 6 7 |
# File 'lib/opensprints-core/race_participation.rb', line 5 def color @color ||= $BIKES[self.race.race_participations.index(self)] end |
#distance ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/opensprints-core/race_participation.rb', line 19 def distance if self.ticks self.ticks * $ROLLER_CIRCUMFERENCE else 0.0 end end |
#finished? ⇒ Boolean
11 12 13 |
# File 'lib/opensprints-core/race_participation.rb', line 11 def finished? !!finish_time end |
#percent_complete ⇒ Object
15 16 17 |
# File 'lib/opensprints-core/race_participation.rb', line 15 def percent_complete [1.0, self.distance / $RACE_DISTANCE].min end |
#speed(time) ⇒ Object
yikes.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/opensprints-core/race_participation.rb', line 39 def speed(time) @unit_conversion ||= unit_conversion @distance = self.distance @time = time @distance_old ||= 0 @time_old ||= 0 @speed ||= 0 if(@time_old > @time) @time_old = time end if time == 0 0 else if(@time-@time_old > 999) if(@distance_old > 0) @speed = "%.2f" % (((@distance - @distance_old) / (@time - @time_old)) * @unit_conversion).to_f else @speed = 0 end @distance_old = @distance @time_old = @time end @speed end end |
#unit_conversion ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/opensprints-core/race_participation.rb', line 29 def unit_conversion case UNIT_SYSTEM when :mph @unit_conversion = METERS_PER_MILLISECOND_TO_MILES_PER_HOUR when :kph @unit_conversion = METERS_PER_MILLISECOND_TO_KILOMETERS_PER_HOUR end end |