Sha256: b272edc6b1e871be3cad9b45b4763fd3e9f59d4bfa2056098be9d1b15473bd35

Contents?: true

Size: 1.76 KB

Versions: 38

Compression:

Stored size: 1.76 KB

Contents

AircraftClass.class_eval do
  data_miner do
    schema Earth.database_options do
      string  'brighter_planet_aircraft_class_code'
      string  'name'
      float   'm1'
      float   'm2'
      float   'm3'
      float   'endpoint_fuel'
      integer 'seats'
    end
    
    import "Brighter Planet's aircraft classes", :url => 'http://static.brighterplanet.com/science/data/transport/air/brighter_planet_aircraft_classes.csv' do
      key 'brighter_planet_aircraft_class_code'
      store 'name', :field_name => 'description'
    end
    
    process "Derive some average aircraft chraracteristics from aircraft" do
      Aircraft.run_data_miner!
      aircraft = Aircraft.arel_table
      aircraft_classes = AircraftClass.arel_table
      conditional_relation = aircraft_classes[:brighter_planet_aircraft_class_code].eq(aircraft[:brighter_planet_aircraft_class_code])
      %w{ m1 m2 m3 endpoint_fuel }.each do |column|
        relation = Aircraft.weighted_average_relation(column).
                            where(conditional_relation)
        update_all "#{column} = (#{relation.to_sql})"
      end
    end
    
    process "Derive some average aircraft characteristics from flight segments" do # FIXME TODO why not derive this from aircraft?
      FlightSegment.run_data_miner!
      aircraft = Aircraft.arel_table
      aircraft_classes = AircraftClass.arel_table
      segments = FlightSegment.arel_table
      relation = FlightSegment.joins(:aircraft). # this requires associations
                               weighted_average_relation(:seats, :weighted_by => :passengers).
                               where(aircraft_classes[:brighter_planet_aircraft_class_code].eq(aircraft[:brighter_planet_aircraft_class_code]))
      update_all "seats = (#{relation.to_sql})"
    end
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
earth-0.2.6 lib/earth/air/aircraft_class/data_miner.rb
earth-0.2.5 lib/earth/air/aircraft_class/data_miner.rb
earth-0.2.4 lib/earth/air/aircraft_class/data_miner.rb
earth-ruby19-0.2.3 lib/earth/air/aircraft_class/data_miner.rb
earth-0.2.3 lib/earth/air/aircraft_class/data_miner.rb
earth-0.2.2 lib/earth/air/aircraft_class/data_miner.rb
earth-0.2.1 lib/earth/air/aircraft_class/data_miner.rb
earth-0.2.0 lib/earth/air/aircraft_class/data_miner.rb
earth-0.1.4 lib/earth/air/aircraft_class/data_miner.rb
earth-0.1.3 lib/earth/air/aircraft_class/data_miner.rb
earth-0.1.2 lib/earth/air/aircraft_class/data_miner.rb
earth-0.1.1 lib/earth/air/aircraft_class/data_miner.rb
earth-0.1.0 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.43 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.42 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.41 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.40 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.39 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.38 lib/earth/air/aircraft_class/data_miner.rb
earth-0.0.37 lib/earth/air/aircraft_class/data_miner.rb