lib/earth/rail/rail_company/data_miner.rb in earth-0.11.0 vs lib/earth/rail/rail_company/data_miner.rb in earth-0.11.1

- old
+ new

@@ -27,11 +27,11 @@ NationalTransitDatabaseMode.run_data_miner! end process "Derive US transit rail company data from the National Transit Database" do NationalTransitDatabaseCompany.rail_companies.each do |ntd_company| - company = RailCompany.find_or_create_by_name(ntd_company.name) + company = find_or_create_by_name(ntd_company.name) company.country_iso_3166_code = 'US' company.duns_number = ntd_company.duns_number company.passengers = ntd_company.rail_passengers company.passenger_distance = ntd_company.rail_passenger_distance company.passenger_distance_units = ntd_company.rail_passenger_distance_units @@ -53,34 +53,35 @@ company.save! end end process "Calculate average trip distance" do - RailCompany.find_each do |company| + find_each do |company| if company.passenger_distance.present? and company.passengers.present? and company.passengers > 0 company.trip_distance = company.passenger_distance / company.passengers company.trip_distance_units = company.passenger_distance_units company.save! end end end process "Calculate average trip speed" do - RailCompany.find_each do |company| + find_each do |company| if company.train_distance.present? and company.train_time.present? and company.train_time > 0 company.speed = company.train_distance / company.train_time company.speed_units = "#{company.train_distance_units}_per_#{company.train_time_units.singularize}" company.save! end end end - process "Ensure RailFuel is populated" do + process "Ensure RailFuel and EgridSubregion are populated" do RailFuel.run_data_miner! + EgridSubregion.run_data_miner! end process "Calculate co2 emission factor for US rail companies" do - RailCompany.where(:country_iso_3166_code => 'US').find_each do |company| + where(:country_iso_3166_code => 'US').find_each do |company| company.co2_emission_factor = 0 if company.diesel_intensity.present? company.co2_emission_factor += company.diesel_intensity * RailFuel.find_by_name("diesel").co2_emission_factor end