Sha256: 764392024d9e4cf90339b6e882eb9cf40f85be69ecc353492e9398cee7c04c26

Contents?: true

Size: 1.55 KB

Versions: 45

Compression:

Stored size: 1.55 KB

Contents

AutomobileModel.class_eval do
  data_miner do
    process "Start from scratch" do
      connection.drop_table table_name
    end
    
    schema Earth.database_options do
      string  'name' # make + model
      string  'make_name'
      float   'fuel_efficiency_city'
      string  'fuel_efficiency_city_units'
      float   'fuel_efficiency_highway'
      string  'fuel_efficiency_highway_units'
    end

    process "Derive model names from automobile variants" do
      AutomobileVariant.run_data_miner!
      connection.execute %{
        INSERT IGNORE INTO automobile_models(name, make_name)
        SELECT automobile_variants.model_name, automobile_variants.make_name FROM automobile_variants WHERE LENGTH(automobile_variants.model_name) > 0 AND LENGTH(automobile_variants.make_name) > 0
      }
    end
    
    # TODO not weighted until we get weightings on auto variants
    process "Derive average fuel economy from automobile variants" do
      AutomobileVariant.run_data_miner!
      automobile_models = AutomobileModel.arel_table
      automobile_variants = AutomobileVariant.arel_table
      conditional_relation = automobile_models[:name].eq(automobile_variants[:model_name])
      %w{ city highway }.each do |i|
        relation = AutomobileVariant.where(conditional_relation).where("`automobile_variants`.`fuel_efficiency_#{i}` IS NOT NULL").project("AVG(`automobile_variants`.`fuel_efficiency_#{i}`)")
        update_all "fuel_efficiency_#{i} = (#{relation.to_sql})"
        update_all "fuel_efficiency_#{i}_units = 'kilometres_per_litre'"
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
earth-0.2.14 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.13 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.12 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.11 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.9 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.8 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.7 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.6 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.5 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.4 lib/earth/automobile/automobile_model/data_miner.rb
earth-ruby19-0.2.3 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.3 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.2 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.1 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.2.0 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.1.4 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.1.3 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.1.2 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.1.1 lib/earth/automobile/automobile_model/data_miner.rb
earth-0.1.0 lib/earth/automobile/automobile_model/data_miner.rb