Skip to content

Commit

Permalink
Merge pull request #490 from Vizzuality/develop
Browse files Browse the repository at this point in the history
Prod release
  • Loading branch information
martintomas authored Feb 12, 2024
2 parents 6bee443 + 7359363 commit 507002f
Show file tree
Hide file tree
Showing 53 changed files with 449 additions and 321 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ GEM
net-protocol
net-ssh (7.0.1)
nio4r (2.7.0)
nokogiri (1.16.0)
nokogiri (1.16.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
optimist (3.0.1)
Expand Down
8 changes: 6 additions & 2 deletions app/admin/ascor/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

menu label: 'Countries', parent: 'ASCOR', priority: 1

permit_params :name, :iso, :region, :wb_lending_group, :fiscal_monitor_category, :type_of_party
permit_params :name, :iso, :region, :wb_lending_group, :fiscal_monitor_category, :type_of_party, :visibility_status

filter :iso_contains, label: 'ISO'
filter :name_contains, label: 'Name'
Expand All @@ -18,6 +18,7 @@
column :name
column 'Country ISO code', :iso
column :region
tag_column :visibility_status

actions
end
Expand All @@ -31,6 +32,7 @@
row 'World Bank lending group', &:wb_lending_group
row 'International Monetary Fund fiscal monitor category', &:fiscal_monitor_category
row 'Type of Party to the United Nations Framework Convention on Climate Change', &:type_of_party
row :visibility_status
end

active_admin_comments
Expand All @@ -42,12 +44,13 @@
f.inputs do
f.input :name
f.input :iso, label: 'Country ISO code'
f.input :region, as: :select, collection: ASCOR::Country::REGIONS
f.input :region
f.input :wb_lending_group, as: :select, collection: ASCOR::Country::LENDING_GROUPS, label: 'World Bank lending group'
f.input :fiscal_monitor_category, as: :select, collection: ASCOR::Country::MONITOR_CATEGORIES,
label: 'International Monetary Fund fiscal monitor category'
f.input :type_of_party, as: :select, collection: ASCOR::Country::TYPE_OF_PARTY,
label: 'Type of Party to the United Nations Framework Convention on Climate Change'
f.input :visibility_status, as: :select, collection: ASCOR::Country::VISIBILITY
end

f.actions
Expand All @@ -61,5 +64,6 @@
column 'World Bank lending group', humanize_name: false, &:wb_lending_group
column 'International Monetary Fund fiscal monitor category', humanize_name: false, &:fiscal_monitor_category
column 'Type of Party to the United Nations Framework Convention on Climate Change', humanize_name: false, &:type_of_party
column :visibility_status
end
end
2 changes: 2 additions & 0 deletions app/admin/companies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@
row :publication_date
row :assessment_date
row :cp_alignment_2025
row :cp_alignment_2027
row :cp_alignment_2035
row :cp_alignment_2050
if a.region.present?
row :region
row :cp_regional_alignment_2025
row :cp_regional_alignment_2027
row :cp_regional_alignment_2035
row :cp_regional_alignment_2050
end
Expand Down
8 changes: 6 additions & 2 deletions app/admin/cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
decorate_with CP::AssessmentDecorator

permit_params :sector_id, :assessment_date, :publication_date, :cp_assessmentable_id, :last_reported_year,
:assumptions, :cp_alignment_2025, :cp_alignment_2035, :cp_alignment_2050,
:region, :cp_regional_alignment_2025, :cp_regional_alignment_2035,
:assumptions, :cp_alignment_2025, :cp_alignment_2027, :cp_alignment_2035, :cp_alignment_2050,
:region, :cp_regional_alignment_2025, :cp_regional_alignment_2027, :cp_regional_alignment_2035,
:cp_regional_alignment_2050, :years_with_targets_string, :emissions,
cp_matrices_attributes: [:id, :portfolio, :cp_alignment_2025, :cp_alignment_2035, :cp_alignment_2050, :_destroy]

Expand Down Expand Up @@ -64,9 +64,11 @@
row :last_reported_year
row :cp_alignment_2050
row :cp_alignment_2025
row :cp_alignment_2027
row :cp_alignment_2035
row :region
row :cp_regional_alignment_2025
row :cp_regional_alignment_2027
row :cp_regional_alignment_2035
row :cp_regional_alignment_2050
row :years_with_targets
Expand Down Expand Up @@ -101,6 +103,7 @@
column :sector
column :cp_alignment_2050
column :cp_alignment_2025
column :cp_alignment_2027
column :cp_alignment_2035
column :assessment_date
column :publication_date
Expand Down Expand Up @@ -132,6 +135,7 @@

if params[:cp_assessmentable_type] == 'Company'
column :cp_alignment_2025
column :cp_alignment_2027
column :cp_alignment_2035
column :cp_alignment_2050
column :cp_regional_alignment_2025
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/tpi/ascor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ def user_download
private

def fetch_ascor_countries
@countries = ASCOR::Country.all.order(:name)
@countries = ASCOR::Country.published.all.order(:name)
@countries_json = [
{name: 'All countries', path: tpi_ascor_index_path},
*@countries.as_json(only: [:name], methods: [:path])
]
end

def fetch_ascor_country
@country = ASCOR::Country.friendly.find(params[:id])
@country = ASCOR::Country.published.friendly.find(params[:id])
rescue ActiveRecord::RecordNotFound
redirect_to tpi_ascor_index_path
end

def fetch_assessment_date
Expand Down
1 change: 1 addition & 0 deletions app/models/ascor/assessment_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class ASCOR::AssessmentResult < ApplicationRecord

scope :of_type, ->(type) { includes(:indicator).where(ascor_assessment_indicators: {indicator_type: type}) }
scope :by_date, ->(date) { includes(:assessment).where(ascor_assessments: {assessment_date: date}) }
scope :published, -> { includes(assessment: :country).where(ascor_countries: {visibility_status: 'published'}) }
end
11 changes: 2 additions & 9 deletions app/models/ascor/country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@
# created_at :datetime not null
# updated_at :datetime not null
# type_of_party :string
# visibility_status :string default("draft")
#
class ASCOR::Country < ApplicationRecord
include VisibilityStatus
extend FriendlyId

REGIONS = [
'Africa',
'Asia',
'Europe',
'Latin America and Caribbean',
'North America',
'Oceania'
].freeze
LENDING_GROUPS = %w[High-income Upper-middle-income Lower-middle-income Low-income].freeze
MONITOR_CATEGORIES = [
'Advanced economies',
Expand All @@ -47,7 +41,6 @@ class ASCOR::Country < ApplicationRecord

validates_presence_of :name, :slug, :iso, :region, :wb_lending_group, :fiscal_monitor_category
validates_uniqueness_of :name, :slug, :iso
validates :region, inclusion: {in: REGIONS}, allow_nil: true
validates :wb_lending_group, inclusion: {in: LENDING_GROUPS}, allow_nil: true
validates :fiscal_monitor_category, inclusion: {in: MONITOR_CATEGORIES}, allow_nil: true
validates :type_of_party, inclusion: {in: TYPE_OF_PARTY}, allow_nil: true
Expand Down
4 changes: 2 additions & 2 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class Company < ApplicationRecord

delegate :level, :status, :status_description_short,
to: :latest_mq_assessment, prefix: :mq, allow_nil: true
delegate :cp_alignment_2050, :cp_alignment_2025, :cp_alignment_2035,
:cp_regional_alignment_2050, :cp_regional_alignment_2025, :cp_regional_alignment_2035,
delegate :cp_alignment_2050, :cp_alignment_2025, :cp_alignment_2027, :cp_alignment_2035,
:cp_regional_alignment_2050, :cp_regional_alignment_2025, :cp_regional_alignment_2027, :cp_regional_alignment_2035,
to: :latest_cp_assessment, allow_nil: true

validates :ca100, inclusion: {in: [true, false]}
Expand Down
4 changes: 4 additions & 0 deletions app/models/cp/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# cp_assessmentable_id :bigint
# sector_id :bigint
# final_disclosure_year :integer
# cp_alignment_2027 :string
# cp_regional_alignment_2027 :string
#

module CP
Expand Down Expand Up @@ -59,9 +61,11 @@ class Assessment < ApplicationRecord

with_options allow_nil: true, allow_blank: true, inclusion: {in: CP::Alignment::ALLOWED_NAMES} do
validates :cp_alignment_2025
validates :cp_alignment_2027
validates :cp_alignment_2035
validates :cp_alignment_2050
validates :cp_regional_alignment_2025
validates :cp_regional_alignment_2027
validates :cp_regional_alignment_2035
validates :cp_regional_alignment_2050
end
Expand Down
19 changes: 10 additions & 9 deletions app/models/news_article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#
# Table name: news_articles
#
# id :bigint not null, primary key
# title :string
# content :text
# publication_date :datetime
# created_by_id :bigint
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# id :bigint not null, primary key
# title :string
# content :text
# publication_date :datetime
# created_by_id :bigint
# updated_by_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# is_insight :boolean default(FALSE)
# short_description :text
#

class NewsArticle < ApplicationRecord
Expand Down
2 changes: 1 addition & 1 deletion app/services/api/ascor/bubble_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def call
::ASCOR::AssessmentResult
.by_date(@assessment_date)
.of_type(:area)
.includes(assessment: :country)
.published
.order(:indicator_id)
.map do |result|
{
Expand Down
4 changes: 2 additions & 2 deletions app/services/api/ascor/emissions_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def collect_metadata

def countries
@countries ||= if country_ids.blank?
::ASCOR::Country.where(iso: ::ASCOR::Country::DEFAULT_COUNTRIES)
::ASCOR::Country.published.where(iso: ::ASCOR::Country::DEFAULT_COUNTRIES)
else
::ASCOR::Country.where(id: country_ids)
::ASCOR::Country.published.where(id: country_ids)
end
end

Expand Down
12 changes: 12 additions & 0 deletions app/services/api/presenters/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def cp_alignment_2025
CP::Alignment.new(name: @company.cp_alignment_2025, sector: @company.sector.name)
end

def cp_alignment_2027
return unless @company.cp_alignment_2027.present?

CP::Alignment.new(name: @company.cp_alignment_2027, sector: @company.sector.name)
end

def cp_alignment_2035
return unless @company.cp_alignment_2035.present?

Expand All @@ -58,6 +64,12 @@ def cp_regional_alignment_2025
CP::Alignment.new(name: @company.cp_regional_alignment_2025, sector: @company.sector.name)
end

def cp_regional_alignment_2027
return unless @company.cp_regional_alignment_2027.present?

CP::Alignment.new(name: @company.cp_regional_alignment_2027, sector: @company.sector.name)
end

def cp_regional_alignment_2035
return unless @company.cp_regional_alignment_2035.present?

Expand Down
3 changes: 2 additions & 1 deletion app/services/csv_export/ascor/assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def year_values_for(assessment)
end

def assessments
@assessments ||= ::ASCOR::Assessment.joins(:country).includes(:country).order(:assessment_date, 'ascor_countries.name')
@assessments ||= ::ASCOR::Assessment.joins(:country).includes(:country)
.where(ascor_countries: {visibility_status: 'published'}).order(:assessment_date, 'ascor_countries.name')
end

def assessment_results
Expand Down
3 changes: 2 additions & 1 deletion app/services/csv_export/ascor/benchmarks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def year_columns
end

def benchmarks
@benchmarks ||= ::ASCOR::Benchmark.joins(:country).includes(:country).order('ascor_countries.name')
@benchmarks ||= ::ASCOR::Benchmark.joins(:country).includes(:country)
.where(ascor_countries: {visibility_status: 'published'}).order('ascor_countries.name')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/csv_export/ascor/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def call
private

def countries
@countries ||= ::ASCOR::Country.order(:name)
@countries ||= ::ASCOR::Country.published.order(:name)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/services/csv_export/ascor/pathways.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def year_columns

def pathways
@pathways ||= ::ASCOR::Pathway.joins(:country).includes(:country)
.where(ascor_countries: {visibility_status: 'published'})
.order(:assessment_date, 'ascor_countries.name')
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/services/csv_export/user/company_cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def call
'Publication Date',
'Assessment Date',
'Carbon Performance Alignment 2025',
'Carbon Performance Alignment 2027',
'Carbon Performance Alignment 2035',
'Carbon Performance Alignment 2050',
'Benchmark ID',
Expand Down Expand Up @@ -48,6 +49,7 @@ def call
assessment.publication_date,
assessment.assessment_date,
assessment.cp_alignment_2025,
assessment.cp_alignment_2027,
assessment.cp_alignment_2035,
assessment.cp_alignment_2050,
assessment.cp_benchmark_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def call
'Assessment Date',
'Region',
'Carbon Performance Regional Alignment 2025',
'Carbon Performance Regional Alignment 2027',
'Carbon Performance Regional Alignment 2035',
'Carbon Performance Regional Alignment 2050',
'Regional Benchmark ID',
Expand Down Expand Up @@ -52,6 +53,7 @@ def call
assessment.assessment_date,
assessment.region,
assessment.cp_regional_alignment_2025,
assessment.cp_regional_alignment_2027,
assessment.cp_regional_alignment_2035,
assessment.cp_regional_alignment_2050,
assessment.cp_regional_benchmark_id,
Expand Down
4 changes: 4 additions & 0 deletions app/services/csv_export/user/company_latest_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ def call
'CP Assessment Date',
'Benchmark ID',
'Carbon Performance Alignment 2025',
'Carbon Performance Alignment 2027',
'Carbon Performance Alignment 2035',
'Carbon Performance Alignment 2050',
'Years with targets',
'Previous Carbon Performance Alignment 2025',
'Previous Carbon Performance Alignment 2027',
'Previous Carbon Performance Alignment 2035',
'Previous Carbon Performance Alignment 2050',
'Previous Years with targets',
Expand Down Expand Up @@ -74,10 +76,12 @@ def call
cp_assessment&.assessment_date,
cp_assessment&.cp_benchmark_id,
cp_assessment&.cp_alignment_2025,
cp_assessment&.cp_alignment_2027,
cp_assessment&.cp_alignment_2035,
cp_assessment&.cp_alignment_2050,
cp_assessment&.years_with_targets&.join(';'),
prev_cp_assessment&.cp_alignment_2025,
prev_cp_assessment&.cp_alignment_2027,
prev_cp_assessment&.cp_alignment_2035,
prev_cp_assessment&.cp_alignment_2050,
prev_cp_assessment&.years_with_targets&.join(';'),
Expand Down
1 change: 1 addition & 0 deletions app/services/csv_import/ascor_countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def import
if row.header?(:type_of_party_to_the_united_nations_framework_convention_on_climate_change)
country.type_of_party = row[:type_of_party_to_the_united_nations_framework_convention_on_climate_change]
end
country.visibility_status = row[:visibility_status]&.downcase if row.header?(:visibility_status)

was_new_record = country.new_record?
any_changes = country.changed?
Expand Down
4 changes: 4 additions & 0 deletions app/services/csv_import/company_cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ def import
assessment.emissions = parse_emissions(row) if emission_headers?(row)
assessment.last_reported_year = row[:last_reported_year] if row.header?(:last_reported_year)
assessment.cp_alignment_2025 = CP::Alignment.format_name(row[:cp_alignment_2025]) if row.header?(:cp_alignment_2025)
assessment.cp_alignment_2027 = CP::Alignment.format_name(row[:cp_alignment_2027]) if row.header?(:cp_alignment_2027)
assessment.cp_alignment_2035 = CP::Alignment.format_name(row[:cp_alignment_2035]) if row.header?(:cp_alignment_2035)
assessment.cp_alignment_2050 = CP::Alignment.format_name(row[:cp_alignment_2050]) if row.header?(:cp_alignment_2050)
assessment.region = parse_cp_benchmark_region(row[:region]) if row.header?(:region)
if row.header?(:cp_regional_alignment_2025)
assessment.cp_regional_alignment_2025 = CP::Alignment.format_name(row[:cp_regional_alignment_2025])
end
if row.header?(:cp_regional_alignment_2027)
assessment.cp_regional_alignment_2027 = CP::Alignment.format_name(row[:cp_regional_alignment_2027])
end
if row.header?(:cp_regional_alignment_2035)
assessment.cp_regional_alignment_2035 = CP::Alignment.format_name(row[:cp_regional_alignment_2035])
end
Expand Down
Loading

0 comments on commit 507002f

Please sign in to comment.