Class: GoobyTracksLogParser
- Inherits:
-
GoobyBaseObject
- Object
- GoobyBaseObject
- GoobyTracksLogParser
- Defined in:
- lib/gooby_track_log_parser.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
-
#logs_file ⇒ Object
readonly
Returns the value of attribute logs_file.
-
#trackpoints ⇒ Object
readonly
Returns the value of attribute trackpoints.
Instance Method Summary collapse
- #parse(logs_file) ⇒ Object
- #parse_trackpoints ⇒ Object
- #post_process_trackpoints ⇒ Object
- #reformatDate(mmddccyy) ⇒ Object
-
#reformatDateTime(mmddccyy, time) ⇒ Object
Return a String value in this format: 2007-03-03T15:58:57Z.
- #trackpoints_to_csv ⇒ Object
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
Methods included from GoobyEnvironment
#array_param, #boolean_param, #command_line_arg, #float_param, #integer_param, #string_param
Instance Attribute Details
#logs_file ⇒ Object (readonly)
Returns the value of attribute logs_file.
10 11 12 |
# File 'lib/gooby_track_log_parser.rb', line 10 def logs_file @logs_file end |
#trackpoints ⇒ Object (readonly)
Returns the value of attribute trackpoints.
10 11 12 |
# File 'lib/gooby_track_log_parser.rb', line 10 def trackpoints @trackpoints end |
Instance Method Details
#parse(logs_file) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/gooby_track_log_parser.rb', line 12 def parse(logs_file) @logs_file, @trackpoints = logs_file, [] @log_lines = IO.readlines(@logs_file, "\r") # funky line ends on this file; not \n puts "#{@log_lines.size} lines read from file #{@logs_file}" parse_trackpoints post_process_trackpoints # @current_trackpoint = GoobyTrackpoint.new end |
#parse_trackpoints ⇒ Object
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 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gooby_track_log_parser.rb', line 21 def parse_trackpoints # The input file looks like the following: # Format: DDD M/D/Y H:M:S -5.00 hrs Datum[116]: WGS 84 # ID Date Time Latitude Longitude Altitude # L ACTIVE LOG # T 11/16/2008 08:43:06.000 35.21357 -81.29359 262.6 # T 11/16/2008 08:44:13.000 35.21363 -81.29353 265.0 # T 11/16/2008 08:44:16.000 35.21366 -81.29349 262.6 sequence = 0 @log_lines.each { | line | tokens = line.split if (tokens.size > 5) && (tokens[0] == 'T') sequence = sequence + 1 mmddccyy = tokens[1].strip time = tokens[2].strip latitude = tokens[3].strip longitude = tokens[4].strip altitude = tokens[5].strip tkpt = GoobyTrackpoint.new tkpt.set('ActivityId', '') tkpt.set('LapStartTime', '') tkpt.set('LapSeq', '1') tkpt.set('Seq', sequence) tkpt.set('Time', reformatDateTime(mmddccyy, time)) tkpt.set('ElapsedTime', '') tkpt.set('LatitudeDegrees', latitude) tkpt.set('LongitudeDegrees', longitude) tkpt.set('AltitudeMeters', altitude.to_f / METERS_PER_FOOT) tkpt.set('Distance', '') tkpt.set('Pace', '') tkpt.set('MPH', '') @trackpoints << tkpt end } end |
#post_process_trackpoints ⇒ Object
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 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/gooby_track_log_parser.rb', line 70 def post_process_trackpoints # Trackpoint,"","","","",2008-11-16T08:43:06Z,"",35.21357,-81.29359,262.6,0.0,"","" # 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]) cumulative_distance, first_tkpt_dttm, prev_tkpt = 0.0, nil, nil if @trackpoints.size > 0 activity_id = @trackpoints[0].time else return end @trackpoints.each { | tkpt | tkpt.set('ActivityId', activity_id) tkpt.set('LapStartTime', activity_id) 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 |
#reformatDate(mmddccyy) ⇒ Object
59 60 61 62 |
# File 'lib/gooby_track_log_parser.rb', line 59 def reformatDate(mmddccyy) date_tokens = mmddccyy.split('/') "#{date_tokens[2]}-#{date_tokens[0]}-#{date_tokens[1]}" end |
#reformatDateTime(mmddccyy, time) ⇒ Object
Return a String value in this format: 2007-03-03T15:58:57Z
65 66 67 68 |
# File 'lib/gooby_track_log_parser.rb', line 65 def reformatDateTime(mmddccyy, time) time_tokens = time.split('.') "#{reformatDate(mmddccyy)}T#{time_tokens[0]}Z" end |
#trackpoints_to_csv ⇒ Object
108 109 110 111 112 |
# File 'lib/gooby_track_log_parser.rb', line 108 def trackpoints_to_csv lines = [] @trackpoints.each { | trackpoint | lines << trackpoint.to_csv } lines end |