gooby 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (257) hide show
  1. data/README +133 -341
  2. data/config/ballantyne.yaml +11 -0
  3. data/config/big_sur_marathon.yaml +11 -0
  4. data/config/crowders_mtn_hike.yaml +11 -0
  5. data/config/davidson1.yaml +16 -0
  6. data/config/gooby_config.yaml +28 -135
  7. data/cucumber.yml +1 -0
  8. data/features/build_gem.feature +88 -0
  9. data/features/gooby.feature +300 -0
  10. data/features/install.feature +78 -0
  11. data/features/steps/gooby_steps.rb +245 -0
  12. data/features/support/env.rb +4 -0
  13. data/lib/gooby.rb +24 -30
  14. data/lib/gooby_activity.rb +63 -0
  15. data/lib/gooby_base_object.rb +46 -0
  16. data/lib/gooby_base_sax_parser.rb +95 -0
  17. data/lib/gooby_configuration.rb +33 -115
  18. data/lib/gooby_counter_hash.rb +28 -87
  19. data/lib/gooby_dttm.rb +88 -66
  20. data/lib/gooby_environment.rb +48 -0
  21. data/lib/gooby_garmin_tcx_parser.rb +92 -0
  22. data/lib/gooby_google_kml_generator.rb +168 -0
  23. data/lib/gooby_google_map_generator.rb +284 -349
  24. data/lib/gooby_gpx_parser.rb +97 -0
  25. data/lib/gooby_help_producer.rb +40 -0
  26. data/lib/gooby_introspection.rb +25 -0
  27. data/lib/gooby_io.rb +30 -0
  28. data/lib/gooby_lap.rb +27 -18
  29. data/lib/gooby_process.rb +281 -0
  30. data/lib/gooby_sax_path_parser.rb +43 -0
  31. data/lib/gooby_tcx_extractor.rb +71 -0
  32. data/lib/gooby_track_log_parser.rb +114 -0
  33. data/lib/gooby_trackpoint.rb +276 -0
  34. data/lib/gooby_xml_object.rb +40 -0
  35. data/{img/gicons → out/images}/blank.png +0 -0
  36. data/{img/gicons → out/images}/dd-end.png +0 -0
  37. data/{img/gicons → out/images}/dd-start.png +0 -0
  38. data/{img/gicons → out/images}/marker.png +0 -0
  39. data/{img/gicons → out/images}/marker0.png +0 -0
  40. data/{img/gicons → out/images}/marker00.png +0 -0
  41. data/{img/gicons → out/images}/marker01.png +0 -0
  42. data/{img/gicons → out/images}/marker02.png +0 -0
  43. data/{img/gicons → out/images}/marker03.png +0 -0
  44. data/{img/gicons → out/images}/marker04.png +0 -0
  45. data/{img/gicons → out/images}/marker05.png +0 -0
  46. data/{img/gicons → out/images}/marker06.png +0 -0
  47. data/{img/gicons → out/images}/marker07.png +0 -0
  48. data/{img/gicons → out/images}/marker08.png +0 -0
  49. data/{img/gicons → out/images}/marker09.png +0 -0
  50. data/{img/gicons → out/images}/marker1.png +0 -0
  51. data/{img/gicons → out/images}/marker10.png +0 -0
  52. data/{img/gicons → out/images}/marker11.png +0 -0
  53. data/{img/gicons → out/images}/marker12.png +0 -0
  54. data/{img/gicons → out/images}/marker13.png +0 -0
  55. data/{img/gicons → out/images}/marker14.png +0 -0
  56. data/{img/gicons → out/images}/marker15.png +0 -0
  57. data/{img/gicons → out/images}/marker16.png +0 -0
  58. data/{img/gicons → out/images}/marker17.png +0 -0
  59. data/{img/gicons → out/images}/marker18.png +0 -0
  60. data/{img/gicons → out/images}/marker19.png +0 -0
  61. data/{img/gicons → out/images}/marker2.png +0 -0
  62. data/{img/gicons → out/images}/marker20.png +0 -0
  63. data/{img/gicons → out/images}/marker21.png +0 -0
  64. data/{img/gicons → out/images}/marker22.png +0 -0
  65. data/{img/gicons → out/images}/marker23.png +0 -0
  66. data/{img/gicons → out/images}/marker24.png +0 -0
  67. data/{img/gicons → out/images}/marker25.png +0 -0
  68. data/{img/gicons → out/images}/marker26.png +0 -0
  69. data/{img/gicons → out/images}/marker27.png +0 -0
  70. data/{img/gicons → out/images}/marker28.png +0 -0
  71. data/{img/gicons → out/images}/marker29.png +0 -0
  72. data/{img/gicons → out/images}/marker3.png +0 -0
  73. data/{img/gicons → out/images}/marker30.png +0 -0
  74. data/{img/gicons → out/images}/marker31.png +0 -0
  75. data/{img/gicons → out/images}/marker32.png +0 -0
  76. data/{img/gicons → out/images}/marker33.png +0 -0
  77. data/{img/gicons → out/images}/marker34.png +0 -0
  78. data/{img/gicons → out/images}/marker35.png +0 -0
  79. data/{img/gicons → out/images}/marker36.png +0 -0
  80. data/{img/gicons → out/images}/marker37.png +0 -0
  81. data/{img/gicons → out/images}/marker38.png +0 -0
  82. data/{img/gicons → out/images}/marker39.png +0 -0
  83. data/{img/gicons → out/images}/marker4.png +0 -0
  84. data/{img/gicons → out/images}/marker40.png +0 -0
  85. data/{img/gicons → out/images}/marker41.png +0 -0
  86. data/{img/gicons → out/images}/marker42.png +0 -0
  87. data/{img/gicons → out/images}/marker43.png +0 -0
  88. data/{img/gicons → out/images}/marker44.png +0 -0
  89. data/{img/gicons → out/images}/marker45.png +0 -0
  90. data/{img/gicons → out/images}/marker46.png +0 -0
  91. data/{img/gicons → out/images}/marker47.png +0 -0
  92. data/{img/gicons → out/images}/marker48.png +0 -0
  93. data/{img/gicons → out/images}/marker49.png +0 -0
  94. data/{img/gicons → out/images}/marker5.png +0 -0
  95. data/{img/gicons → out/images}/marker50.png +0 -0
  96. data/{img/gicons → out/images}/marker51.png +0 -0
  97. data/{img/gicons → out/images}/marker52.png +0 -0
  98. data/{img/gicons → out/images}/marker53.png +0 -0
  99. data/{img/gicons → out/images}/marker54.png +0 -0
  100. data/{img/gicons → out/images}/marker55.png +0 -0
  101. data/{img/gicons → out/images}/marker56.png +0 -0
  102. data/{img/gicons → out/images}/marker57.png +0 -0
  103. data/{img/gicons → out/images}/marker58.png +0 -0
  104. data/{img/gicons → out/images}/marker59.png +0 -0
  105. data/{img/gicons → out/images}/marker6.png +0 -0
  106. data/{img/gicons → out/images}/marker60.png +0 -0
  107. data/{img/gicons → out/images}/marker61.png +0 -0
  108. data/{img/gicons → out/images}/marker62.png +0 -0
  109. data/{img/gicons → out/images}/marker63.png +0 -0
  110. data/{img/gicons → out/images}/marker64.png +0 -0
  111. data/{img/gicons → out/images}/marker65.png +0 -0
  112. data/{img/gicons → out/images}/marker66.png +0 -0
  113. data/{img/gicons → out/images}/marker67.png +0 -0
  114. data/{img/gicons → out/images}/marker68.png +0 -0
  115. data/{img/gicons → out/images}/marker69.png +0 -0
  116. data/{img/gicons → out/images}/marker7.png +0 -0
  117. data/{img/gicons → out/images}/marker70.png +0 -0
  118. data/{img/gicons → out/images}/marker71.png +0 -0
  119. data/{img/gicons → out/images}/marker72.png +0 -0
  120. data/{img/gicons → out/images}/marker73.png +0 -0
  121. data/{img/gicons → out/images}/marker74.png +0 -0
  122. data/{img/gicons → out/images}/marker75.png +0 -0
  123. data/{img/gicons → out/images}/marker76.png +0 -0
  124. data/{img/gicons → out/images}/marker77.png +0 -0
  125. data/{img/gicons → out/images}/marker78.png +0 -0
  126. data/{img/gicons → out/images}/marker79.png +0 -0
  127. data/{img/gicons → out/images}/marker8.png +0 -0
  128. data/{img/gicons → out/images}/marker80.png +0 -0
  129. data/{img/gicons → out/images}/marker81.png +0 -0
  130. data/{img/gicons → out/images}/marker82.png +0 -0
  131. data/{img/gicons → out/images}/marker83.png +0 -0
  132. data/{img/gicons → out/images}/marker84.png +0 -0
  133. data/{img/gicons → out/images}/marker85.png +0 -0
  134. data/{img/gicons → out/images}/marker86.png +0 -0
  135. data/{img/gicons → out/images}/marker87.png +0 -0
  136. data/{img/gicons → out/images}/marker88.png +0 -0
  137. data/{img/gicons → out/images}/marker89.png +0 -0
  138. data/{img/gicons → out/images}/marker9.png +0 -0
  139. data/{img/gicons → out/images}/marker90.png +0 -0
  140. data/{img/gicons → out/images}/marker91.png +0 -0
  141. data/{img/gicons → out/images}/marker92.png +0 -0
  142. data/{img/gicons → out/images}/marker93.png +0 -0
  143. data/{img/gicons → out/images}/marker94.png +0 -0
  144. data/{img/gicons → out/images}/marker95.png +0 -0
  145. data/{img/gicons → out/images}/marker96.png +0 -0
  146. data/{img/gicons → out/images}/marker97.png +0 -0
  147. data/{img/gicons → out/images}/marker98.png +0 -0
  148. data/{img/gicons → out/images}/marker99.png +0 -0
  149. data/{img/gicons → out/images}/markerA.png +0 -0
  150. data/{img/gicons → out/images}/markerB.png +0 -0
  151. data/{img/gicons → out/images}/markerC.png +0 -0
  152. data/{img/gicons → out/images}/markerD.png +0 -0
  153. data/{img/gicons → out/images}/markerE.png +0 -0
  154. data/{img/gicons → out/images}/markerF.png +0 -0
  155. data/{img/gicons → out/images}/markerG.png +0 -0
  156. data/{img/gicons → out/images}/markerH.png +0 -0
  157. data/{img/gicons → out/images}/markerI.png +0 -0
  158. data/{img/gicons → out/images}/markerJ.png +0 -0
  159. data/{img/gicons → out/images}/mm_20_red.png +0 -0
  160. data/{img/gicons → out/images}/mm_20_shadow.png +0 -0
  161. data/{img/gicons → out/images}/shadow50.png +0 -0
  162. data/rakefile.rb +79 -0
  163. data/samples.sh +21 -0
  164. data/samples/2008_04_27_13_49_50_tcx.csv +2449 -0
  165. data/samples/2008_04_27_13_49_50_tcx.xml +24560 -0
  166. data/samples/2009_01_01_14_45_00_tcx.xml +10630 -0
  167. data/samples/ballantyne.csv +27 -0
  168. data/samples/ballantyne.gpx +117 -0
  169. data/samples/ballantyne.kml +91 -0
  170. data/samples/big_sur_marathon.html +2766 -0
  171. data/samples/big_sur_marathon.kml +685 -0
  172. data/samples/build_gem_test_results.txt +6 -0
  173. data/samples/crowders_mtn_hike.csv +1065 -0
  174. data/samples/crowders_mtn_hike.html +1283 -0
  175. data/samples/crowders_mtn_hike.log +1 -0
  176. data/samples/cucumber_test_results.txt +302 -0
  177. data/samples/davidson1.csv +1 -0
  178. data/samples/davidson1.html +75 -0
  179. data/samples/davidson_1_point_tcx.csv +0 -0
  180. data/samples/doc.kml +49 -0
  181. data/samples/gps_track_log_asheville_mt_pisgah.txt +1 -0
  182. data/samples/gps_track_logs.txt +1 -0
  183. data/samples/install_test_results.txt +81 -0
  184. data/samples/mt_pisgah.txt +1 -0
  185. data/samples/rspec_test_results.txt +5 -0
  186. data/setup.rb +66 -0
  187. data/spec/gooby_base_object_spec.rb +116 -0
  188. data/spec/gooby_counter_hash_spec.rb +34 -0
  189. data/spec/gooby_dttm_spec.rb +40 -0
  190. data/spec/gooby_spec_helper.rb +9 -0
  191. data/spec/gooby_xml_object_spec.rb +32 -0
  192. metadata +225 -226
  193. data/bin/code_scan.rb +0 -16
  194. data/bin/gooby_been_there.rb +0 -33
  195. data/bin/gooby_config.rb +0 -24
  196. data/bin/gooby_csv_validation.rb +0 -50
  197. data/bin/gooby_first_trackpoints_as_poi.rb +0 -31
  198. data/bin/gooby_gen_gmap.rb +0 -20
  199. data/bin/gooby_parser.rb +0 -21
  200. data/bin/gooby_splitter.rb +0 -21
  201. data/bin/gooby_version.rb +0 -20
  202. data/bin/run_all.sh +0 -33
  203. data/bin/run_been_there.sh +0 -19
  204. data/bin/run_config.sh +0 -12
  205. data/bin/run_csv_validation.sh +0 -15
  206. data/bin/run_db_gen.sh +0 -11
  207. data/bin/run_db_load.sh +0 -11
  208. data/bin/run_first_trackpoints_as_poi.sh +0 -16
  209. data/bin/run_gen_gmaps.sh +0 -21
  210. data/bin/run_parse_full.sh +0 -45
  211. data/bin/run_parse_samples.sh +0 -21
  212. data/bin/run_split.sh +0 -24
  213. data/bin/run_version.sh +0 -12
  214. data/data/20050305_corporate_cup_hm.csv +0 -251
  215. data/data/20050305_corporate_cup_hm.xml +0 -2208
  216. data/data/20050430_nashville_marathon.xml +0 -10043
  217. data/data/20050430_nashville_marathon_km.csv +0 -1208
  218. data/data/20060115_phoenix_marathon.csv +0 -1280
  219. data/data/20060115_phoenix_marathon.xml +0 -10620
  220. data/data/20070101_davidson_11m.csv +0 -251
  221. data/data/20070101_davidson_11m.xml +0 -2020
  222. data/data/20070505_davidson_5k.xml +0 -2875
  223. data/data/20070505_davidson_5k_km.csv +0 -286
  224. data/data/hrm1.csv +0 -5
  225. data/img/gicons/readme.txt +0 -14
  226. data/lib/gooby_code_scanner.rb +0 -288
  227. data/lib/gooby_command.rb +0 -210
  228. data/lib/gooby_course.rb +0 -117
  229. data/lib/gooby_csv_point.rb +0 -71
  230. data/lib/gooby_csv_reader.rb +0 -71
  231. data/lib/gooby_csv_run.rb +0 -28
  232. data/lib/gooby_delim_line.rb +0 -42
  233. data/lib/gooby_duration.rb +0 -86
  234. data/lib/gooby_forerunner_xml_parser.rb +0 -191
  235. data/lib/gooby_forerunner_xml_splitter.rb +0 -115
  236. data/lib/gooby_history.rb +0 -41
  237. data/lib/gooby_kernel.rb +0 -163
  238. data/lib/gooby_line.rb +0 -80
  239. data/lib/gooby_object.rb +0 -22
  240. data/lib/gooby_point.rb +0 -172
  241. data/lib/gooby_run.rb +0 -213
  242. data/lib/gooby_simple_xml_parser.rb +0 -50
  243. data/lib/gooby_test_helper.rb +0 -23
  244. data/lib/gooby_track.rb +0 -47
  245. data/lib/gooby_track_point.rb +0 -229
  246. data/lib/gooby_training_center_xml_parser.rb +0 -224
  247. data/lib/gooby_training_center_xml_splitter.rb +0 -116
  248. data/lib/split_code.sh +0 -29
  249. data/samples/20050305_corporate_cup_hm.html +0 -450
  250. data/samples/20050430_nashville_marathon.html +0 -1668
  251. data/samples/20060115_phoenix_marathon.html +0 -1596
  252. data/samples/20070101_davidson_11m.html +0 -432
  253. data/samples/20070505_davidson_5k.html +0 -413
  254. data/samples/been_there.txt +0 -92
  255. data/samples/hrm1.html +0 -87
  256. data/sql/gooby.ddl +0 -60
  257. data/sql/gooby_load.dml +0 -62
@@ -1,210 +0,0 @@
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 GoobyCommand < GoobyObject
12
-
13
- attr_reader :configuration, :csv_points, :csv_col_names
14
-
15
- def initialize(gooby_yaml_filename=nil)
16
- @configuration = Gooby::Configuration.init(gooby_yaml_filename)
17
- end
18
-
19
- def display_configuration
20
- #puts @configuration.to_s
21
- @configuration.print_all
22
- end
23
-
24
- def display_version
25
- s = "# #{project_name} #{project_version_number} #{project_date}. #{project_copyright}."
26
- puts s
27
- end
28
-
29
- def split_garmin_export_file(argv)
30
- if (argv == nil)
31
- puts "ERROR: no ARGV args passed."
32
- elsif (argv.size < 3)
33
- puts ""
34
- puts "Invalid program args; three args required - format, input filename, output directory"
35
- puts " the first arg, format, should be one of: garmin201, garmin205, garmin305, etc."
36
- puts " the second arg is the input filename - which is a garmin export file"
37
- puts " the third arg is the output directory where the split files are written to\n\n"
38
- puts "Please correct the program arguments and try again. \n\n"
39
- else
40
- format = argv[0].downcase
41
- filename = argv[1]
42
- out_dir = argv[2]
43
-
44
- if (format == 'garmin201')
45
- split_garmin_forerunner_logbook_xml(filename, out_dir)
46
- else
47
- split_garmin_training_center_xml(filename, out_dir)
48
- end
49
- end
50
- end
51
-
52
- def split_garmin_forerunner_logbook_xml(xml_filename, out_dir)
53
- splitter = Gooby::ForerunnerXmlSplitter.new(xml_filename, out_dir)
54
- splitter.split
55
- end
56
-
57
- def split_garmin_training_center_xml(tcx_filename, out_dir)
58
- splitter = Gooby::TrainingCenterXmlSplitter.new(tcx_filename, out_dir)
59
- splitter.split
60
- end
61
-
62
- def parse_garmin_xml_file(argv)
63
- if (argv == nil)
64
- puts "ERROR: no ARGV args passed."
65
- elsif (argv.size < 2)
66
- puts ""
67
- puts "Invalid program args; three args required - format, uom, input (xml) filename"
68
- puts " the first arg, format, should be one of: garmin201, garmin205, garmin305, etc."
69
- puts " the second arg, unit-of-measure, should be either 'english' or 'metric'."
70
- puts " the third arg, input xml filename, was produced by the Gooby 'splitter.rb' program."
71
- puts "Please correct the program arguments and try again. \n\n"
72
- else
73
- format = argv[0].downcase
74
- uom = argv[1].downcase
75
- filename = argv[2]
76
- puts Trackpoint.csv_header
77
- if (format == 'garmin201')
78
- parse_garmin_forerunner_logbook_xml(filename, uom)
79
- else
80
- parse_garmin_training_center_xml(filename, uom)
81
- end
82
- end
83
- end
84
-
85
- def parse_garmin_forerunner_logbook_xml(xml_filename, uom)
86
- handler = Gooby::ForerunnerXmlParser.new(uom)
87
- Document.parse_stream((File.new xml_filename), handler)
88
- handler.put_all_run_tkpt_csv()
89
- end
90
-
91
- def parse_garmin_training_center_xml(tcx_filename, uom)
92
- handler = Gooby::TrainingCenterXmlParser.new(uom)
93
- Document.parse_stream((File.new tcx_filename), handler)
94
- handler.put_all_run_tkpt_csv()
95
- end
96
-
97
- def read_csv_files(array_of_filenames, record_index=0)
98
- @csv_reader = Gooby::CsvReader.new(array_of_filenames)
99
- @csv_points = @csv_reader.read
100
- @csv_col_names = @csv_reader.col_names
101
- puts @csv_reader.to_s
102
- if (record_index > 0)
103
- @csv_reader.display_formatted_record(record_index)
104
- end
105
- @csv_points
106
- end
107
-
108
- def been_there(course_id, proximity=0.0070, uom='deg')
109
- unless @csv_points
110
- puts "You must first invoke method 'read_csv_files' with a list of parsed CSV filenames."
111
- return
112
- end
113
- course = configuration.get_course("#{course_id}")
114
- unless course
115
- puts "Unable to find course id '#{course_id}' in the gooby config yaml file."
116
- return
117
- end
118
- puts ''
119
- # collect the csv_points into run arrays
120
- @curr_run_id = 'x'
121
- @csv_runs = Array.new
122
- @csv_points.each { |csv_point|
123
- if (csv_point.run_id == @curr_run_id)
124
- @curr_run.add_point(csv_point)
125
- else
126
- @curr_run_id = csv_point.run_id
127
- @curr_run = Gooby::CsvRun.new(@curr_run_id)
128
- @curr_run.add_point(csv_point)
129
- @csv_runs << @curr_run
130
- end
131
- }
132
-
133
- # iterate the runs - looking for a match vs the course
134
- @csv_runs.each { |csv_run|
135
- puts "Scanning run id '#{csv_run.id}', point count= #{csv_run.points.size}" if false
136
- run_points = csv_run.points
137
- course.reset
138
- course.points.each { |course_point|
139
- closest_diff = 999
140
- closest_point = nil
141
- run_points.each { |run_point|
142
- diff = course_point.degrees_diff(run_point)
143
- if ((diff < proximity) && (diff < closest_diff))
144
- closest_diff = diff
145
- closest_point = run_point
146
- closest_point.degrees_diff = diff
147
- course.matched(course_point.number, run_point)
148
- end
149
- }
150
- }
151
- if course.matched?
152
- puts "Course '#{course.name}' matched vs run id '#{csv_run.id}'"
153
- course.display_matches
154
- else
155
- puts "course not matched" if false
156
- end
157
- }
158
- end
159
-
160
- def first_trackpoints_as_poi(date_string)
161
- # cat 2007_poi.csv | sort +4n > 2007_poi_sorted.csv
162
- home_point = Point.new('35.495469007128285', '-80.83213448524475', '752.5755445824', 'Home at South Faulkner Way Stopsign') # TODO
163
- # poi.123 35.484114 -80.820274 788.7661681152 2007-06-30 10:48:32 1.01214244648463
164
- @csv_points.each { |csv_point|
165
- proximity = home_point.proximity(csv_point, 'm')
166
- if (csv_point.lap_number == 1)
167
- if date_string
168
- if csv_point.date == date_string
169
- puts sprintf("%s %s %s %s %s %s %s", 'poi. ',
170
- character_align('.', csv_point.latitude, 3, 7),
171
- character_align('.', csv_point.longitude, 4, 7),
172
- character_align('.', csv_point.altitude, 5, 11),
173
- character_align('.', proximity.to_s, 3, 20),
174
- csv_point.date,
175
- csv_point.time,
176
- csv_point.distance)
177
- end
178
- else
179
- puts sprintf("%s %s %s %s %s %s %s", 'poi. ',
180
- character_align('.', csv_point.latitude, 3, 7),
181
- character_align('.', csv_point.longitude, 4, 7),
182
- character_align('.', csv_point.altitude, 5, 11),
183
- character_align('.', proximity.to_s, 3, 20),
184
- csv_point.date,
185
- csv_point.time,
186
- csv_point.distance)
187
- end
188
- end
189
- }
190
- end
191
-
192
- def generate_google_map(argv)
193
- if (argv == nil)
194
- puts "ERROR: no ARGV args passed."
195
- elsif (argv.size < 1)
196
- puts ""
197
- puts "Invalid program args; one required - input csv filename"
198
- puts " the first arg, csv filename, was produced by the Gooby 'parser.rb' program."
199
- puts "Please correct the program arguments and try again. \n\n"
200
- else
201
- csv_filename = argv[0]
202
- configuration = Gooby::Configuration.get_config
203
- generator = Gooby::GoogleMapGenerator.new(csv_filename)
204
- generator.generate_page(configuration)
205
- end
206
- end
207
-
208
- end
209
-
210
- end # end of module
@@ -1,117 +0,0 @@
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 Course < GoobyObject
12
-
13
- attr_accessor :name, :distance, :point_numbers, :points
14
-
15
- def initialize(yaml_csv)
16
- @name, @distance = '', 0.0
17
- @point_numbers, @points, @bad_points = Array.new, Array.new, Array.new
18
- @points_hash, @matched_points = Hash.new, Hash.new
19
- tokens = yaml_csv.split(',')
20
- @name = tokens[0] if tokens.size > 0
21
- @distance = tokens[1].to_f if tokens.size > 1
22
- if tokens.size > 2
23
- index = 0
24
- tokens.each { |tok|
25
- index = index + 1
26
- if (index > 2)
27
- poi = Configuration.get_config.get_poi(tok)
28
- if (poi)
29
- poi.number = "#{tok}"
30
- @point_numbers << "#{tok}"
31
- @points << poi
32
- @points_hash["#{tok}"] = poi
33
- else
34
- @bad_points << tok
35
- end
36
- end
37
- }
38
- end
39
- end
40
-
41
- def has_errors
42
- (@bad_points.size > 0) ? true : false
43
- end
44
-
45
- def matched(number, point)
46
- @matched_points["#{number}"] = point if point
47
- end
48
-
49
- def matched?
50
- (@matched_points.size == @point_numbers.size) ? true : false
51
- end
52
-
53
- def display_matches
54
- puts ''
55
- calculate_matches
56
- @point_numbers.each { |num|
57
- point = @points_hash["#{num}"]
58
- mpoint = @matched_points["#{num}"]
59
- puts ''
60
- puts " Course Point: #{point.to_formatted_string}" if point
61
- puts " Matched Point: #{mpoint.to_formatted_string}" if mpoint
62
- }
63
- puts ''
64
- end
65
-
66
- def reset
67
- @matched_points = Hash.new
68
- end
69
-
70
- def to_s
71
- "#{@name} #{@distance} points: #{@points.size} errors: #{has_errors}"
72
- end
73
-
74
- def dump
75
- puts "Course: #{@name}"
76
- puts "Distance: #{@distance}"
77
- points.each { |pt| puts pt } #{@points.size} errors: #{has_errors}"
78
- end
79
-
80
- private
81
-
82
- def calculate_matches
83
- # first, identify the high and low distance points and their indices.
84
- idx, low_dist, low_dist_idx, low_time, high_dist, high_dist_idx = -1, 999999.0, 0, '', -1.0, 0
85
- @point_numbers.each { |num|
86
- idx = idx + 1
87
- mpoint = @matched_points["#{num}"]
88
- if mpoint && mpoint.distance < low_dist
89
- low_dist = mpoint.distance
90
- low_dist_idx = idx
91
- low_time = mpoint.elapsed
92
- end
93
- if mpoint && mpoint.distance > high_dist
94
- high_dist = mpoint.distance
95
- high_dist_idx = idx
96
- end
97
- }
98
- low_dttm = DtTm.new("2007-06-09T#{low_time}Z")
99
-
100
- # reorder the entries in @point_numbers if necessary - 'low-to-high distance'.
101
- if (high_dist_idx < low_dist_idx)
102
- @point_numbers.reverse!
103
- end
104
-
105
- @point_numbers.each { |num|
106
- mpoint = @matched_points["#{num}"]
107
- if mpoint
108
- mpoint.course_distance = mpoint.distance - low_dist
109
- dttm = DtTm.new("2007-06-09T#{mpoint.elapsed}Z")
110
- mpoint.course_elapsed = dttm.hhmmss_diff(low_dttm)
111
- end
112
- }
113
- end
114
-
115
- end
116
-
117
- end # end of module
@@ -1,71 +0,0 @@
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 CsvPoint < Point
12
-
13
- attr_reader :rawdata, :tokens
14
- attr_reader :id, :run_id, :date, :time, :tkpt_num, :distance, :elapsed, :uom
15
- attr_reader :lap_number, :lap_distance, :lap_elapsed
16
- attr_accessor :course_distance, :course_elapsed, :degrees_diff
17
-
18
- def initialize(csv_line)
19
- @rawdata = "#{csv_line}"
20
- @tokens = @rawdata.split(csv_delim)
21
- if (@tokens.size > 14)
22
- @id = @tokens[0] # <-- consists of @run_id.@tkpt_num for uniqueness and use as a DB table primary key.
23
- @run_id = @tokens[1]
24
- @date = @tokens[2]
25
- @time = @tokens[3]
26
- @tkpt_num = @tokens[4].strip.to_i
27
- @latitude = @tokens[5].to_f
28
- @longitude = @tokens[6].to_f
29
- @altitude = @tokens[7].strip.to_f
30
- @heartbeat = @tokens[8].strip.to_f
31
- @distance = @tokens[9].strip.to_f
32
- @uom = @tokens[10].strip
33
- @elapsed = @tokens[11]
34
- @lap_number = @tokens[12].strip.to_i
35
- @lap_distance = @tokens[13].strip.to_f
36
- @lap_elapsed = @tokens[14]
37
- end
38
- end
39
-
40
- def token_count
41
- @tokens ? @tokens.size : 0
42
- end
43
-
44
- def as_trackpoint
45
- tkpt = Trackpoint.new(@tkpt_num, @latitude, @longitude, @altitude, @heartbeat, "#{date}T#{time}Z", @uom)
46
- tkpt.lap_number = @lap_number
47
- tkpt.lap_distance = @lap_distance
48
- tkpt.lap_elapsed = @lap_elapsed
49
- tkpt
50
- end
51
-
52
- def to_s
53
- return "lat: #{@latitude} lng: #{@longitude} alt: #{@altitude} note: #{@note}"
54
- end
55
-
56
- def to_formatted_string
57
- s = "lat: #{@latitude.to_s.ljust(20)}"
58
- s << " lng: #{@longitude.to_s.ljust(20)}"
59
- s << " time: #{@time}"
60
- pad = ''.ljust(70)
61
- s << "\n#{pad} course elapsed: #{@course_elapsed}"
62
- s << "\n#{pad} distance: #{@distance}"
63
- s << "\n#{pad} heartbeat: #{@heartbeat}" if (@heartbeat && (@heartbeat.to_f > 0))
64
- s << "\n#{pad} course distance: #{@course_distance}"
65
- s << "\n#{pad} altitude: #{@altitude}"
66
- s << "\n#{pad} degrees diff: #{@degrees_diff}"
67
- s
68
- end
69
- end
70
-
71
- end # end of module
@@ -1,71 +0,0 @@
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 CsvReader < GoobyObject
12
-
13
- attr_reader :files, :csv_points, :col_names
14
-
15
- def initialize(array_of_filenames=nil)
16
- @files = Array.new
17
- @csv_points = Array.new
18
- if array_of_filenames
19
- array_of_filenames.each { |filename| add_file(filename) }
20
- end
21
- end
22
-
23
- def add_file(filename)
24
- if (filename)
25
- if (File.exist?(filename))
26
- @files << filename
27
- end
28
- end
29
- end
30
-
31
- def read
32
- @files.each { |filename|
33
- lines = read_lines(filename, true)
34
- lines.each { |line|
35
- if (line.match('^#'))
36
- if (line.match('^#cols: '))
37
- col_names_header = line[7, line.size]
38
- @col_names = col_names_header.split('|')
39
- end
40
- else
41
- if (line.size > 50)
42
- @csv_points << Gooby::CsvPoint.new(line)
43
- end
44
- end
45
- }
46
- }
47
- @csv_points
48
- end
49
-
50
- def display_formatted_record(record_index=2)
51
- tokens = @csv_points[record_index].rawdata.split('|')
52
- puts "\nCsvReader.display_formatted_record hdr_cols=#{@col_names.size} data_cols=#{tokens.size}"
53
- size = 0
54
- @col_names.each { |col_name|
55
- size = size + 1
56
- if size <= tokens.size
57
- value = tokens[size - 1]
58
- puts "#{col_name.strip.ljust(20)} #{(size - 1).to_s.ljust(3)} #{value}"
59
- end
60
- }
61
- end
62
-
63
- def to_s
64
- s = "CsvReader - file count: #{files.size} total points: #{csv_points.size}"
65
- @files.each { |file| s << "\n file: #{file} "}
66
- s
67
- end
68
-
69
- end
70
-
71
- end # end of module