Earth is a collection of data models that represent various things found here on Earth, such as countries, automobiles, aircraft, zip codes, and pet breeds.
By default the data that these models represent is pulled from Brighter Planet's open reference data site using the taps gem. The data can also be imported directly from preconfigured authoritative sources.
require 'earth' require 'earth/automobile/automobile_fuel' . ft = .first # ...
Earth.init prepares the environment to load and download data for each data model. You can load all data models at once with
Earth.init :all. There are several other options to
init that configure data mining sources and database connections. See the rdocs for more details on the Earth module.
Data model categories
||Aircraft, Airline, Airport ...|
||AutomobileFuel, AutomobileMake, AutomobileModel ...|
||BusClass, BusFuel ...|
||ComputationCarrier, ComputationCarrierInstanceClass ...|
||DietClass, FoodGroup ...|
||Fuel, FuelPrice, GreenhouseGas ...|
||LodgingClass, CommercialBuildingEnergyConsumptionSurveyResponse ...|
||Industry, CbecsEnergyIntensity ...|
||CensusDivision, Country, ZipCode ...|
||Breed, Gender, Species ...|
||RailClass, RailFuel, RailCompany ...|
||Urbanity, ResidenceClass, AirConditionerUse|
||Carrier, ShipmentMode ...|
You can store Earth data in any relational database. On your very first run, you will need to create the tables for data each model. You can either use the Rails standard rake tasks (see below) or with a call to
Pulling data from data.brighterplanet.com
By default, Earth will pull data from data.brighterplanet.com, which continuously (and transparently) refreshes its data from authoritative sources. Simply call
#run_data_miner! on whichever data model class you need. If there are any Earth classes that the chosen class depends on, they will be downloaded as well automatically:
require 'earth' require 'earth/locality/zip_code' . .run_data_miner!
Pulling data from the original sources
If you'd like to bypass the data.brighterplanet.com proxy and pull data directly from authoritative sources (*e.g.,* automobile data from EPA), simply specify the :mine_original_sources option to
require 'earth' . :mine_original_sources => true require 'earth/automobile' .run_data_miner!
Earth provides handy rails tasks for creating, migrating, and data mining models whether you're using it from a Rails app or a standalone Ruby app.
In your Rakefile, add:
require 'earth/tasks' ::.
If you're using Earth outside of Rails, all of the default
rake db:* tasks will now be available. Within rails, certain tasks are augmented to
help manage your Earth models using data_miner and active_record_inline_schema in addition to standard migrations.
Of note are the following tasks:
.create_table!on each Earth resource model.
.run_data_miner!on each Earth resource model.
Brighter Planet vigorously encourages collaborative improvement.
- Fork the earth repository on GitHub.
- Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
- Improve the code until your new test passes and commit your changes.
- Push your changes to your GitHub fork.
- Submit a pull request to brighterplanet.
- Receive a pull request.
- Pull changes from forked repository.
- Ensure tests pass.
- Review changes for scientific accuracy.
- Merge changes to master repository and publish.
- Direct production environment to use new library version.