Skip to content

Commit

Permalink
Merge branch 'release-2.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
drewpotter committed Apr 11, 2019
2 parents abe24c2 + 9979ea1 commit 19c1d5e
Show file tree
Hide file tree
Showing 10 changed files with 56,895 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
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
5 changes: 5 additions & 0 deletions .travis.yml
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
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 2.4.2

* Update the PAME importer to use the latest monthly CSV with additional PAME Evaluation information.
* Add pame source model.

### 2.4.1

* Add a warning message to country pages that have restricted Protected Areas
Expand Down
3 changes: 2 additions & 1 deletion app/models/pame_evaluation.rb
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
3 changes: 3 additions & 0 deletions app/models/pame_source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class PameSource < ActiveRecord::Base
has_many :pame_evaluations
end
28,679 changes: 28,679 additions & 0 deletions lib/data/seeds/pame_data-2019-01-31.csv

Large diffs are not rendered by default.

28,169 changes: 28,169 additions & 0 deletions lib/data/seeds/pame_data-2019-03-29.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/data/seeds/pame_template.csv
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
35 changes: 29 additions & 6 deletions lib/modules/wdpa/pame_importer.rb
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

0 comments on commit 19c1d5e

Please sign in to comment.