Class: GoobyTrackpoint
Overview
Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license.
Constant Summary
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
#hash, #list
Instance Method Summary
collapse
#add, #base_initialize, #get, #id, #initialize, #sequence, #set
boolean_config_value, config_value, get_config, set_config
Methods included from GoobyIO
#read_file_as_lines, #write_file, #write_lines
#classname, included
#array_param, #boolean_param, #command_line_arg, #float_param, #integer_param, #string_param
Constructor Details
This class inherits a constructor from GoobyXmlObject
Instance Method Details
#activity_id ⇒ Object
42
43
44
|
# File 'lib/gooby_trackpoint.rb', line 42
def activity_id
get('ActivityId')
end
|
#altitude ⇒ Object
26
27
28
|
# File 'lib/gooby_trackpoint.rb', line 26
def altitude
altitude_meters * METERS_PER_FOOT
end
|
#altitude_meters ⇒ Object
34
35
36
|
# File 'lib/gooby_trackpoint.rb', line 34
def altitude_meters
get('AltitudeMeters').to_f
end
|
#altitude_rounded ⇒ Object
30
31
32
|
# File 'lib/gooby_trackpoint.rb', line 30
def altitude_rounded
sprintf("%5.1f", altitude)
end
|
#as_glatlng(comment_out, gen_comments, tkpt_count, curr_idx, start_dttm) ⇒ Object
194
195
196
197
|
# File 'lib/gooby_trackpoint.rb', line 194
def as_glatlng(, , tkpt_count, curr_idx, start_dttm)
? = '// ' : = ''
"\n #{}points.push(new GLatLng(#{latitude},#{longitude})); "
end
|
#as_info_window_html(checkpoint, start_dttm) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/gooby_trackpoint.rb', line 235
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)
td_style="style='padding-left:12px;padding-right:1px;'"
if checkpoint.to_i == 0
s << "<tr><td colspan='2'><b>Start!</b></td></tr>"
elsif checkpoint.to_i == 999999
s << "<tr><td colspan='2'><b>Finish!</b></td></tr>"
else
s << "<tr><td colspan='2'><b>Mile #{checkpoint}</b></td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_distance')
s << "<tr><td>Distance: </td><td #{td_style}>#{distance_rounded}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_elapsed_time')
s << "<tr><td>Elapsed Time: </td><td #{td_style}>#{elapsed_time}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_average_pace')
s << "<tr><td>Average Pace: </td><td #{td_style}>#{pace}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_average_mph')
s << "<tr><td>Average MPH: </td><td #{td_style}>#{mph}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_latutude')
s << "<tr><td>Latitude: </td><td #{td_style}>#{latitude}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_longitude')
s << "<tr><td>Longitude: </td><td #{td_style}>#{longitude}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_altitude')
s << "<tr><td>Altitude: </td><td #{td_style}>#{altitude_rounded}</td></tr>"
end
s
end
s << "</table>"
s
end
|
#as_one_point_info_window_html(label = nil) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'lib/gooby_trackpoint.rb', line 217
def as_one_point_info_window_html(label=nil)
td_style="style='padding-left:12px;padding-right:1px;'"
s = "\"<table align='left'>"
s << "<tr><td colspan='2'><b>#{label}</b></td></tr>" if label
if GoobyBaseObject.boolean_config_value('gmap_info_window_latutude')
s << "<tr><td>Latitude: </td><td #{td_style}>#{latitude}</td></tr>"
end
if GoobyBaseObject.boolean_config_value('gmap_info_window_longitude')
s << "<tr><td>Longitude: </td><td #{td_style}>#{longitude}</td></tr>"
end
s << "</table>\""
s
end
|
#as_quoted_info_window_html(checkpoint, start_dttm) ⇒ Object
231
232
233
|
# File 'lib/gooby_trackpoint.rb', line 231
def as_quoted_info_window_html(checkpoint, start_dttm)
"\"#{as_info_window_html(checkpoint, start_dttm)}\""
end
|
#compute_cumulative_pace_and_mph(first_tkpt_dttm) ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/gooby_trackpoint.rb', line 147
def compute_cumulative_pace_and_mph(first_tkpt_dttm)
if distance > 0.0
secs_diff = dttm.seconds_diff(first_tkpt_dttm)
secs_mile = ((secs_diff.to_f) / distance)
mins_mile = (secs_mile / 60.0)
whole_mins = mins_mile.floor
fract_mins = mins_mile - (whole_mins.to_f)
fract_secs = fract_mins * 60.0
if fract_secs < 10
pace = sprintf("%d:0%2.2f", whole_mins, fract_secs)
else
pace = sprintf("%d:%2.2f", whole_mins, fract_secs)
end
set('Pace', pace)
hours = secs_diff / 3600.0
mph = sprintf("%5.3f", distance / hours)
set('MPH', sprintf("%5.3f", mph))
else
set('Pace', '0:00')
set('MPH', '0.00')
end
end
|
#compute_elapsed_time(first_tkpt_dttm) ⇒ Object
143
144
145
|
# File 'lib/gooby_trackpoint.rb', line 143
def compute_elapsed_time(first_tkpt_dttm)
set('ElapsedTime', dttm.hhmmss_diff(first_tkpt_dttm))
end
|
#deg2rad(degrees) ⇒ Object
135
136
137
|
# File 'lib/gooby_trackpoint.rb', line 135
def deg2rad(degrees)
(((0.0 + degrees.to_f) * Math::PI) / 180.0)
end
|
#degrees_diff(another_tkpt) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/gooby_trackpoint.rb', line 74
def degrees_diff(another_tkpt)
if another_tkpt
lat_diff = latitude - another_tkpt.latitude
lng_diff = longitude - another_tkpt.longitude
lat_diff.abs + lng_diff.abs
else
360
end
end
|
#distance ⇒ Object
54
55
56
|
# File 'lib/gooby_trackpoint.rb', line 54
def distance
get('Distance').to_f
end
|
#distance_rounded ⇒ Object
58
59
60
|
# File 'lib/gooby_trackpoint.rb', line 58
def distance_rounded
sprintf("%3.3f", distance)
end
|
#dttm ⇒ Object
14
15
16
|
# File 'lib/gooby_trackpoint.rb', line 14
def dttm
GoobyDtTm.new(time)
end
|
#dump ⇒ Object
38
39
40
|
# File 'lib/gooby_trackpoint.rb', line 38
def dump
puts to_csv
end
|
#elapsed_time ⇒ Object
70
71
72
|
# File 'lib/gooby_trackpoint.rb', line 70
def elapsed_time
get('ElapsedTime')
end
|
#from_csv(row) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/gooby_trackpoint.rb', line 170
def from_csv(row)
if row && row.size > 12
set('ActivityId', row[1])
set('LapStartTime', row[2])
set('LapSeq', row[3])
set('Seq', row[4])
set('Time', row[5])
set('ElapsedTime', row[6])
set('LatitudeDegrees', row[7])
set('LongitudeDegrees', row[8])
set('AltitudeMeters', row[9])
set('Distance', row[10])
set('Pace', row[11])
set('MPH', row[12])
end
end
|
#lap_seq ⇒ Object
46
47
48
|
# File 'lib/gooby_trackpoint.rb', line 46
def lap_seq
get('LapSeq')
end
|
#lap_start_time ⇒ Object
50
51
52
|
# File 'lib/gooby_trackpoint.rb', line 50
def lap_start_time
get('LapStartTime')
end
|
#latitude ⇒ Object
18
19
20
|
# File 'lib/gooby_trackpoint.rb', line 18
def latitude
get('LatitudeDegrees').to_f
end
|
#longitude ⇒ Object
22
23
24
|
# File 'lib/gooby_trackpoint.rb', line 22
def longitude
get('LongitudeDegrees').to_f
end
|
#mph ⇒ Object
66
67
68
|
# File 'lib/gooby_trackpoint.rb', line 66
def mph
get('MPH')
end
|
#pace ⇒ Object
62
63
64
|
# File 'lib/gooby_trackpoint.rb', line 62
def pace
get('Pace')
end
|
#proximity(another_tkpt, uom = 'm') ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/gooby_trackpoint.rb', line 94
def proximity(another_tkpt, uom='m')
if same_location?(another_tkpt)
return 0.0
end
if another_tkpt
arg1 = latitude
arg2 = another_tkpt.latitude
arg3 = latitude
arg4 = another_tkpt.latitude
theta = longitude - another_tkpt.longitude
res1 = Math.sin(deg2rad(arg1))
res2 = Math.sin(deg2rad(arg2))
res3 = Math.cos(deg2rad(arg3))
res4 = Math.cos(deg2rad(arg4))
res5 = Math.cos(deg2rad(theta.to_f))
dist = ((res1 * res2) + (res3 * res4 * res5)).to_f
if !dist.nan?
dist = Math.acos(dist.to_f)
if (!dist.nan?)
dist = rad2deg(dist)
if !dist.nan?
dist = dist * 60.0 * 1.1515;
if !dist.nan?
if uom == "km"
dist = dist * 1.609344;
elsif uom == "n"
dist = dist * 0.8684;
end
end
end
end
return dist.to_f
else
return 0.0
end
else
return 0.0
end
end
|
#rad2deg(radians) ⇒ Object
139
140
141
|
# File 'lib/gooby_trackpoint.rb', line 139
def rad2deg(radians)
(((0.0 + radians.to_f) * 180.0) / Math::PI)
end
|
#same_location?(another_tkpt) ⇒ Boolean
84
85
86
87
88
89
90
91
92
|
# File 'lib/gooby_trackpoint.rb', line 84
def same_location?(another_tkpt)
if another_tkpt
return false if latitude != another_tkpt.latitude
return false if longitude != another_tkpt.longitude
true
else
false
end
end
|
#split? ⇒ Boolean
213
214
215
|
# File 'lib/gooby_trackpoint.rb', line 213
def split?
false
end
|
#split_info(a_dttm) ⇒ Object
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/gooby_trackpoint.rb', line 199
def split_info(a_dttm)
''
end
|
#time ⇒ Object
10
11
12
|
# File 'lib/gooby_trackpoint.rb', line 10
def time
get('Time')
end
|
#to_csv ⇒ Object
187
188
189
190
191
192
|
# File 'lib/gooby_trackpoint.rb', line 187
def to_csv
csv_string = FasterCSV.generate do | csv |
csv << ['Trackpoint', activity_id, lap_start_time, lap_seq, sequence, time, elapsed_time, latitude, longitude, altitude, distance, pace, mph ]
end
csv_string.strip
end
|