Sha256: 55bf9010ffd5bad555a43df8ac1d7527da724c530cee0f0ec82c67de4c283a30

Contents?: true

Size: 1.77 KB

Versions: 55

Compression:

Stored size: 1.77 KB

Contents

AutomobileMakeYear.class_eval do
  data_miner do
    process "Start from scratch" do
      connection.drop_table table_name
    end
    
    schema Earth.database_options do
      string   'name'
      string   'make_name'
      integer  'year'
      float    'fuel_efficiency'
      string   'fuel_efficiency_units'
      integer  'volume'
    end

    process "Derive manufacturer names and years from automobile make fleet years" do
      AutomobileMakeFleetYear.run_data_miner!
      connection.execute %{
        INSERT IGNORE INTO automobile_make_years(name, make_name, year)
        SELECT
          automobile_make_fleet_years.make_year_name,
          automobile_make_fleet_years.make_name,
          automobile_make_fleet_years.year
        FROM automobile_make_fleet_years
      }
    end
    
    process "Derive annual corporate average fuel economy across all vehicles from automobile make fleet years" do
      AutomobileMakeFleetYear.run_data_miner!
      make_fleet_years = AutomobileMakeFleetYear.arel_table
      make_years = AutomobileMakeYear.arel_table
      conditional_relation = make_years[:name].eq(make_fleet_years[:make_year_name])
      relation = AutomobileMakeFleetYear.weighted_average_relation(:fuel_efficiency, :weighted_by => :volume).where(conditional_relation)
      update_all "fuel_efficiency = (#{relation.to_sql})"
      update_all "fuel_efficiency_units = 'kilometres_per_litre'"
    end
    
    process "Derive sales volume across all vehicles from automobile make fleet years" do
      connection.execute %{
        UPDATE automobile_make_years SET automobile_make_years.volume = (SELECT SUM(automobile_make_fleet_years.volume) FROM automobile_make_fleet_years WHERE automobile_make_fleet_years.make_year_name = automobile_make_years.name)
      }
    end
  end
end

Version data entries

55 entries across 55 versions & 2 rubygems

Version Path
earth-0.3.9 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.8 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.7 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.6 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.5 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.4 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.3 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.2 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.1 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.3.0 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.14 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.13 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.12 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.11 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.9 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.8 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.7 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.6 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.5 lib/earth/automobile/automobile_make_year/data_miner.rb
earth-0.2.4 lib/earth/automobile/automobile_make_year/data_miner.rb