Class: GoobyActivity

Inherits:
GoobyXmlObject show all
Defined in:
lib/gooby_activity.rb

Overview

Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license.

Constant Summary

Constants inherited from GoobyBaseObject

GoobyBaseObject::KILOMETERS_PER_MILE, GoobyBaseObject::METERS_PER_FOOT, GoobyBaseObject::MILES_PER_KILOMETER, GoobyBaseObject::SECONDS_PER_HOUR, GoobyBaseObject::UOM_KILOMETERS, GoobyBaseObject::UOM_MILES, GoobyBaseObject::UOM_YARDS, GoobyBaseObject::YARDS_PER_KILOMETER, GoobyBaseObject::YARDS_PER_MILE

Instance Attribute Summary collapse

Attributes inherited from GoobyXmlObject

#hash, #list

Instance Method Summary collapse

Methods inherited from GoobyXmlObject

#add, #base_initialize, #get, #id, #sequence, #set

Methods inherited from GoobyBaseObject

boolean_config_value, config_value, get_config, set_config

Methods included from GoobyIO

#read_file_as_lines, #write_file, #write_lines

Methods included from GoobyIntrospection

#classname, included

Methods included from GoobyEnvironment

#array_param, #boolean_param, #command_line_arg, #float_param, #integer_param, #string_param

Constructor Details

#initialize(attrs = nil) ⇒ GoobyActivity

Returns a new instance of GoobyActivity.



12
13
14
15
16
17
18
# File 'lib/gooby_activity.rb', line 12

def initialize(attrs=nil)
  base_initialize
  @laps, @trackpoints, @current_lap = [], [], nil
  if attrs
    attrs.keys.each { | name | set(name, attrs[name]) }
  end
end

Instance Attribute Details

#lapsObject (readonly)

Returns the value of attribute laps.



10
11
12
# File 'lib/gooby_activity.rb', line 10

def laps
  @laps
end

#sportObject (readonly)

Returns the value of attribute sport.



10
11
12
# File 'lib/gooby_activity.rb', line 10

def sport
  @sport
end

#trackpointsObject (readonly)

Returns the value of attribute trackpoints.



10
11
12
# File 'lib/gooby_activity.rb', line 10

def trackpoints
  @trackpoints
end

Instance Method Details

#add_lap(lap) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/gooby_activity.rb', line 24

def add_lap(lap)
  if lap
    lap.set('Seq', @laps.size + 1)      
    @laps << lap
    @current_lap = lap
  end
end

#add_trackpoint(trackpoint) ⇒ Object



32
33
34
35
36
37
# File 'lib/gooby_activity.rb', line 32

def add_trackpoint(trackpoint)
  if trackpoint
    trackpoint.set('Seq', @trackpoints.size + 1)
    @trackpoints << trackpoint
  end
end

#post_processObject

Coumpute the elapsed time and distance of each Trackpoint within the Activity.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gooby_activity.rb', line 40

def post_process
  cumulative_distance, first_tkpt_dttm, prev_tkpt = 0.0, nil, nil
  @trackpoints.each { | tkpt |
    if prev_tkpt
      incremental_distance = tkpt.proximity(prev_tkpt)
      cumulative_distance = cumulative_distance + incremental_distance
      tkpt.set('Distance', cumulative_distance)
    else
      first_tkpt_dttm = tkpt.dttm
      tkpt.set('Distance', 0.0)
    end
    tkpt.compute_elapsed_time(first_tkpt_dttm)
    tkpt.compute_cumulative_pace_and_mph(first_tkpt_dttm)
    prev_tkpt = tkpt
  }
end

#trackpoints_csvObject



57
58
59
60
61
# File 'lib/gooby_activity.rb', line 57

def trackpoints_csv
  lines = []
  @trackpoints.each { | trackpoint | lines << trackpoint.to_csv }
  lines
end