Skip to content

Commit

Permalink
feat: make Not Applicable category as a standalone category
Browse files Browse the repository at this point in the history
  • Loading branch information
yuelongh committed Dec 20, 2023
1 parent 5109f0c commit 9bdc0ba
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions app/presenters/designations_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ def initialize(geo_entity)
@geo_entity = geo_entity
end

JURISDICTIONS = %w(National Regional International).freeze
JURISDICTIONS = ['National', 'Regional', 'International', 'Not Applicable'].freeze
JURISDICTIONS_TITLE = {
'National' => 'National',
'Regional' => 'Regional',
'International' => 'International',
'Not Applicable' => 'Other'
}.freeze

def designations(exclude_oecms: false)
JURISDICTIONS.map do |j|
Expand All @@ -22,39 +28,40 @@ def designations(exclude_oecms: false)

private

def geo_entity
@geo_entity
end
attr_reader :geo_entity

def get_designations
geo_entity.designations.group_by { |design|
design.jurisdiction.name rescue "Not Reported"
}
geo_entity.designations.group_by do |design|
design.jurisdiction.name
rescue StandardError
'Not Reported'
end
end

def get_jurisdiction(jurisdiction)
Jurisdiction.find_by_name(jurisdiction)
end

def designation_title(jurisdiction)
"#{jurisdiction} designations"
jurisdiction_title = JURISDICTIONS_TITLE[jurisdiction]
jurisdiction_title ? "#{jurisdiction_title} designations": 'Designation Title Not Found'
end

def all_pas(exclude_oecms)
@all_pas ||= geo_entity.protected_areas_per_jurisdiction(exclude_oecms: exclude_oecms)
end

def total_number_of_designations(exclude_oecms)
all_pas(exclude_oecms).reduce(0) { |count, j| count + j["count"] }
all_pas(exclude_oecms).reduce(0) { |count, j| count + j['count'] }
end

def percent_of_total(jurisdictions, exclude_oecms: false)
total = designation_total(jurisdictions)
(( total / total_number_of_designations(exclude_oecms).to_f ) * 100).round(2)
((total / total_number_of_designations(exclude_oecms).to_f) * 100).round(2)
end

def designation_total(jurisdictions)
jurisdictions.reduce(0) { |count, j| count + j["count"].to_i }
jurisdictions.reduce(0) { |count, j| count + j['count'].to_i }
end

def jurisdiction_counts(jurisdiction, exclude_oecms: false)
Expand All @@ -65,10 +72,6 @@ def jurisdiction_counts(jurisdiction, exclude_oecms: false)
end

def get_jurisdictions(jurisdiction)
# 'Not Applicable' jurisdictions are to be included with
# 'National' in the country and region show pages.
# https://unep-wcmc.codebasehq.com/projects/protected-planet-support-and-maintenance/tickets/241
jurisdictions = jurisdiction == 'National' ? ['National', 'Not Applicable'] : jurisdiction
Jurisdiction.where(name: jurisdictions)
Jurisdiction.where(name: jurisdiction)
end
end

0 comments on commit 9bdc0ba

Please sign in to comment.