Skip to content

Commit

Permalink
Merge pull request #434 from Vizzuality/fix/mq-beta-scores
Browse files Browse the repository at this point in the history
feat: minor tweaks and fixes of MQ BETA scores
  • Loading branch information
martintomas authored Aug 23, 2023
2 parents 7491c6c + d9ea6e6 commit b0bf06a
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 98 deletions.
122 changes: 61 additions & 61 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.7.4)
actionpack (= 6.1.7.4)
activesupport (= 6.1.7.4)
actioncable (6.1.7.6)
actionpack (= 6.1.7.6)
activesupport (= 6.1.7.6)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.7.4)
actionpack (= 6.1.7.4)
activejob (= 6.1.7.4)
activerecord (= 6.1.7.4)
activestorage (= 6.1.7.4)
activesupport (= 6.1.7.4)
actionmailbox (6.1.7.6)
actionpack (= 6.1.7.6)
activejob (= 6.1.7.6)
activerecord (= 6.1.7.6)
activestorage (= 6.1.7.6)
activesupport (= 6.1.7.6)
mail (>= 2.7.1)
actionmailer (6.1.7.4)
actionpack (= 6.1.7.4)
actionview (= 6.1.7.4)
activejob (= 6.1.7.4)
activesupport (= 6.1.7.4)
actionmailer (6.1.7.6)
actionpack (= 6.1.7.6)
actionview (= 6.1.7.6)
activejob (= 6.1.7.6)
activesupport (= 6.1.7.6)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.7.4)
actionview (= 6.1.7.4)
activesupport (= 6.1.7.4)
actionpack (6.1.7.6)
actionview (= 6.1.7.6)
activesupport (= 6.1.7.6)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.7.4)
actionpack (= 6.1.7.4)
activerecord (= 6.1.7.4)
activestorage (= 6.1.7.4)
activesupport (= 6.1.7.4)
actiontext (6.1.7.6)
actionpack (= 6.1.7.6)
activerecord (= 6.1.7.6)
activestorage (= 6.1.7.6)
activesupport (= 6.1.7.6)
nokogiri (>= 1.8.5)
actionview (6.1.7.4)
activesupport (= 6.1.7.4)
actionview (6.1.7.6)
activesupport (= 6.1.7.6)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
Expand All @@ -59,28 +59,28 @@ GEM
sassc
sassc-rails
xdan-datetimepicker-rails (~> 2.5.1)
activejob (6.1.7.4)
activesupport (= 6.1.7.4)
activejob (6.1.7.6)
activesupport (= 6.1.7.6)
globalid (>= 0.3.6)
activemodel (6.1.7.4)
activesupport (= 6.1.7.4)
activemodel (6.1.7.6)
activesupport (= 6.1.7.6)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (6.1.7.4)
activemodel (= 6.1.7.4)
activesupport (= 6.1.7.4)
activerecord (6.1.7.6)
activemodel (= 6.1.7.6)
activesupport (= 6.1.7.6)
activerecord-import (1.4.0)
activerecord (>= 4.2)
activestorage (6.1.7.4)
actionpack (= 6.1.7.4)
activejob (= 6.1.7.4)
activerecord (= 6.1.7.4)
activesupport (= 6.1.7.4)
activestorage (6.1.7.6)
actionpack (= 6.1.7.6)
activejob (= 6.1.7.6)
activerecord (= 6.1.7.6)
activesupport (= 6.1.7.6)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.7.4)
activesupport (6.1.7.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -294,12 +294,12 @@ GEM
memoist (0.16.2)
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.18.1)
minitest (5.19.0)
msgpack (1.5.3)
multi_json (1.15.0)
net-imap (0.3.6)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -312,7 +312,7 @@ GEM
net-protocol
net-ssh (7.0.1)
nio4r (2.5.9)
nokogiri (1.15.3)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
optimist (3.0.1)
Expand All @@ -339,42 +339,42 @@ GEM
puma (5.6.7)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack (2.2.8)
rack-cors (1.1.1)
rack (>= 2.0.0)
rack-proxy (0.7.2)
rack
rack-test (2.1.0)
rack (>= 1.3)
rails (6.1.7.4)
actioncable (= 6.1.7.4)
actionmailbox (= 6.1.7.4)
actionmailer (= 6.1.7.4)
actionpack (= 6.1.7.4)
actiontext (= 6.1.7.4)
actionview (= 6.1.7.4)
activejob (= 6.1.7.4)
activemodel (= 6.1.7.4)
activerecord (= 6.1.7.4)
activestorage (= 6.1.7.4)
activesupport (= 6.1.7.4)
rails (6.1.7.6)
actioncable (= 6.1.7.6)
actionmailbox (= 6.1.7.6)
actionmailer (= 6.1.7.6)
actionpack (= 6.1.7.6)
actiontext (= 6.1.7.6)
actionview (= 6.1.7.6)
activejob (= 6.1.7.6)
activemodel (= 6.1.7.6)
activerecord (= 6.1.7.6)
activestorage (= 6.1.7.6)
activesupport (= 6.1.7.6)
bundler (>= 1.15.0)
railties (= 6.1.7.4)
railties (= 6.1.7.6)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.1.1)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (6.1.7.4)
actionpack (= 6.1.7.4)
activesupport (= 6.1.7.4)
railties (6.1.7.6)
actionpack (= 6.1.7.6)
activesupport (= 6.1.7.6)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -535,15 +535,15 @@ GEM
semantic_range (>= 2.3.0)
webrick (1.7.0)
websocket (1.2.9)
websocket-driver (0.7.5)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xdan-datetimepicker-rails (2.5.4)
jquery-rails
rails (>= 3.2.16)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.8)
zeitwerk (2.6.11)

PLATFORMS
ruby
Expand Down
28 changes: 25 additions & 3 deletions app/assets/stylesheets/tpi/pages/company.scss
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,18 @@
}
}

$assesment-level-padding: 40px;

.mq-assessment-questions {
margin-top: 50px;

.mq-assessment-level {
padding: 40px;
padding: $assesment-level-padding;

border-left: 2px solid $hawkes-blue;

&.level5 {
background-color: rgba($tpi-level5-background-color, 0.15) ;
background-color: rgba($tpi-level5-background-color, 0.15);
}

&__header {
Expand All @@ -260,9 +262,29 @@

.mq-assessment-question {
margin: 30px 0;

position: relative;

&.highlight-question {
.question-text {
display: block;
position: relative;
background-color: rgba($tpi-level5-background-color, 0.15);
// Use z-index to make sure the question is below the icon
z-index: -1;

// Use transform, padding and width to show the background on the full space of the question
@include until($desktop) {
width: calc(100% + #{$assesment-level-padding} + #{$assesment-level-padding});
transform: translate(-27px, 0px);
padding: 13px $assesment-level-padding 8px 27px;
}

width: calc(100% + #{$assesment-level-padding} + #{$assesment-level-padding});
transform: translate(-$assesment-level-padding, -13px);
padding: 13px $assesment-level-padding 8px $assesment-level-padding;
}
}

.mq-assessment-answer {
width: 36px;
height: 36px;
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/tpi/mq_assessments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ def show; end
def enable_beta_data
session[:enable_beta_mq_assessments] = true

redirect_back fallback_location: tpi_root_url
redirect_to redirect_back_path
end

def disable_beta_data
session[:enable_beta_mq_assessments] = false

redirect_back fallback_location: tpi_root_url
redirect_to redirect_back_path
end

private

def redirect_back_path
return tpi_root_url unless request.referer.present?

URI(request.referer).path
end
end
end
5 changes: 2 additions & 3 deletions app/javascript/components/tpi/charts/mq-level/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const greyDark = '#595B5D';
const dark = '#191919';

export function getOptions({ chartData }) {
const yAxisDataLevels = chartData.find(d => d.name === 'Level')?.data?.map(d => d[1]);
const yAxisMaxLevel = yAxisDataLevels?.length > 0 ? Math.max(...yAxisDataLevels) : 0;
const yAxisMaxLevel = chartData.find(d => d.name === 'Max Level')?.data || 4;
return merge({}, defaultOptions, {
chart: {
marginTop: 50,
Expand Down Expand Up @@ -73,7 +72,7 @@ export function getOptions({ chartData }) {
y: -20
}
},
series: chartData.map(d => ({
series: chartData.filter(d => ['Level', 'Current Level'].includes(d.name)).map(d => ({
...d,
clip: false,
lineWidth: 5,
Expand Down
15 changes: 7 additions & 8 deletions app/models/mq/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ class Assessment < ApplicationRecord
include TPICache

LEVELS = %w[0 1 2 3 4 4STAR 5].freeze
BETA_METHODOLOGIES = [5].freeze # taken into account only when beta is enabled
BETA_LEVELS_PER_METHODOLOGY = { # which levels should be automatically added and marked as BETAs based on methodology
5 => %w[5]
BETA_METHODOLOGIES = { # taken into account only when beta is enabled
5 => {levels: %w[5], highlight_questions: %w[18]}
}.freeze
BETA_LEVELS = BETA_LEVELS_PER_METHODOLOGY.values.flatten.freeze
BETA_LEVELS = BETA_METHODOLOGIES.map { |_k, v| v[:levels] }.flatten.freeze

belongs_to :company, inverse_of: :mq_assessments

scope :latest_first, -> { order(assessment_date: :desc) }
scope :all_publication_dates, -> { distinct.order(publication_date: :desc).pluck(:publication_date) }
scope :all_methodology_versions, -> { distinct.order(methodology_version: :asc).pluck(:methodology_version) }
scope :currently_published, -> { where('publication_date <= ?', DateTime.now) }
scope :without_beta_methodologies, -> { where.not(methodology_version: BETA_METHODOLOGIES) }
scope :only_beta_methodologies, -> { where(methodology_version: BETA_METHODOLOGIES) }
scope :without_beta_methodologies, -> { where.not(methodology_version: BETA_METHODOLOGIES.keys) }
scope :only_beta_methodologies, -> { where(methodology_version: BETA_METHODOLOGIES.keys) }

validates :level, inclusion: {in: LEVELS}
validates_presence_of :assessment_date, :publication_date, :level, :methodology_version
Expand Down Expand Up @@ -100,11 +99,11 @@ def questions_by_level
end

def beta_methodology?
BETA_METHODOLOGIES.include? methodology_version
BETA_METHODOLOGIES.key? methodology_version
end

def beta_levels
Array.wrap BETA_LEVELS_PER_METHODOLOGY[methodology_version]
Array.wrap BETA_METHODOLOGIES.dig(methodology_version, :levels)
end
end
end
4 changes: 4 additions & 0 deletions app/services/api/charts/mq_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def assessments_levels_data
{
name: 'Current Level',
data: [[assessment.assessment_date.to_s, assessment.level.to_i]]
},
{
name: 'Max Level',
data: assessment.beta_methodology? ? assessment.beta_levels.last.to_i : 4
}
]
end
Expand Down
7 changes: 3 additions & 4 deletions app/views/tpi/companies/_mq_assessment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
</div>

<%= react_component('charts/mq-level', {
dataUrl: assessments_levels_chart_data_tpi_company_path(@company.id, mq_assessment_id: assessment.id),
betaLevels: assessment.beta_levels
dataUrl: assessments_levels_chart_data_tpi_company_path(@company.id, mq_assessment_id: assessment.id)
}) %>
</div>
</div>
Expand All @@ -38,10 +37,10 @@
<div class="mq-assessment-answers">
<% questions.each do |question| %>

<p class="mq-assessment-question">
<p class="<%= class_names('mq-assessment-question', 'highlight-question': MQ::Assessment::BETA_METHODOLOGIES.dig(assessment.methodology_version, :highlight_questions)&.include?(question.number.to_s)) %>">
<span class="mq-assessment-answer mq-assessment-answer--<%= question.answer.parameterize %> level<%= level %>">
</span>
<%= question.number %>. <%= question.question %>
<span class="question-text"><%= question.number %>. <%= question.question %></span>
</p>
<% end %>
</div>
Expand Down
Loading

0 comments on commit b0bf06a

Please sign in to comment.