Skip to content

Commit

Permalink
feat: Adding assessment date flags
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Nov 15, 2024
1 parent 63a22da commit 19c9314
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 309 deletions.
4 changes: 3 additions & 1 deletion app/admin/cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
permit_params :sector_id, :assessment_date, :publication_date, :cp_assessmentable_id, :last_reported_year,
: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_regional_alignment_2050, :years_with_targets_string, :emissions, :assessment_date_flag,
cp_matrices_attributes: [:id, :portfolio, :cp_alignment_2025, :cp_alignment_2035, :cp_alignment_2050, :_destroy]

filter :assessment_date
Expand Down Expand Up @@ -60,6 +60,7 @@
end
row :sector
row :assessment_date
row :assessment_date_flag
row :publication_date
row :last_reported_year
row :cp_alignment_2050
Expand Down Expand Up @@ -123,6 +124,7 @@
record.sector.name
end
column :assessment_date
column :assessment_date_flag
column :publication_date, &:publication_date_csv
year_columns.map do |year|
column year do |a|
Expand Down
4 changes: 3 additions & 1 deletion app/services/csv_import/company_cp_assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def import
assessment = prepare_assessment(row)

assessment.assessment_date = assessment_date(row) if row.header?(:assessment_date)
assessment.assessment_date_flag = row[:assessment_date_flag] if row.header?(:assessment_date_flag)
assessment.publication_date = publication_date(row) if row.header?(:publication_date)
assessment.assumptions = row[:assumptions].presence if row.header?(:assumptions)
assessment.emissions = parse_emissions(row) if emission_headers?(row)
Expand Down Expand Up @@ -46,7 +47,8 @@ def prepare_assessment(row)
CP::Assessment.find_or_initialize_by(
cp_assessmentable_type: 'Company',
cp_assessmentable_id: find_company!(row)&.id,
assessment_date: assessment_date(row)
assessment_date: assessment_date(row),
assessment_date_flag: row.header?(:assessment_date_flag) ? row[:assessment_date_flag] : nil
)
end

Expand Down
1 change: 1 addition & 0 deletions app/views/admin/cp_assessments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
%>
<%= f.input :sector, collection: TPISector.tpi_tool %>
<%= f.input :assessment_date %>
<%= f.input :assessment_date_flag %>
<%= f.input :publication_date %>
<%= f.input :last_reported_year %>
<%= f.input :assumptions %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/tpi/companies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@
remote: true,
url: cp_assessment_tpi_company_path(@company),
params: regional_view ? "view=regional" : nil,
data: @company_presenter.cp_assessments.map {|v| {label: v['assessment_date']&.strftime('%d %B %Y'), value: v['id']}},
data: @company_presenter.cp_assessments.map do |v|
label = v['assessment_date']&.strftime('%d %B %Y')
label += " (#{v['assessment_date_flag']})" if v['assessment_date_flag'].present?
{label: label, value: v['id']}
end,
selected: params[:cp_assessment_id]
}) %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAssessmentDateFlagToCPAssessments < ActiveRecord::Migration[6.1]
def change
add_column :cp_assessments, :assessment_date_flag, :string
end
end
448 changes: 225 additions & 223 deletions db/seeds/tpi/company-cp-assessments.csv

Large diffs are not rendered by default.

156 changes: 78 additions & 78 deletions db/seeds/tpi/company-cp-benchmarks.csv

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,8 @@ CREATE TABLE public.cp_assessments (
sector_id bigint,
final_disclosure_year integer,
cp_alignment_2027 character varying,
cp_regional_alignment_2027 character varying
cp_regional_alignment_2027 character varying,
assessment_date_flag character varying
);


Expand Down Expand Up @@ -4178,6 +4179,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240119084250'),
('20240202090401'),
('20240206094238'),
('20240527100352');
('20240527100352'),
('20241115133904');


Binary file modified db/test-dump.psql
Binary file not shown.
2 changes: 2 additions & 0 deletions spec/commands/csv_data_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,9 @@
expect(assessment.cp_regional_alignment_2027).to eq('1.5 Degrees')
expect(assessment.cp_regional_alignment_2035).to eq('2 Degrees')
expect(assessment.cp_regional_alignment_2050).to eq('International Pledges')
expect(assessment.assessment_date_flag).to eq('old')
expect(assessment2.cp_alignment_2050).to eq('Not Aligned')
expect(assessment2.assessment_date_flag).to eq('new')
end

it 'imports CSV files with Bank CP Assessments data' do
Expand Down
1 change: 1 addition & 0 deletions spec/factories/cp_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
association :sector, factory: :tpi_sector

assessment_date { 1.year.ago }
assessment_date_flag { 'current' }
publication_date { 11.months.ago }
last_reported_year { 2020 }

Expand Down
6 changes: 3 additions & 3 deletions spec/support/fixtures/files/company_cp_assessments.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"Id","company_id","Company","Assessment date","Publication date","Last Reported Year",2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,"Assumptions","CP alignment 2025","CP alignment 2035","CP Alignment 2050","Region","CP regional alignment 2025","CP regional alignment 2035","CP regional alignment 2050",CP alignment 2027,CP regional alignment 2027
,1000,"ACME","2019-01-04","2019-02",2018,,101,101,100,101,100,99,98,,,,,,,,,,,"Assumptions for ACME","Paris Pledges","National Pledges","No Disclosure","OECD","1.5 degrees","2 degrees","International Pledges",Paris Pledges,1.5 degrees
,2000,"ACME Materials","2019-01-04","2019-02",2019,,,,,,,,,,,,,,,,,,,"Assumptions for ACME Materials",,,"Not aligned",,,,,,
"Id","company_id","Company","Assessment date","Assessment date flag","Publication date","Last Reported Year",2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,"Assumptions","CP alignment 2025","CP alignment 2035","CP Alignment 2050","Region","CP regional alignment 2025","CP regional alignment 2035","CP regional alignment 2050",CP alignment 2027,CP regional alignment 2027
,1000,"ACME","2019-01-04","old","2019-02",2018,,101,101,100,101,100,99,98,,,,,,,,,,,"Assumptions for ACME","Paris Pledges","National Pledges","No Disclosure","OECD","1.5 degrees","2 degrees","International Pledges",Paris Pledges,1.5 degrees
,2000,"ACME Materials","2019-01-04","new","2019-02",2019,,,,,,,,,,,,,,,,,,,"Assumptions for ACME Materials",,,"Not aligned",,,,,,

0 comments on commit 19c9314

Please sign in to comment.