Skip to content

Commit

Permalink
Merge pull request #472 from Vizzuality/master
Browse files Browse the repository at this point in the history
Sync with master
  • Loading branch information
martintomas authored Nov 7, 2023
2 parents 28fad1e + ac1ba47 commit d6f8535
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 52 deletions.
6 changes: 3 additions & 3 deletions app/assets/stylesheets/tpi/_publications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ $max-lines: 3;
}

&__content-type {
color: $grey-dark;
margin-top: 10px;
color: $blue;
margin: 0 0 10px 0;
font-size: $size-7;
border: 1px solid rgba($grey-dark, 0.5);
border: 1px solid rgba($blue, 0.5);
padding-left: $size-7;
padding-right: $size-7;
display: inline-block;
Expand Down
12 changes: 4 additions & 8 deletions app/controllers/tpi/sectors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ def index
end
@publications_and_articles = publications_and_articles
sectors_page = TPIPage.find_by(slug: 'publicly-listed-equities-content')
@methodology_description = Content.find_by(
page: sectors_page,
code: 'methodology_description'
)
@methodology_id = Content.find_by(
page: sectors_page,
code: 'methodology_publication_id'
)
@methodology_description = Content.find_by(page: sectors_page, code: 'methodology_description')
@methodology_id = Content.find_by(page: sectors_page, code: 'methodology_publication_id')
@beta_methodology_id = Content.find_by(page: sectors_page, code: 'beta_methodology_publication_id')
@methodology_id = @beta_methodology_id || @methodology_id if session[:enable_beta_mq_assessments]
@methodology_publication = Publication.find_by(id: @methodology_id&.text)

fixed_navbar('Sectors', admin_tpi_sectors_path)
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/mq_assessment_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module MQAssessmentHelper
def hide_mq_assessments_with_same_date(assessments)
result = []
assessments.group_by(&:assessment_date).each { |_date, a| result << a.max_by(&:methodology_version) }
result
end
end
9 changes: 4 additions & 5 deletions app/javascript/components/tpi/MqBetaModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { OverlayProvider } from '@react-aria/overlays';

const TPI_MODAL_DISMISSED = 'TPI_MODAL_DISMISSED';
const TPI_MODAL_PAGES_SHOWN = 'TPI_MODAL_PAGES_SHOWN';
const MQ_REPORT_PUBLICATION_LINK = '/static_files/23-10-20 MQ V5 Report for publication.pptx';
const MQ_REPORT_PUBLICATION_LINK = '/static_files/Raising the Bar. TPI\'s new Management Quality framework.pdf';

const MqBetaModal = ({ enabled, page }) => {
const [displayed, setDisplayed] = useState(false);
Expand Down Expand Up @@ -63,7 +63,7 @@ const MqBetaModal = ({ enabled, page }) => {
>
<div className="icon__close" />
</button>
<div className="modal-title">Management Quality (MQ) methodology</div>
<div className="modal-title">Management Quality methodology</div>
<div className="content">
<p>
The TPI Centre has developed an update to its Management Quality
Expand All @@ -79,9 +79,8 @@ const MqBetaModal = ({ enabled, page }) => {
website until at least September 2024.
</p>
<p>
The detailed methodology note behind the BETA MQ methodology,
including a section discussing methodological differences between
it and the existing methodology, can be found <a href={MQ_REPORT_PUBLICATION_LINK}>here</a>.
A report detailing what’s new in the BETA MQ methodology,
and a review of its impact on company scoring, can be found <a href={MQ_REPORT_PUBLICATION_LINK} rel="noreferrer" target="_blank">here</a>.
</p>
<p>
Carbon Performance assessments are not affected by using this
Expand Down
2 changes: 1 addition & 1 deletion app/models/mq/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def previous_assessments
# keep select and sort by, company - mq assessments will be cached once
company
.mq_assessments
.currently_published
.select { |a| a.publication_date <= DateTime.now }
.select { |a| a.assessment_date < assessment_date }
.sort_by(&:assessment_date)
end
Expand Down
17 changes: 15 additions & 2 deletions app/services/api/charts/mq_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assessments_levels_data
},
{
name: 'Max Level',
data: assessment.beta_methodology? ? assessment.beta_levels.last.to_i : 4
data: max_level
}
]
end
Expand All @@ -47,9 +47,22 @@ def company_mq_assessments
@company_mq_assessments ||= begin
query = company.mq_assessments.currently_published.order(:assessment_date)
query = query.without_beta_methodologies unless @enable_beta_mq_assessments
query
hide_mq_assessments_with_same_date query
end
end

def max_level
beta_assessment = company_mq_assessments.detect(&:beta_methodology?)
return 4 unless beta_assessment.present?

beta_assessment.beta_levels.last.to_i
end

def hide_mq_assessments_with_same_date(assessments)
result = []
assessments.group_by(&:assessment_date).each { |_date, a| result << a.max_by(&:methodology_version) }
result
end
end
end
end
6 changes: 6 additions & 0 deletions app/services/api/charts/sector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def companies_grouped_by_latest_assessment_level
)
.map { |c| update_beta_mq_assessments_visibility c }
.reject { |c| c.mq_level.nil? }
.select { |c| @enable_beta_mq_assessments ? c.latest_mq_assessment.beta_methodology? : true }
.group_by { |c| c.mq_level.to_i.to_s }
end

Expand All @@ -126,6 +127,7 @@ def companies_grouped_by_sector
:latest_mq_assessment_only_beta_methodologies
)
.map { |c| update_beta_mq_assessments_visibility c }
.select { |c| @enable_beta_mq_assessments ? c.latest_mq_assessment.beta_methodology? : true }
.group_by { |company| company.sector.name }
end

Expand Down Expand Up @@ -215,6 +217,10 @@ def update_beta_mq_assessments_visibility(company)
company.show_beta_mq_assessments = @enable_beta_mq_assessments
company
end

def keep_only_beta_mq_assessments(companies)
companies.select { |c| c.latest_mq_assessment.beta_methodology? }
end
end
end
end
4 changes: 2 additions & 2 deletions app/views/tpi/companies/_mq_assessment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

<div class="column">
<div class="mq-assessment-box">
<div class="is-hidden-touch">Nr of assessments: <%= assessment.previous_assessments.size + 1 %></div>
<div class="is-hidden-touch">Nr of assessments: <%= hide_mq_assessments_with_same_date(assessment.previous_assessments).size + 1 %></div>
<div class="is-hidden-desktop">
Number of assessments: <span class="assessment-count"><%= assessment.previous_assessments.size + 1 %></span>
Number of assessments: <span class="assessment-count"><%= hide_mq_assessments_with_same_date(assessment.previous_assessments).size + 1 %></span>
</div>

<%= react_component('charts/mq-level', {
Expand Down
4 changes: 2 additions & 2 deletions app/views/tpi/companies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<div class="summary-box summary-box--assessment">
<h4>Management Quality</h4>
<p>
<small>Number of assessments: <%= @company_presenter.mq_assessments.size %></small>
<small>Number of assessments: <%= hide_mq_assessments_with_same_date(@company_presenter.mq_assessments).size %></small>
</p>
<% if @company_presenter.mq_assessments.any? %>
<%= render 'mq_level', level: @company.mq_level, status: @company.mq_status %>
Expand Down Expand Up @@ -170,7 +170,7 @@
name: 'mq_assessment_id',
remote: true,
url: mq_assessment_tpi_company_path(@company),
data: @company_presenter.mq_assessments.map {|v| {label: v['assessment_date']&.strftime('%d %B %Y'), value: v['id']}},
data: hide_mq_assessments_with_same_date(@company_presenter.mq_assessments).map {|v| {label: v['assessment_date']&.strftime('%d %B %Y'), value: v['id']}},
selected: params[:mq_assessment_id]
}) %>
</div>
Expand Down
17 changes: 10 additions & 7 deletions app/views/tpi/publications/_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
<% end %>
</div>
</div>

<div class="publication__content-type">
<% if publication.is_a?(NewsArticle) %>
<%= publication.is_insight? ? 'Insights' : 'News' %>
<% else %>
Publications
<% end %>
</div>

<p class="updated_at "><%= publication.publication_date.strftime('%d/%m/%Y') %></p>

<div class="content__message">
Expand All @@ -29,13 +38,7 @@
<% end %>
</p>
</div>
<div class="publication__content-type">
<% if publication.is_a?(NewsArticle) %>
<%= publication.is_insight? ? 'Insights' : 'News' %>
<% else %>
Publications
<% end %>
</div>

<% if publication.keywords.any? || publication.tpi_sectors.any? %>
<div class="publication__tags">
<% publication.tags_and_sectors.each do |tag| %>
Expand Down
9 changes: 5 additions & 4 deletions app/views/tpi/publications/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
<h1 class="pages__title"><%= @publication.title %></h1>
<p class="pages__date"><%= @publication.publication_date.strftime('%d/%m/%Y') %></p>

<div class="pages__content__flex">
<div>
<% if @publication.image.present? %>
<div class="pages__image" style="margin-bottom: 0;"><%= image_tag(@publication.image) %></div>
<% end %>
<div class="pages__description">
<p><%= @publication.short_description %></p>
<div class="pages__description" style="font-size: 20px;">
<% if @publication.keywords.any? || @publication.tpi_sectors.any? %>
<div class="publication__tags">
<div class="publication__tags" style="margin-bottom: 0px;">
<% @publication.tags_and_sectors.each do |tag| %>
<span class="tag"><%= tag %></span>
<% end %>
</div>
<% end %>
<p style="margin-bottom: 20px;"><%= @publication.short_description %></p>

<div class="pages__description">
<%= @publication.summary&.html_safe %>
</div>
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions spec/services/api/charts/mq_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
create(:mq_assessment, company: company, assessment_date: '2018-08-08', publication_date: '2018-08-08', level: '2')
create(:mq_assessment, company: company, assessment_date: '2019-02-02', publication_date: '2019-02-02', level: '4')
create(:mq_assessment, company: company, assessment_date: '2020-03-03', publication_date: '2020-03-03', level: '3')
create(:mq_assessment, company: company, assessment_date: '2021-03-03', publication_date: '2021-03-03', level: '4')
# beta scores
create(:mq_assessment,
company: company,
Expand All @@ -43,7 +44,8 @@
['01/01/2018', 3],
['08/08/2018', 2],
['02/02/2019', 4],
['03/03/2020', 3]
['03/03/2020', 3],
['03/03/2021', 4]
],
name: 'Level'
},
Expand All @@ -64,7 +66,7 @@
context 'when beta assessments are enabled' do
subject do
described_class.new(
company.mq_assessments.where(assessment_date: '2021-03-03').first,
company.mq_assessments.where(assessment_date: '2021-03-03', methodology_version: beta_methodology).first,
enable_beta_mq_assessments: true
)
end
Expand Down
51 changes: 35 additions & 16 deletions spec/services/api/charts/sector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let_it_be(:sector2) { create(:tpi_sector, name: 'Autos') }
let_it_be(:company) { create(:company, sector: sector) }
let_it_be(:company2) { create(:company, sector: sector2) }
let_it_be(:company3) { create(:company, sector: sector2) }
let_it_be(:beta_methodology_version) { MQ::Assessment::BETA_METHODOLOGIES.keys.first }
let_it_be(:beta_level) { MQ::Assessment::BETA_METHODOLOGIES[beta_methodology_version][:levels].first }

Expand Down Expand Up @@ -36,6 +37,13 @@
level: beta_level,
methodology_version: beta_methodology_version
)
create(
:mq_assessment,
company: company3,
assessment_date: '2020-01-01',
level: 3,
methodology_version: beta_methodology_version
)
# should be ignored
create(
:mq_assessment,
Expand Down Expand Up @@ -128,7 +136,18 @@
'4' => []
},
sector2.name => {
'0' => [],
'0' => [
{
name: company3.name,
slug: company3.slug,
path: company3.path,
sector: company3.sector.name,
market_cap_group: company3.market_cap_group,
level: company3.mq_level.to_i.to_s,
level4STAR: false,
status: company3.mq_status
}
],
'1' => [],
'2' => [],
'3' => [],
Expand Down Expand Up @@ -158,10 +177,10 @@
'0' => [],
'1' => [],
'2' => [],
'3' => [],
'4' => [
{id: company2.id, name: company2.name, status: 'new', level: '4STAR', slug: company2.slug}
'3' => [
{id: company3.id, name: company3.name, status: 'new', level: '3', slug: company3.slug}
],
'4' => [],
beta_level => [
{id: company.id, name: company.name, status: 'unchanged', level: beta_level, slug: company.slug}
]
Expand All @@ -175,8 +194,8 @@
'0' => 0,
'1' => 0,
'2' => 0,
'3' => 0,
'4' => 1,
'3' => 1,
'4' => 0,
beta_level => 1
)
end
Expand Down Expand Up @@ -208,19 +227,19 @@
'0' => [],
'1' => [],
'2' => [],
'3' => [],
'4' => [
'3' => [
{
name: company2.name,
slug: company2.slug,
path: company2.path,
sector: company2.sector.name,
market_cap_group: company2.market_cap_group,
level: company2.mq_level.to_i.to_s,
level4STAR: true,
status: company2.mq_status
name: company3.name,
slug: company3.slug,
path: company3.path,
sector: company3.sector.name,
market_cap_group: company3.market_cap_group,
level: '3',
level4STAR: false,
status: 'new'
}
],
'4' => [],
beta_level => []
}
)
Expand Down

0 comments on commit d6f8535

Please sign in to comment.