Module: PlantWatchdog

Defined in:
lib/plantwatchdog/db.rb,
lib/plantwatchdog/data.rb,
lib/plantwatchdog/main.rb,
lib/plantwatchdog/model.rb,
lib/plantwatchdog/sinatra.rb,
lib/plantwatchdog/aggregation.rb,
lib/plantwatchdog/aggregation_methods.rb

Defined Under Namespace

Modules: ActiveRecordConnections, Aggregation, Datadetection, Model, Monthhelper, UI, Version Classes: ConnectionError, DayOfYearConverter

Class Method Summary collapse

Class Method Details

.parse_command_line(args) ⇒ Object

Parses the command line arguments



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/plantwatchdog/main.rb', line 32

def self.parse_command_line args
  options = OpenStruct.new
  options.config_file = File.join(File.dirname(__FILE__),'..', '..', 'config', 'app_config.yaml')
  options.aggregate = false
  args.options do |opt|
    opt.on("Usage:")
    opt.on("plantwatchdog [options]")
    opt.on("Options:")
    opt.on("--debug", "-d","Turns on debug messages") { $DEBUG=true }
    opt.on("-v", "--version","Displays the version") { $stdout.puts("v#{Version::STRING}");exit 0 }
    opt.on("--config_file FILE", "-c FILE", "The config file") { |file| options.config_file = file }
    opt.on("--aggregate", "-a", "Run daily data aggregation") { options.aggregate = true }
    opt.on("--create_solar", nil, "Create database with sample data from a solar generator") { options.createsolar = true }
    opt.on("--help", "-h", "-?", "This text") { $stdout.puts opt; exit 0 }
    opt.parse!
  end
  options
end

.startObject

Starts App



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/plantwatchdog/main.rb', line 51

def self.start
  logger=Patir.setup_logger
  options=parse_command_line(ARGV)
  if File.exists?(options.config_file)
    config=YAML.load(File.read(options.config_file))
    config[:logger]=logger
  else
    logger.fatal("Cannot find #{options.config_file}")
    exit 1
  end
  extend PlantWatchdog::ActiveRecordConnections
  self.connect_to_active_record(config[:database_configuration],logger)
  if options.createsolar then
    $:.unshift File.join(File.dirname(__FILE__),"..","..")
    require 'sample/solar/create_solar'
    PlantWatchdog::CreateSolar.create
  elsif options.aggregate then
    require 'plantwatchdog/aggregation'
    Aggregation::Runner.new.run
  else
    PlantWatchdog::UI::SinatraApp.run!
  end
end