Sha256: e861edfa1936cbbb9633b2882bd60b64d1f10abb55499c59d8a01fbbcf05e56b

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

BusFuelControl.class_eval do
  data_miner do
    import "a list of bus fuel controls",
           :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEw1QW80VVJhaXRkUURQSFhHczNyVWc&gid=0&output=csv' do
      key   'name'
      store 'bus_fuel_name'
      store 'control'
      store 'ch4_emission_factor', :units_field_name => 'ch4_emission_factor_units'
      store 'n2o_emission_factor', :units_field_name => 'n2o_emission_factor_units'
    end
    
    process "Convert emission factors to metric units" do
      conversion_factor = (1 / 1.609344) * (1.0 / 1_000.0 ) # Google: 1 mile / 1.609344 km * 1 kg / 1000 g
      
      where(:ch4_emission_factor_units => 'grams_per_mile').update_all(%{
        ch4_emission_factor = 1.0 * ch4_emission_factor * #{conversion_factor},
        ch4_emission_factor_units = 'kilograms_per_kilometre'
      })
      where(:n2o_emission_factor_units => 'grams_per_mile').update_all(%{
        n2o_emission_factor = 1.0 * n2o_emission_factor * #{conversion_factor},
        n2o_emission_factor_units = 'kilograms_per_kilometre'
      })
    end
    
    # FIXME TODO verify this
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
earth-1.0.0 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.7 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.6 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.5 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.4 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.3 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.2 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.1 lib/earth/bus/bus_fuel_control/data_miner.rb
earth-0.11.0 lib/earth/bus/bus_fuel_control/data_miner.rb