Sha256: 429abf66adbeaa77866fc14870c5a36f9920afddf779a0e95dbb909cfb985e00

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

BusFuelControl.class_eval do
  data_miner do
    schema Earth.database_options do
      string 'name'
      string 'bus_fuel_name'
      string 'control'
      float  'ch4_emission_factor'
      string 'ch4_emission_factor_units'
      float  'n2o_emission_factor'
      string 'n2o_emission_factor_units'
    end
    
    import "a list of bus fuel controls",
           :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEw1QW80VVJhaXRkUURQSFhHczNyVWc&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
      connection.execute %{
        UPDATE bus_fuel_controls
        SET ch4_emission_factor = ch4_emission_factor * #{conversion_factor},
            ch4_emission_factor_units = 'kilograms_per_kilometre'
        WHERE ch4_emission_factor_units = 'grams_per_mile'
      }
      
      connection.execute %{
        UPDATE bus_fuel_controls
        SET n2o_emission_factor = n2o_emission_factor * #{conversion_factor},
            n2o_emission_factor_units = 'kilograms_per_kilometre'
        WHERE n2o_emission_factor_units = 'grams_per_mile'
      }
    end
    
    # FIXME TODO verify this
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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