gooby 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/README +200 -35
  2. data/bin/code_scan.rb +1 -3
  3. data/bin/gooby_been_there.rb +12 -14
  4. data/bin/gooby_config.rb +11 -3
  5. data/bin/gooby_csv_validation.rb +50 -0
  6. data/bin/gooby_first_trackpoints_as_poi.rb +31 -0
  7. data/bin/gooby_gen_gmap.rb +7 -3
  8. data/bin/gooby_parser.rb +7 -5
  9. data/bin/gooby_splitter.rb +7 -4
  10. data/bin/gooby_version.rb +7 -3
  11. data/bin/run_all.sh +12 -2
  12. data/bin/run_been_there.sh +4 -1
  13. data/bin/run_config.sh +12 -0
  14. data/bin/run_csv_validation.sh +15 -0
  15. data/bin/run_db_gen.sh +1 -1
  16. data/bin/run_db_load.sh +1 -1
  17. data/bin/run_first_trackpoints_as_poi.sh +16 -0
  18. data/bin/run_gen_gmaps.sh +7 -6
  19. data/bin/run_parse_full.sh +45 -0
  20. data/bin/run_parse_samples.sh +21 -0
  21. data/bin/run_split.sh +5 -4
  22. data/bin/run_version.sh +12 -0
  23. data/config/gooby_config.yaml +130 -131
  24. data/data/20050305_corporate_cup_hm.csv +251 -251
  25. data/data/20050430_nashville_marathon_km.csv +1208 -0
  26. data/data/20060115_phoenix_marathon.csv +1280 -1280
  27. data/data/20070101_davidson_11m.csv +251 -0
  28. data/data/{davidson_11m_20070101.xml → 20070101_davidson_11m.xml} +0 -0
  29. data/data/{davidson_5K_20070505.xml → 20070505_davidson_5k.xml} +0 -0
  30. data/data/20070505_davidson_5k_km.csv +286 -0
  31. data/data/hrm1.csv +5 -0
  32. data/lib/gooby.rb +27 -3144
  33. data/lib/gooby_code_scanner.rb +288 -0
  34. data/lib/gooby_command.rb +210 -0
  35. data/lib/gooby_configuration.rb +123 -0
  36. data/lib/gooby_counter_hash.rb +95 -0
  37. data/lib/gooby_course.rb +117 -0
  38. data/lib/gooby_csv_point.rb +71 -0
  39. data/lib/gooby_csv_reader.rb +71 -0
  40. data/lib/gooby_csv_run.rb +28 -0
  41. data/lib/gooby_delim_line.rb +42 -0
  42. data/lib/gooby_dttm.rb +87 -0
  43. data/lib/gooby_duration.rb +86 -0
  44. data/lib/gooby_forerunner_xml_parser.rb +191 -0
  45. data/lib/gooby_forerunner_xml_splitter.rb +115 -0
  46. data/lib/gooby_google_map_generator.rb +385 -0
  47. data/lib/gooby_history.rb +41 -0
  48. data/lib/gooby_kernel.rb +163 -0
  49. data/lib/gooby_lap.rb +30 -0
  50. data/lib/gooby_line.rb +80 -0
  51. data/lib/gooby_object.rb +22 -0
  52. data/lib/gooby_point.rb +172 -0
  53. data/lib/gooby_run.rb +213 -0
  54. data/lib/gooby_simple_xml_parser.rb +50 -0
  55. data/lib/gooby_test_helper.rb +23 -0
  56. data/lib/gooby_track.rb +47 -0
  57. data/lib/gooby_track_point.rb +229 -0
  58. data/lib/gooby_training_center_xml_parser.rb +224 -0
  59. data/lib/gooby_training_center_xml_splitter.rb +116 -0
  60. data/lib/split_code.sh +29 -0
  61. data/samples/20050305_corporate_cup_hm.html +269 -269
  62. data/samples/20050430_nashville_marathon.html +1410 -1266
  63. data/samples/20060115_phoenix_marathon.html +1311 -1311
  64. data/samples/{davidson_11m_20070101.html → 20070101_davidson_11m.html} +267 -267
  65. data/samples/20070505_davidson_5k.html +413 -0
  66. data/samples/been_there.txt +52 -704
  67. data/samples/hrm1.html +87 -0
  68. data/sql/gooby.ddl +20 -16
  69. data/sql/gooby_load.dml +36 -9
  70. metadata +48 -14
  71. data/bin/example_usage.txt +0 -55
  72. data/bin/run_parse.sh +0 -43
  73. data/bin/run_parse_named.sh +0 -19
  74. data/data/20050430_nashville_marathon.csv +0 -1208
  75. data/data/davidson_11m_20070101.csv +0 -251
  76. data/data/davidson_5K_20070505.csv +0 -286
  77. data/data/test1.txt +0 -4
  78. data/samples/davidson_5K_20070505.html +0 -395
data/lib/gooby_lap.rb ADDED
@@ -0,0 +1,30 @@
1
+ =begin
2
+
3
+ Gooby = Google APIs + Ruby
4
+ Gooby - Copyright 2007 by Chris Joakim.
5
+ Gooby is available under GNU General Public License (GPL) license.
6
+
7
+ =end
8
+
9
+ module Gooby
10
+
11
+ =begin rdoc
12
+ Instances of this class represent a <Lap> aggregate object from a
13
+ Forerunner XML file.
14
+ =end
15
+
16
+ class Lap < GoobyObject
17
+
18
+ attr_accessor :number, :startTime, :duration, :length, :begin_position, :end_position
19
+
20
+ def initialize(num)
21
+ @number = num
22
+ end
23
+
24
+ def to_s
25
+ return "Lap: num: #{@number} start: #{@startTime} dur: #{@duration} len: #{@length} begin: #{@begin_position.to_s} end: #{@end_position.to_s}"
26
+ end
27
+
28
+ end
29
+
30
+ end # end of module
data/lib/gooby_line.rb ADDED
@@ -0,0 +1,80 @@
1
+ =begin
2
+
3
+ Gooby = Google APIs + Ruby
4
+ Gooby - Copyright 2007 by Chris Joakim.
5
+ Gooby is available under GNU General Public License (GPL) license.
6
+
7
+ =end
8
+
9
+ module Gooby
10
+
11
+ class Line < GoobyObject
12
+
13
+ attr_accessor :raw_data, :tokens
14
+
15
+ def initialize(raw='', delim=nil, strip=false)
16
+ if strip
17
+ @raw_data = raw.strip
18
+ else
19
+ @raw_data = raw
20
+ end
21
+
22
+ @tokens = tokenize(@raw_data, delim, strip=false)
23
+ end
24
+
25
+ public
26
+
27
+ def token(idx)
28
+ @tokens[idx]
29
+ end
30
+
31
+ def token_count
32
+ @tokens.size
33
+ end
34
+
35
+ def token_idx_equals(idx, value)
36
+ if idx < token_count
37
+ if @tokens[idx] == value
38
+ return true
39
+ end
40
+ end
41
+ false
42
+ end
43
+
44
+ def match(pattern)
45
+ @raw_data.match(pattern)
46
+ end
47
+
48
+ def is_comment
49
+ s = @raw_data.strip
50
+ (s.match('^#')) ? true : false
51
+ end
52
+
53
+ def is_populated_non_comment
54
+ s = @raw_data.strip
55
+ if s.size == 0
56
+ return false
57
+ end
58
+ if is_comment
59
+ return false
60
+ end
61
+ return true
62
+ end
63
+
64
+ def concatinate_tokens(start_idx = 0)
65
+ s = ''
66
+ idx = -1
67
+ @tokens.each { |tok|
68
+ idx = idx + 1
69
+ if idx >= start_idx
70
+ s << tok
71
+ s << ' '
72
+ end
73
+ }
74
+ s.strip!
75
+ s
76
+ end
77
+
78
+ end
79
+
80
+ end # end of module
@@ -0,0 +1,22 @@
1
+ =begin
2
+
3
+ Gooby = Google APIs + Ruby
4
+ Gooby - Copyright 2007 by Chris Joakim.
5
+ Gooby is available under GNU General Public License (GPL) license.
6
+
7
+ =end
8
+
9
+ module Gooby
10
+
11
+ =begin rdoc
12
+ This is the abstract superclass of several Gooby classes.
13
+ It includes module GoobyKernel.
14
+ =end
15
+
16
+ class GoobyObject
17
+
18
+ include Gooby::GoobyKernel
19
+
20
+ end
21
+
22
+ end # end of module
@@ -0,0 +1,172 @@
1
+ =begin
2
+
3
+ Gooby = Google APIs + Ruby
4
+ Gooby - Copyright 2007 by Chris Joakim.
5
+ Gooby is available under GNU General Public License (GPL) license.
6
+
7
+ =end
8
+
9
+ module Gooby
10
+
11
+ class Point < GoobyObject
12
+
13
+ attr_accessor :number, :latitude, :longitude, :altitude, :uom, :note
14
+
15
+ def initialize(*args)
16
+ @number, @latitude, @longitude, @altitude, @uom, @heartbeat, @note = '', '', '', '', 'm', -1, ''
17
+ if args
18
+ if args.size == 1
19
+ initialize_from_string(args[0]) # yaml
20
+ else
21
+ initialize_from_array(args)
22
+ end
23
+ end
24
+ end
25
+
26
+ def csv_delim
27
+ '|'
28
+ end
29
+
30
+ def english_system
31
+ if @uom
32
+ (@uom == 'm') ? true : false
33
+ else
34
+ return true # english is the default
35
+ end
36
+ end
37
+
38
+ def metric_system
39
+ return false if !english_system
40
+ end
41
+
42
+ def initialize_from_array(args)
43
+ @latitude = args[0] if args.size > 0
44
+ @longitude = args[1] if args.size > 1
45
+ @altitude = args[2] if args.size > 2
46
+ @note = args[3] if args.size > 3
47
+ end
48
+
49
+ def initialize_from_string(yaml_value_string)
50
+ tokens = yaml_value_string.split
51
+ if (tokens.size > 2)
52
+ @latitude = tokens[0]
53
+ @longitude = tokens[1]
54
+ @note = ''
55
+ count = 0
56
+ tokens.each { |tok|
57
+ count = count + 1
58
+ if (count > 2)
59
+ @note << tok
60
+ @note << ' '
61
+ end
62
+ }
63
+ end
64
+ end
65
+
66
+ public
67
+
68
+ def has_coordinates?
69
+ return false if @latitude == nil
70
+ return false if @latitude.size < 1
71
+ return false if @longitude == nil
72
+ return false if @longitude .size < 1
73
+ return true
74
+ end
75
+
76
+ def to_s
77
+ return "lat: #{@latitude} lng: #{@longitude} alt: #{@altitude} note: #{@note}"
78
+ end
79
+
80
+ def to_formatted_string
81
+ s = "lat: #{@latitude.to_s.ljust(20)}"
82
+ s << " lng: #{@longitude.to_s.ljust(20)}"
83
+ s << " poi.#{@number.to_s.ljust(12)}" if @number
84
+ s << " #{@note}" if @note
85
+ s
86
+ end
87
+
88
+ def to_csv
89
+ return "#{@latitude}#{csv_delim}#{@longitude}#{csv_delim}#{@altitude}"
90
+ end
91
+
92
+ def latitude_as_float
93
+ @latitude ? @latitude.to_f : invalid_latitude
94
+ end
95
+
96
+ def longitude_as_float
97
+ @longitude ? @longitude.to_f : invalid_longitude
98
+ end
99
+
100
+ def altitude_as_float
101
+ @altitude ? @altitude.to_f : invalid_altitude
102
+ end
103
+
104
+ def heartbeat_as_float
105
+ @heartbeat? @heartbeat.to_f : invalid_heartbeat
106
+ end
107
+
108
+ def degrees_diff(another_point)
109
+ if (another_point)
110
+ puts "this: #{to_s}" if false
111
+ puts "other: #{another_point.to_s}" if false
112
+ puts "lats: #{latitude_as_float} #{another_point.latitude_as_float}" if false
113
+ puts "lngs: #{longitude_as_float} #{another_point.longitude_as_float}" if false
114
+ lat_diff = latitude_as_float - another_point.latitude_as_float
115
+ lng_diff = longitude_as_float - another_point.longitude_as_float
116
+ diff = lat_diff.abs + lng_diff.abs
117
+ puts "diff: #{diff} #{lat_diff} #{lng_diff}" if false
118
+ diff
119
+ else
120
+ 360
121
+ end
122
+ end
123
+
124
+ def proximity(another_point, uom)
125
+ if (another_point)
126
+ arg1 = latitude_as_float
127
+ arg2 = another_point.latitude_as_float
128
+ arg3 = latitude_as_float
129
+ arg4 = another_point.latitude_as_float
130
+ theta = longitude_as_float - another_point.longitude_as_float
131
+ res1 = Math.sin(deg2rad(arg1))
132
+ res2 = Math.sin(deg2rad(arg2))
133
+ res3 = Math.cos(deg2rad(arg3))
134
+ res4 = Math.cos(deg2rad(arg4))
135
+ res5 = Math.cos(deg2rad(theta.to_f))
136
+ dist = ((res1 * res2) + (res3 * res4 * res5)).to_f
137
+
138
+ if (!dist.nan?)
139
+ dist = Math.acos(dist.to_f)
140
+ if (!dist.nan?)
141
+ dist = rad2deg(dist)
142
+ if (!dist.nan?)
143
+ dist = dist * 60 * 1.1515;
144
+ if (!dist.nan?)
145
+ if uom == "km"
146
+ dist = dist * 1.609344;
147
+ end
148
+ if uom == "n"
149
+ dist = dist * 0.8684;
150
+ end
151
+ end
152
+ end
153
+ end
154
+ return dist.to_f
155
+ else
156
+ return 0
157
+ end
158
+ else
159
+ return 0
160
+ end
161
+ end
162
+
163
+ def deg2rad(degrees)
164
+ (((0 + degrees) * Math::PI) / 180)
165
+ end
166
+
167
+ def rad2deg(radians)
168
+ (((0 + radians) * 180) / Math::PI)
169
+ end
170
+ end
171
+
172
+ end # end of module
data/lib/gooby_run.rb ADDED
@@ -0,0 +1,213 @@
1
+ =begin
2
+
3
+ Gooby = Google APIs + Ruby
4
+ Gooby - Copyright 2007 by Chris Joakim.
5
+ Gooby is available under GNU General Public License (GPL) license.
6
+
7
+ =end
8
+
9
+ module Gooby
10
+
11
+ =begin rdoc
12
+ Instances of this class represent a <Run> aggregate object from a
13
+ Forerunner XML file.
14
+
15
+ Additionally, there is distance, pace, and Google Map generation logic
16
+ in this class.
17
+ =end
18
+
19
+ class Run < GoobyObject
20
+
21
+ attr_accessor :number, :run_id, :descr, :notes, :tracks, :tkpts, :laps, :distance
22
+
23
+ def initialize(number=0, descr='')
24
+ @number = number
25
+ @run_id = nil
26
+ @descr = descr
27
+ @notes = ''
28
+ @tracks = Array.new
29
+ @tkpts = Array.new
30
+ @laps = Array.new
31
+ @distance = 0
32
+ @configuration = Hash.new
33
+ @logProgress = true
34
+ @finished = false
35
+ end
36
+
37
+ public
38
+
39
+ # This method is invoked at end-of-parsing.
40
+ def finish()
41
+ @logProgress = false
42
+ unless @finished
43
+ @tracks.each { |trk|
44
+ trk.trackpoints().each { |tkpt|
45
+ tkpt.run_number = @number
46
+ @tkpts.push(tkpt)
47
+ }
48
+ }
49
+ compute_distance_and_pace
50
+ compute_splits
51
+ set_run_ids
52
+ @finished = true
53
+ end
54
+ end
55
+
56
+ public
57
+
58
+ def add_track(trk)
59
+ if trk != nil
60
+ @tracks.push(trk)
61
+ end
62
+ end
63
+
64
+ def trackpoint_count()
65
+ @tkpts.size()
66
+ end
67
+
68
+ def add_lap(lap)
69
+ @laps.push(lap)
70
+ end
71
+
72
+ def lap_count()
73
+ @laps.size
74
+ end
75
+
76
+ def start_dttm()
77
+ count = 0
78
+ @tracks.each { |trk|
79
+ trk.trackpoints().each { |tkpt|
80
+ return tkpt.dttm()
81
+ }
82
+ }
83
+ return nil
84
+ end
85
+
86
+ def end_dttm()
87
+ lastOne = nil
88
+ @tracks.each { |trk|
89
+ trk.trackpoints().each { |tkpt|
90
+ lastOne = tkpt.dttm()
91
+ }
92
+ }
93
+ lastOne
94
+ end
95
+
96
+ def duration()
97
+ first = start_dttm()
98
+ last = end_dttm()
99
+ if first
100
+ if last
101
+ return last.hhmmss_diff(first)
102
+ end
103
+ end
104
+ return "00:00:00"
105
+ end
106
+
107
+ def start_yyyy_mm_dd
108
+ if start_dttm()
109
+ start_dttm().yyyy_mm_dd()
110
+ else
111
+ ""
112
+ end
113
+ end
114
+
115
+ def start_hh_mm_ss
116
+ if start_dttm()
117
+ start_dttm().hh_mm_ss()
118
+ else
119
+ ""
120
+ end
121
+ end
122
+
123
+ def end_hh_mm_ss
124
+ if end_dttm()
125
+ end_dttm().hh_mm_ss()
126
+ else
127
+ ""
128
+ end
129
+ end
130
+
131
+ def to_s
132
+ finish() unless @finished
133
+ s = "Run: #{@number} date: #{start_yyyy_mm_dd} distance: #{distance} duration: #{duration} "
134
+ s << " tracks: #{@tracks.size} tkpts: #{trackpoint_count} laps: #{lap_count} "
135
+ s << " notes: #{@notes} "
136
+ s
137
+ end
138
+
139
+ def print_string
140
+ finish() unless @finished
141
+ "Run number=#{@number} tracks=#{@tracks.size} tkpts=#{@tkpts.size} laps=#{@laps.size} distance=#{@distance} "
142
+ end
143
+
144
+ def put_csv()
145
+ finish() unless @finished
146
+ puts "#{@number}|#{}|#{start_yyyy_mm_dd()}|#{start_hh_mm_ss()}|#{end_hh_mm_ss}|#{duration()}|#{@distance}|#{@tracks.size}|#{trackpoint_count()}|#{lap_count}|#{@notes.strip}"
147
+ end
148
+
149
+ def put_tkpt_csv()
150
+ finish() unless @finished
151
+ @tkpts.each { | tkpt |
152
+ @prev_tkpt = tkpt if (@prev_tkpt == nil)
153
+ puts tkpt.to_csv(@prev_tkpt)
154
+ }
155
+ end
156
+
157
+ def put_laps
158
+ @laps.each { | lap | puts lap.to_s }
159
+ end
160
+
161
+ private
162
+
163
+ def compute_distance_and_pace
164
+ cumulative_dist = 0.to_f;
165
+ curr_index = -1
166
+ prev_tkpt = nil
167
+ start_dttm = nil
168
+ @tkpts.each { | tkpt |
169
+ curr_index = curr_index + 1
170
+ if curr_index == 0
171
+ start_dttm = tkpt.dttm()
172
+ prev_tkpt = tkpt
173
+ else
174
+ cumulative_dist = tkpt.compute_distance_and_pace(curr_index, start_dttm, cumulative_dist, prev_tkpt)
175
+ prev_tkpt = tkpt
176
+ end
177
+ }
178
+ @distance = cumulative_dist
179
+ end
180
+
181
+ def compute_splits
182
+ nextSplitDist = 1.00
183
+ prev_splitTkpt = nil
184
+ loop1Count = 0;
185
+ @tkpts.each { |tkpt|
186
+ loop1Count = loop1Count + 1
187
+ if tkpt.cumulative_distance() >= nextSplitDist
188
+ tkpt.set_split(0 + nextSplitDist, prev_splitTkpt)
189
+ nextSplitDist = nextSplitDist + 1.00
190
+ prev_splitTkpt = tkpt
191
+ end
192
+ }
193
+ # set first and last booleans
194
+ count = 0
195
+ @tkpts.each { |tkpt|
196
+ count = count + 1
197
+ tkpt.first = true if count == 1
198
+ tkpt.last = true if count == loop1Count
199
+ }
200
+ end
201
+
202
+ def set_run_ids
203
+ @tkpts.each { |tkpt|
204
+ if (@run_id == nil)
205
+ @run_id = tkpt.dttm.rawdata
206
+ end
207
+ tkpt.run_id = @run_id
208
+ }
209
+ end
210
+
211
+ end
212
+
213
+ end # end of module