Class: GoobyProcess

Inherits:
Object
  • Object
show all
Includes:
GoobyConfiguration, GoobyEnvironment, GoobyHelpProducer, GoobyIO
Defined in:
lib/gooby_process.rb

Overview

Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GoobyIO

#read_file_as_lines, #write_file, #write_lines

Methods included from GoobyHelpProducer

#produce_help_page

Methods included from GoobyEnvironment

#array_param, #boolean_param, #command_line_arg, #float_param, #integer_param, #string_param

Methods included from GoobyConfiguration

#read_configuration

Constructor Details

#initialize(method_name_symbol, opts = {}) ⇒ GoobyProcess

Returns a new instance of GoobyProcess.



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
48
49
50
# File 'lib/gooby_process.rb', line 18

def initialize(method_name_symbol, opts={})
  begin
    @start_time, @method_name = Time.now, method_name_symbol.to_s
    if opts
      opts.keys.each { | key | ENV[key.to_s] = opts[key].to_s }
    end   
    if @method_name != 'help'
      puts "---" 
      puts "Beginning of Gooby process: '#{method_name_symbol}'" 
    end
    self.send(method_name_symbol.to_s) # "dynamic dispatch" to the implementation method
  rescue Exception => e
    @exception = e
    puts "Exception in process #{process_info}"  
    puts "class:     #{e.class.name}"  
    puts "exception: #{e.inspect}"    
    if e.backtrace && e.backtrace.class == Array
      e.backtrace.each { | line | puts line }
    else
      puts e.backtrace
    end   
  ensure
    if @method_name != 'help'      
      end_time = Time.now     
      elapsed  = end_time - start_time
      minutes  = elapsed.to_f / 60.0
      hours    = elapsed.to_f / 3600.0
      puts "Process completed #{Time.now.to_s}." 
      puts sprintf("Elapsed seconds %6.6f = %5.6f minutes = %2.6f hours", elapsed, minutes, hours) 
      puts "---" 
    end
  end
end

Instance Attribute Details

#dispatchObject (readonly)

Returns the value of attribute dispatch.



16
17
18
# File 'lib/gooby_process.rb', line 16

def dispatch
  @dispatch
end

#exceptionObject (readonly)

Returns the value of attribute exception.



15
16
17
# File 'lib/gooby_process.rb', line 15

def exception
  @exception
end

#help_contentObject (readonly)

Returns the value of attribute help_content.



16
17
18
# File 'lib/gooby_process.rb', line 16

def help_content
  @help_content
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



15
16
17
# File 'lib/gooby_process.rb', line 15

def method_name
  @method_name
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



15
16
17
# File 'lib/gooby_process.rb', line 15

def start_time
  @start_time
end

#subsystemObject (readonly)

Returns the value of attribute subsystem.



15
16
17
# File 'lib/gooby_process.rb', line 15

def subsystem
  @subsystem
end

#system_test_commandsObject (readonly)

Returns the value of attribute system_test_commands.



16
17
18
# File 'lib/gooby_process.rb', line 16

def system_test_commands
  @system_test_commands
end

#tmp_dirObject (readonly)

Returns the value of attribute tmp_dir.



15
16
17
# File 'lib/gooby_process.rb', line 15

def tmp_dir
  @tmp_dir
end

Instance Method Details

#classnameObject



52
53
54
# File 'lib/gooby_process.rb', line 52

def classname
  self.class.name
end

#extract_activities_from_tcxObject


command: rake gooby:extract_activities_from_tcx description: Splits the potentially huge Garmin Training Center tcx file into individual

Activity xml files, and places these in the /splits directory.  Each has a filename 
based on the starting date/time of the activity.

parameters: tcx_file - The input file, created by exporting from Garmin Training Center.

            Defaults to 'data/current.tcx' in your GOOBY_HOME directory.
example:     rake gooby:extract_activities_from_tcx tcx_file=data/current.tcx


124
125
126
127
128
129
130
131
132
133
# File 'lib/gooby_process.rb', line 124

def extract_activities_from_tcx
  tcx_file = command_line_arg('tcx_file', "#{gooby_home}/data/current.tcx")
  if File.exist?(tcx_file)
    puts "processing file: #{tcx_file}"
    extractor = GoobyTcxExtractor.new
    extractor.extract(tcx_file, "#{gooby_home}/splits")
  else
    puts "file does not exist: #{tcx_file}  GOOBY_HOME is #{gooby_home}"
  end
end

#generate_google_earth_mapObject


command: rake gooby:generate_google_earth_map description: Generate a Google Earth kml file from a csv file. parameters: config_file - Your yaml configuration file in /config.

Defaults to 'config/gooby_config.yaml' in your GOOBY_HOME directory.

note 1: The configuration file entry ‘csv_file’ specifies the csv data file that

will be read and used to generate the map.

note 2: Gooby will optionally create a kmz file for you. A kmz file is essentially a

zip file, which contains your kml file(s), as well as any associated files such
as images.  Two parameters are required in your yaml config file for kmz generation:
'kmz_build' must be set to true, and 'kmz_build_command' must be the appropriate
zip-creating command for your operating system and set of installed software.
A Mac OS/X example command is: zip -r gooby_big_sur.kmz .

example: rake gooby:generate_google_earth_map config_file=config/big_sur_marathon.yaml



272
273
274
275
276
# File 'lib/gooby_process.rb', line 272

def generate_google_earth_map
  config_file = command_line_arg('config_file', "#{gooby_home}/config/gooby_config.yaml")
  generator = GoobyGoogleKmlGenerator.new
  generator.generate(config_file)
end

#generate_google_mapObject


command: rake gooby:generate_google_map description: Generate a Google Map html file from a csv file. parameters: config_file - Your yaml configuration file in /config.

Defaults to 'config/gooby_config.yaml' in your GOOBY_HOME directory.

note 1: The configuration file entry ‘csv_file’ specifies the csv data file that

will be read and used to generate the map.

example: rake gooby:generate_google_map config_file=config/big_sur_marathon.yaml



250
251
252
253
254
# File 'lib/gooby_process.rb', line 250

def generate_google_map
  config_file = command_line_arg('config_file', "#{gooby_home}/config/gooby_config.yaml")
  generator = GoobyGoogleMapGenerator.new
  generator.generate(config_file)
end

#gooby_homeObject



60
61
62
# File 'lib/gooby_process.rb', line 60

def gooby_home
  ENV['GOOBY_HOME']
end

#helpObject

Gooby = Google APIs + Ruby. Copyright 2009 by Chris Joakim. Gooby is available under GNU General Public License (GPL) license. Version 2.0.0

Directory Structure:

{GOOBY_HOME}              Your chosen directory on your computer in which to store Gooby files.
                          You must set the "GOOBY_HOME" environment variable on your computer to this
                          chosen directory name.
{GOOBY_HOME}/config       Contains configuration files in yaml format.
                          File /config/gooby_config.yaml is the "base" configuration file, and is read first.
                          This file typically remains unchanged after your intial edits to it.  Be sure to
                          set "gmap_key" to your Google Maps key, and "gmap_icon_url_base" to the URL on
                          your site where the map icon images are located.
                          You should create one "map-specific" yaml file for each map you wish to create.
                          It "inherits" all entries from the base configuration file, gooby_config.yaml.
                          So just specify the additions or overrides in your map-specific yaml files.
                          This design allows you generate your various maps, without having to frequently
                          reset the values the the base configuration file.
{GOOBY_HOME}/csv          Gooby places CSV data files in this directory.  All Gooby parsers create a
                          standard CSV format that you can use to generate either Google maps or Google Earth
                          maps with.
{GOOBY_HOME}/data         You place data files from your desktop GPS software here.
{GOOBY_HOME}/out          Gooby places generated Google Map html files and Google Earth kml files here.
{GOOBY_HOME}/out/images   Standard set of images here which are used in the generated html & kml files.
                          Add your own images here, or replace the existing ones, as necessary.
{GOOBY_HOME}/samples      Contains a set of sample files for your reference.
{GOOBY_HOME}/splits       Gooby places individual 'activity xml files' here, split-out from a large tcx file.
{GOOBY_HOME}/tmp          Temporary files.

List of Gooby commands (in order of typical usage):

rake                                    # Default task; same as 'rake gooby:help'.
rake gooby:help                         # Display Gooby usage instructions.  
rake gooby:extract_activities_from_tcx  # Extract individual Activity xml files from a Garmin tcx file
rake gooby:parse_activity_xml_to_csv    # Parse an extracted Activity xml file to a corresponding csv file.
rake gooby:parse_track_log_to_csv       # Parse a GPS Track Log file a corresponding csv file.  
rake gooby:parse_gpx_to_csv             # Parse a *.gpx file into a corresponding csv file.
rake gooby:generate_google_map          # Generate a Google Map from a csv file.
rake gooby:generate_google_earth_map    # Generate a Google Earth kml file from a csv file, with optional
                                          kmz file generation.

Gooby Command Detail:

command: rake gooby:help description: Displays help information for each Gooby command. parameters: none



110
111
112
# File 'lib/gooby_process.rb', line 110

def help
  produce_help_page(__FILE__, true)
end

#parse_activity_xml_to_csvObject


command: rake gooby:parse_activity_xml_to_csv description: Parse an extracted Activity xml ‘split’ file to a corresponding csv file. parameters: config_file - Your yaml configuration file in /config.

Defaults to 'config/gooby_config.yaml' in your GOOBY_HOME directory.

note 1: The configuration file entry ‘activity_xml_file’ specifies the xml file that

will be read and parsed into csv.

note 2: The configuration file entry ‘csv_file’ specifies the csv file that will be created. example: rake gooby:parse_activity_xml_to_csv config_file=config/big_sur_marathon.yaml



146
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_process.rb', line 146

def parse_activity_xml_to_csv
  config_file = command_line_arg('config_file', nil)
  read_configuration(config_file)    
  file     = @configuration['activity_xml_file']
  csv_file = @configuration['csv_file']    
  if File.exist?(file)
    puts "processing file: #{file}"
    parser = GoobyGarminTcxParser.new
    parser.process_file(file)
    puts "parser.error #{parser.error}"  if parser.error
    puts "parser.exception #{parser.exception}"  if parser.exception
    parser.post_process
    csv_lines = parser.trackpoints_to_csv
    # basename = File.basename(file)
    # basename.gsub!('.xml', '.csv')
    csv_filename = "#{gooby_home}/#{csv_file}"
    # csv_filename.gsub!('.xml', '.csv')
    write_lines(csv_filename, csv_lines)
    puts "file written; #{csv_filename}"
  else
    puts "file does not exist: #{file}"
  end
end

#parse_gpx_to_csvObject


command: rake gooby:parse_gpx_to_csv description: Parse a *.gpx file into a corresponding csv file. parameters: config_file - Your yaml configuration file in /config.

Defaults to 'config/gooby_config.yaml' in your GOOBY_HOME directory.

note 1: The configuration file entry ‘gpx_file’ specifies the gpx file that

will be read and parsed into csv.

note 2: The configuration file entry ‘csv_file’ specifies the csv file that will be created. example: rake gooby:parse_gpx_to_csv config_file=config/ballantyne.yaml



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gooby_process.rb', line 181

def parse_gpx_to_csv
  config_file = command_line_arg('config_file', nil)
  read_configuration(config_file)    
  file     = @configuration['gpx_file']
  csv_file = @configuration['csv_file']
  if File.exist?(file)
    puts "processing file: #{file}"
    parser = GoobyGpxParser.new
    parser.process_file(file)
    puts "parser.error #{parser.error}"  if parser.error
    puts "parser.exception #{parser.exception}"  if parser.exception
    parser.post_process
    csv_lines = parser.trackpoints_to_csv
    # basename = File.basename(file)
    # basename.gsub!('.gpx', '.csv')
    csv_filename = "#{gooby_home}/#{csv_file}"
    #csv_filename.gsub!('.gpx', '.csv')
    write_lines(csv_filename, csv_lines)
    puts "file written; #{csv_filename}"
  else
    puts "file does not exist: #{file}"
  end
end

#parse_track_log_to_csvObject


command: rake gooby:parse_track_log_to_csv description: Parse an extracted ‘GPS Tracks Log’ file from MacGpsPro into csv format. parameters: config_file - Your yaml configuration file in /config.

Defaults to 'config/gooby_config.yaml' in your GOOBY_HOME directory.

note 1: The configuration file entry ‘track_log_file’ specifies the track log file that

will be read and parsed into csv.  The filename suffix should be '.txt'.

note 2: It is strongly recommended that you manually copy the ‘GPS Tracks Log’ file

from your MacGpsPro installation to the GOOBY_HOME/data directory, and rename it to
'gps_track_logs.txt', before running this command.  Then manually edit out the lines 
not pertinent to the map you want to generate.

note 3: I use MacGpsPro to read the GPS data from my Garmin eTrex Venture device, since the

Garmin Training Center software does not support this device.

example: rake gooby:parse_track_log_to_csv config_file=config/crowders_mtn_hike.yaml



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/gooby_process.rb', line 221

def parse_track_log_to_csv
  config_file = command_line_arg('config_file', nil)
  read_configuration(config_file)    
  logs_file = @configuration['track_log_file']
  logs_file = "#{gooby_home}/data/gps_track_logs.txt" if logs_file.nil?
  csv_file  = @configuration['csv_file']
  if File.exist?(logs_file)
    puts "processing file: #{logs_file}"
    parser = GoobyTracksLogParser.new
    parser.parse(logs_file)
    csv_lines = parser.trackpoints_to_csv  
    csv_filename = "#{gooby_home}/#{csv_file}"
    write_lines(csv_filename, csv_lines)
    puts "file written; #{csv_filename}"
  else
    puts "file does not exist: #{logs_file}"
  end
end

#process_infoObject



56
57
58
# File 'lib/gooby_process.rb', line 56

def process_info
  "'#{classname}.#{method_name.to_s}'"
end