Sha256: 1d5c22635c04cd5533ad50cdba9c7a18a77a00845553a14ff93e792a527766c4

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

AutomobileMakeModelYear.class_eval do
  data_miner do
    process "Start from scratch" do
      delete_all
    end
    
    process "Ensure AutomobileMakeModelYearVariant is populated" do
      AutomobileMakeModelYearVariant.run_data_miner!
    end
    
    process "Derive model year names from automobile make model year variants" do
      ::Earth::Utils.insert_ignore(
        :src => AutomobileMakeModelYearVariant,
        :dest => AutomobileMakeModelYear,
        :cols => {
          :make_model_year_name => :name,
          :make_name => :make_name,
          :name => :model_name,
          :make_model_name => :make_model_name,
          :year => :year,
          :make_year_name => :make_year_name
        }
        # :where => 'LENGTH(src.make_name) > 0 AND LENGTH(src.make_model_name) > 0'
      )
    end
    
    # FIXME TODO make this a method on AutomobileMakeModelYear?
    # TODO: weight by volume somehow
    # note that we used to derive averages from make years, but here we get it from variants
    # even without volume-weighting, the values are much better.
    # for example, 20km/l for a toyota prius 2006 vs. 13km/l if you use make years
    process "Calculate city and highway fuel efficiency from automobile make model year variants" do
      model_years = AutomobileMakeModelYear.arel_table
      variants = AutomobileMakeModelYearVariant.arel_table
      conditional_relation = model_years[:name].eq(variants[:make_model_year_name])
      %w{ city highway }.each do |i|
        null_check = variants[:"fuel_efficiency_#{i}"].not_eq(nil)
        # sabshere 12/6/10 careful, don't use AutomobileMakeModelYearVariant.where here or you will be forced into projecting *
        relation = variants.project(variants[:"fuel_efficiency_#{i}"].average).where(conditional_relation).where(null_check)
        update_all "fuel_efficiency_#{i} = (#{relation.to_sql})"
        update_all "fuel_efficiency_#{i}_units" => 'kilometres_per_litre'
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
earth-0.7.0 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.6 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.5 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.4 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.3 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.2 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.1 lib/earth/automobile/automobile_make_model_year/data_miner.rb
earth-0.6.0 lib/earth/automobile/automobile_make_model_year/data_miner.rb