Class: Gooby::Trackpoint
- Inherits:
-
Point
- Object
- GoobyObject
- Point
- Gooby::Trackpoint
- Defined in:
- lib/gooby_track_point.rb
Instance Attribute Summary collapse
-
#cumulative_distance ⇒ Object
Returns the value of attribute cumulative_distance.
-
#cumulative_pace ⇒ Object
Returns the value of attribute cumulative_pace.
-
#dttm ⇒ Object
Returns the value of attribute dttm.
-
#first ⇒ Object
Returns the value of attribute first.
-
#incremental_distance ⇒ Object
Returns the value of attribute incremental_distance.
-
#lap_distance ⇒ Object
Returns the value of attribute lap_distance.
-
#lap_elapsed ⇒ Object
Returns the value of attribute lap_elapsed.
-
#lap_number ⇒ Object
Returns the value of attribute lap_number.
-
#lap_seq ⇒ Object
Returns the value of attribute lap_seq.
-
#last ⇒ Object
Returns the value of attribute last.
-
#number ⇒ Object
Returns the value of attribute number.
-
#prev_split ⇒ Object
Returns the value of attribute prev_split.
-
#prev_tkpt ⇒ Object
Returns the value of attribute prev_tkpt.
-
#run_id ⇒ Object
Returns the value of attribute run_id.
-
#run_number ⇒ Object
Returns the value of attribute run_number.
-
#run_start_dttm ⇒ Object
Returns the value of attribute run_start_dttm.
-
#split ⇒ Object
Returns the value of attribute split.
Attributes inherited from Point
#altitude, #latitude, #longitude, #note, #uom
Class Method Summary collapse
Instance Method Summary collapse
- #as_glatlng(comment_out, gen_comments, tkpt_count, curr_idx, start_dttm) ⇒ Object
- #as_info_window_html(checkpoint, start_dttm) ⇒ Object
- #compute_cumulative_pace(start_dttm) ⇒ Object
- #compute_distance_and_pace(curr_index, start_dttm, prev_cumulative_dist, prev_trackpoint) ⇒ Object
-
#initialize(num, lat, lng, alt, hb, time_string, uom, auxInfoHash = Hash.new('')) ⇒ Trackpoint
constructor
A new instance of Trackpoint.
- #is_split ⇒ Object
- #point ⇒ Object
- #position ⇒ Object
- #set_split(n, tkpt) ⇒ Object
- #split_info(dtTm) ⇒ Object
- #to_csv(prev_tkpt = nil) ⇒ Object
- #to_geo_s ⇒ Object
- #to_s ⇒ Object
Methods inherited from Point
#altitude_as_float, #csv_delim, #deg2rad, #degrees_diff, #english_system, #has_coordinates?, #heartbeat_as_float, #initialize_from_array, #initialize_from_string, #latitude_as_float, #longitude_as_float, #metric_system, #proximity, #rad2deg, #to_formatted_string
Methods included from GoobyKernel
#character_align, #default_delimiter, #invalid_altitude, #invalid_heartbeat, #invalid_latitude, #invalid_longitude, #invalid_time, #project_author, #project_copyright, #project_date, #project_embedded_comment, #project_license, #project_name, #project_version_number, #project_year, #read_as_ascii_lines, #read_lines, #strip_lines, #tokenize
Constructor Details
#initialize(num, lat, lng, alt, hb, time_string, uom, auxInfoHash = Hash.new('')) ⇒ Trackpoint
Returns a new instance of Trackpoint.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/gooby_track_point.rb', line 18 def initialize(num, lat, lng, alt, hb, time_string, uom, auxInfoHash=Hash.new('')) @number = num @run_number = 0 @auxInfoHash = auxInfoHash @lap_seq = 1 @lap_distance = 0 lap_num = @auxInfoHash['lap_number'] if (lap_num && lap_num.size > 0) @lap_number = lap_num.to_i else @lap_number = 0 end # initialize superclass variables: @latitude = lat.to_s @longitude = lng.to_s @altitude = alt.to_f @uom = uom @altitude = @altitude * 3.2736 if (@uom == 'm') @heartbeat = hb.to_s if ((@heartbeat == nil) || (@heartbeat == '')) @heartbeat = -1 end @note = note.to_s @dttm = DtTm.new(time_string) @first = false @last = false @prev_tkpt = nil @cumulative_distance, @incremental_distance, @split = 0.0, 0.0, 0.0 @cumulative_pace = "" end |
Instance Attribute Details
#cumulative_distance ⇒ Object
Returns the value of attribute cumulative_distance.
14 15 16 |
# File 'lib/gooby_track_point.rb', line 14 def cumulative_distance @cumulative_distance end |
#cumulative_pace ⇒ Object
Returns the value of attribute cumulative_pace.
14 15 16 |
# File 'lib/gooby_track_point.rb', line 14 def cumulative_pace @cumulative_pace end |
#dttm ⇒ Object
Returns the value of attribute dttm.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def dttm @dttm end |
#first ⇒ Object
Returns the value of attribute first.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def first @first end |
#incremental_distance ⇒ Object
Returns the value of attribute incremental_distance.
14 15 16 |
# File 'lib/gooby_track_point.rb', line 14 def incremental_distance @incremental_distance end |
#lap_distance ⇒ Object
Returns the value of attribute lap_distance.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def lap_distance @lap_distance end |
#lap_elapsed ⇒ Object
Returns the value of attribute lap_elapsed.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def lap_elapsed @lap_elapsed end |
#lap_number ⇒ Object
Returns the value of attribute lap_number.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def lap_number @lap_number end |
#lap_seq ⇒ Object
Returns the value of attribute lap_seq.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def lap_seq @lap_seq end |
#last ⇒ Object
Returns the value of attribute last.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def last @last end |
#number ⇒ Object
Returns the value of attribute number.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def number @number end |
#prev_split ⇒ Object
Returns the value of attribute prev_split.
14 15 16 |
# File 'lib/gooby_track_point.rb', line 14 def prev_split @prev_split end |
#prev_tkpt ⇒ Object
Returns the value of attribute prev_tkpt.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def prev_tkpt @prev_tkpt end |
#run_id ⇒ Object
Returns the value of attribute run_id.
15 16 17 |
# File 'lib/gooby_track_point.rb', line 15 def run_id @run_id end |
#run_number ⇒ Object
Returns the value of attribute run_number.
13 14 15 |
# File 'lib/gooby_track_point.rb', line 13 def run_number @run_number end |
#run_start_dttm ⇒ Object
Returns the value of attribute run_start_dttm.
16 17 18 |
# File 'lib/gooby_track_point.rb', line 16 def run_start_dttm @run_start_dttm end |
#split ⇒ Object
Returns the value of attribute split.
14 15 16 |
# File 'lib/gooby_track_point.rb', line 14 def split @split end |
Class Method Details
.csv_header ⇒ Object
97 98 99 |
# File 'lib/gooby_track_point.rb', line 97 def self.csv_header "#cols: primary_key|run_id|date|time|tkpt_num|latitude|longitude|altitude|heartbeat|run_distance|uom|run_elapsed|lap_tkpt_number|lap_distance|lap_elapsed" end |
Instance Method Details
#as_glatlng(comment_out, gen_comments, tkpt_count, curr_idx, start_dttm) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/gooby_track_point.rb', line 183 def as_glatlng(comment_out, gen_comments, tkpt_count, curr_idx, start_dttm) comment_out ? comment = '// ' : comment = '' if gen_comments secs_diff = @dttm.seconds_diff(start_dttm) fmt_time = @dttm.hhmmss_diff(start_dttm) "\n #{comment}points.push(new GLatLng(#{latitude_as_float},#{longitude_as_float})); " + "// (#{curr_idx + 1} of #{tkpt_count}) #{@dttm.to_s} #{secs_diff} #{fmt_time} #{@cumulative_distance} #{split_info(start_dttm)} #{} " else "\n #{comment}points.push(new GLatLng(#{latitude_as_float},#{longitude_as_float})); // #{} " end end |
#as_info_window_html(checkpoint, start_dttm) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/gooby_track_point.rb', line 195 def as_info_window_html(checkpoint, start_dttm) s = "\"<table align='left'>" if checkpoint secs_diff = @dttm.seconds_diff(start_dttm) fmt_time = @dttm.hhmmss_diff(start_dttm) if checkpoint == 'Start' s << "<tr><td colspan='2'><b>Start!</b></td></tr>" elsif checkpoint == 'Finish' s << "<tr><td colspan='2'><b>Finish!</b></td></tr>" else if (@uom == 'km') s << "<tr><td colspan='2'><b>Kilometer #{checkpoint}</b></td></tr>" else s << "<tr><td colspan='2'><b>Mile #{checkpoint}</b></td></tr>" end end s << "<tr><td>Distance:</td><td>#{@cumulative_distance} #{@uom}</td></tr>" s << "<tr><td>Time of Day:</td><td>#{@dttm.to_s}</td></tr>" s << "<tr><td>Elapsed Time:</td><td>#{fmt_time}</td></tr>" s << "<tr><td>Average Pace:</td><td>#{@cumulative_pace}</td></tr>" s << "<tr><td>Lat/Lng:</td><td>#{latitude_as_float} , #{longitude_as_float}</td></tr>" s << "<tr><td>Altitude:</td><td>#{altitude_as_float}</td></tr>" if (@heartbeat && (@heartbeat.size > 1) && (@heartbeat.to_i > 0)) s << "<tr><td>Heartbeat:</td><td>#{@heartbeat}</td></tr>" end s end s << "</table>\"" s end |
#compute_cumulative_pace(start_dttm) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/gooby_track_point.rb', line 131 def compute_cumulative_pace(start_dttm) if @cumulative_distance > 0 secsDiff = @dttm.seconds_diff(start_dttm) secsMile = ((secsDiff.to_f) / (@cumulative_distance.to_f)) minsMile = (secsMile / 60) wholeMins = minsMile.floor fractMins = minsMile - (wholeMins.to_f) fractSecs = fractMins * 60 secsStr = fractSecs.to_s tokens = secsStr.split('.') whole, fract = '', '' if tokens.size > 1 whole = tokens[0] fract = tokens[1] fract = fract[0,3] if fract.size > 3 if (whole.to_f < 10) secsStr = "0#{whole}.#{fract}" else secsStr = "#{whole}.#{fract}" end end #s1 = " | #{secsDiff} #{secsMile} #{minsMile} #{wholeMins} #{fractMins} #{fractSecs} #{whole} #{fract} #{@cumulative_distance} " s2 = sprintf("%d:%5s", minsMile, secsStr) @cumulative_pace = "#{s2} per #{@uom}" else @cumulative_pace = "" end end |
#compute_distance_and_pace(curr_index, start_dttm, prev_cumulative_dist, prev_trackpoint) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gooby_track_point.rb', line 106 def compute_distance_and_pace(curr_index, start_dttm, prev_cumulative_dist, prev_trackpoint) @prev_tkpt = prev_trackpoint @cumulative_distance = prev_cumulative_dist.to_f @run_start_dttm = start_dttm if @prev_tkpt @incremental_distance = proximity(@prev_tkpt, @uom) if (!@incremental_distance.nan?) @cumulative_distance = @cumulative_distance + @incremental_distance.to_f if (@lap_number == prev_trackpoint.lap_number) @lap_seq = prev_trackpoint.lap_seq + 1 @lap_distance = prev_trackpoint.lap_distance + @incremental_distance else @lap_seq = 1 @lap_distance = @incremental_distance end end compute_cumulative_pace(start_dttm) @cumulative_distance else @lap_seq = 1 0 end end |
#is_split ⇒ Object
164 165 166 |
# File 'lib/gooby_track_point.rb', line 164 def is_split() (@split >= 1) end |
#point ⇒ Object
51 52 53 |
# File 'lib/gooby_track_point.rb', line 51 def point Point.new(@latitude, @longitude, @altitude, @note) end |
#position ⇒ Object
55 56 57 |
# File 'lib/gooby_track_point.rb', line 55 def position Point.new(@latitude, @longitude, @altitude, @note) end |
#set_split(n, tkpt) ⇒ Object
160 161 162 |
# File 'lib/gooby_track_point.rb', line 160 def set_split(n, tkpt) @split, @prev_split = n, tkpt end |
#split_info(dtTm) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/gooby_track_point.rb', line 168 def split_info(dtTm) if is_split hhmmss = '' if @prev_split return "#{@split} #{@dttm.hhmmss_diff(@prev_split.dttm())}" else return "#{@split} #{@dttm.hhmmss_diff(dtTm)}" end else "" end end |
#to_csv(prev_tkpt = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gooby_track_point.rb', line 63 def to_csv(prev_tkpt=nil) first_lap_start_time_s = @auxInfoHash['first_lap_start_time'] curr_lap_start_time_s = @auxInfoHash['curr_lap_start_time'] lap_elapsed = '' total_elapsed = '' if (first_lap_start_time_s && (first_lap_start_time_s.size > 0) && curr_lap_start_time_s && (curr_lap_start_time_s.size > 0)) # garmin205 & 305 first_lap_start_time = DtTm.new(first_lap_start_time_s) first_lap_start_time = @run_start_dttm curr_lap_start_time = DtTm.new(curr_lap_start_time_s) lap_elapsed = @dttm.hhmmss_diff(curr_lap_start_time) total_elapsed = @dttm.hhmmss_diff(first_lap_start_time) else # garmin 201 total_elapsed = @dttm.hhmmss_diff(@run_start_dttm) lap_elapsed = total_elapsed end delim = csv_delim csv = "#{@run_id}.#{@number}" # <-- primary key csv << "#{delim}#{@run_id}" csv << "#{delim}#{@dttm.yyyy_mm_dd_hh_mm_ss('|')}" csv << "#{delim}#{@number}" csv << "#{delim}#{position.to_csv}" csv << "#{delim}#{@heartbeat}" csv << "#{delim}#{@cumulative_distance}" csv << "#{delim}#{uom}" csv << "#{delim}#{total_elapsed}" csv << "#{delim}#{@lap_seq}" csv << "#{delim}#{@lap_distance}" csv << "#{delim}#{lap_elapsed}" csv end |
#to_geo_s ⇒ Object
101 102 103 104 |
# File 'lib/gooby_track_point.rb', line 101 def to_geo_s ss = position.to_csv "Tkpt: #{@number} | #{ss} | #{@descr}" end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/gooby_track_point.rb', line 59 def to_s "Tkpt: #{@number} #{super.to_s} date: #{@dttm.to_s} cdist: #{@cumulative_distance}" end |