diff --git a/app/models/protected_area.rb b/app/models/protected_area.rb index dc08b096c..f906866be 100644 --- a/app/models/protected_area.rb +++ b/app/models/protected_area.rb @@ -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 } diff --git a/app/presenters/home_presenter.rb b/app/presenters/home_presenter.rb index bdfae40d7..1c271a50d 100644 --- a/app/presenters/home_presenter.rb +++ b/app/presenters/home_presenter.rb @@ -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 @@ -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: [ @@ -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: [ diff --git a/lib/modules/stats/global.rb b/lib/modules/stats/global.rb index 2c1827cfc..c97f31498 100644 --- a/lib/modules/stats/global.rb +++ b/lib/modules/stats/global.rb @@ -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 @@ -74,6 +55,5 @@ def self.percentage_land_cover def self.percentage_marine_cover CountryStatistic.global_percentage_pa_marine_cover end - end