Skip to content

Commit

Permalink
moved methods in protected area, and tentative methods for calculatin…
Browse files Browse the repository at this point in the history
…g oecm coverages
  • Loading branch information
stanleypliu committed Aug 5, 2020
1 parent dcde1da commit f9e0004
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
12 changes: 12 additions & 0 deletions app/models/protected_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ def overlap(pa)
overlap
end

def self.global_terrestrial_oecm_coverage
land_oecms = ProtectedArea.where(is_oecm: true, marine: false).pluck(:reported_area)
total_oecm_area = land_oecms.inject(0) { |sum, area| sum + area.to_i }
((total_oecm_area.to_f / CountryStatistic.global_land_area.to_f) * 100).round(2)
end

def self.global_marine_oecm_coverage
marine_oecms = ProtectedArea.where(is_oecm: true, marine: true).pluck(:reported_marine_area)
total_oecm_area = marine_oecms.inject(0) { |sum, area| sum + area.to_i }
((total_oecm_area.to_f / CountryStatistic.global_marine_area.to_f) * 100).round(2)
end

def self.global_marine_coverage
reported_areas = marine_areas.pluck(:reported_marine_area)
reported_areas.inject(0){ |sum, area| sum + area.to_i }
Expand Down
24 changes: 16 additions & 8 deletions app/presenters/home_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@ def initialize
end

def terrestrial_pas
@terrestrial_pas ||= number_with_delimiter(Stats::Global.terrestrial_pa_count)
@terrestrial_pas ||= number_with_delimiter(ProtectedArea.where(marine: false).count)
end

def marine_pas
@marine_pas ||= number_with_delimiter(Stats::Global.marine_pa_count)
@marine_pas ||= number_with_delimiter(ProtectedArea.where(marine: true).count)
end

def terrestrial_oecms
@terrestrial_oecms = number_with_delimiter(Stats::Global.terrestrial_oecm_count)
number_with_delimiter(ProtectedArea.where(marine: false, is_oecm: true).count)
end

def marine_oecms
@marine_oecms = number_with_delimiter(Stats::Global.marine_oecm_count)
number_with_delimiter(ProtectedArea.where(marine: true, is_oecm: true).count)
end

def terrestrial_cover
@terrestrial_cover = CountryStatistic.global_percentage_pa_land_cover
CountryStatistic.global_percentage_pa_land_cover
end

def marine_cover
@marine_cover = CountryStatistic.global_percentage_pa_marine_cover
CountryStatistic.global_percentage_pa_marine_cover
end

def oecm_pa_land_cover
ProtectedArea.global_terrestrial_oecm_coverage
end

def oecm_pa_marine_cover
ProtectedArea.global_marine_oecm_coverage
end

def fact_card_stats
Expand Down Expand Up @@ -53,7 +61,7 @@ def fact_card_stats
]
},
{
percentage: 00, #total percentage coverage of terrestrial pas and OECMs
percentage: oecm_pa_land_cover,
theme: I18n.t('home.facts')[2][:theme],
title: I18n.t('home.facts')[2][:title],
totals: [
Expand All @@ -68,7 +76,7 @@ def fact_card_stats
]
},
{
percentage: 00, #total percentage coverage of marine pas and OECMs
percentage: oecm_pa_marine_cover,
theme: I18n.t('home.facts')[3][:theme],
title: I18n.t('home.facts')[3][:title],
totals: [
Expand Down
20 changes: 0 additions & 20 deletions lib/modules/stats/global.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
class Stats::Global
IUCN_CATEGORIES = "'Ia', 'Ib', 'II', 'II', 'IV', 'V', 'VI'"

def self.pa_count
ProtectedArea.count
end

def self.terrestrial_pa_count
ProtectedArea.where(marine: false).count
end

def self.marine_pa_count
ProtectedArea.where(marine: true).count
end

def self.terrestrial_oecm_count
ProtectedArea.where(marine: false, is_oecm: true).count
end

def self.marine_oecm_count
ProtectedArea.where(marine: true, is_oecm: true).count
end



Expand Down Expand Up @@ -74,6 +55,5 @@ def self.percentage_land_cover
def self.percentage_marine_cover
CountryStatistic.global_percentage_pa_marine_cover
end


end

0 comments on commit f9e0004

Please sign in to comment.