Sha256: e2ecca47cbb9a19b7903d099f51e07f346bc1b14d798a9d4c2c476641218079d

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

BusFuelYearControl.class_eval do
  data_miner do
    schema Earth.database_options do
      string  'name'
      string  'bus_fuel_name'
      integer 'year'
      string  'control'
      string  'bus_fuel_control_name'
      float   'total_travel_percent'
    end
    
    process "Ensure all BusFuelControls are imported" do
      BusFuelControl.run_data_miner!
    end
    
    import "a list of bus fuel year controls",
           :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGhHQkZPZW4zbXYzZ3NkYThBWnQ2QXc&output=csv' do
      key   'name'
      store 'bus_fuel_name'
      store 'year'
      store 'control'
      store 'total_travel_percent'
    end
    
    process "Derive bus fuel control name for association with BusFuelControl" do
      if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
        update_all "bus_fuel_control_name = bus_fuel_name || ' ' || control"
      else
        update_all "bus_fuel_control_name = CONCAT(bus_fuel_name, ' ', control)"
      end
    end
    
    # FIXME TODO verify that for any year the percentages sum to 1
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
earth-0.4.4 lib/earth/bus/bus_fuel_year_control/data_miner.rb
earth-0.4.3 lib/earth/bus/bus_fuel_year_control/data_miner.rb
earth-0.4.2 lib/earth/bus/bus_fuel_year_control/data_miner.rb
earth-0.4.1 lib/earth/bus/bus_fuel_year_control/data_miner.rb