-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
56,895 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[submodule "db"] | ||
path = db | ||
path = db | ||
url = https://github.com/unepwcmc/protectedplanet-db.git | ||
branch = master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
language: ruby | ||
# Manually handle git submodules | ||
git: | ||
submodules: false | ||
before_install: | ||
- sed -i 's/[email protected]:/https:\/\/github.com\//' .gitmodules | ||
- git submodule update --init --recursive | ||
- sudo apt-get purge libgdal1 | ||
- sudo apt-add-repository --remove ppa:ubuntugis/ppa -y | ||
- sudo apt-get update | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class PameEvaluation < ActiveRecord::Base | ||
belongs_to :protected_area | ||
belongs_to :pame_source | ||
|
||
validates :methodology, :year, :protected_area, presence: true | ||
validates :methodology, :year, :protected_area, :metadata_id, :url, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class PameSource < ActiveRecord::Base | ||
has_many :pame_evaluations | ||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation_id,wdpa_id,country,methodology,year,url,metadata_id,name,designation,source_data_title,source_resp_party,source_year,source_language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,56 @@ | ||
require 'csv' | ||
|
||
module Wdpa::PameImporter | ||
PAME_EVALUATIONS = "#{Rails.root}/lib/data/seeds/pame_evaluations.csv".freeze | ||
PAME_EVALUATIONS = "#{Rails.root}/lib/data/seeds/pame_data-2019-03-29.csv".freeze | ||
|
||
def self.import | ||
puts "Importing PAME evaluations..." | ||
missing_pas = [] | ||
|
||
CSV.foreach(PAME_EVALUATIONS, headers: true) do |row| | ||
wdpa_id = row[0].to_i | ||
methodology = row[2] | ||
year = row[3].to_i | ||
wdpa_id = row[1].to_i | ||
methodology = row[3] | ||
year = row[4].to_i | ||
protected_area = ProtectedArea.find_by_wdpa_id(wdpa_id) | ||
metadata_id = row[6].to_i | ||
url = row[5] | ||
pame_source = PameSource.where({ | ||
data_title: row[9], | ||
resp_party: row[10], | ||
year: row[11].to_i, | ||
language: row[12] | ||
}).first_or_create do |ps| | ||
# if the record doesn't exist, create it... | ||
ps.data_title = row[9] | ||
ps.resp_party = row[10] | ||
ps.year = row[11].to_i | ||
ps.language = row[12] | ||
end | ||
|
||
if protected_area.nil? | ||
puts "Could not find Protected Area with wdpa #{wdpa_id}" if Rails.env != 'test' | ||
missing_pas << wdpa_id | ||
else | ||
PameEvaluation.where({ | ||
protected_area: protected_area, | ||
methodology: methodology, | ||
year: year | ||
year: year, | ||
metadata_id: metadata_id, | ||
url: url, | ||
pame_source: pame_source | ||
}).first_or_create do |pe| | ||
# If the record doesn't exist, create it... | ||
pe.protected_area = protected_area | ||
pe.methodology = methodology | ||
pe.year = year | ||
pe.metadata_id = metadata_id | ||
pe.url = url | ||
pe.pame_source = pame_source | ||
end | ||
end | ||
end | ||
|
||
puts "Import finished!" | ||
puts "Missing Protected Areas: #{missing_pas.count}" | ||
puts missing_pas.join(",") | ||
end | ||
end |