Skip to content

Commit

Permalink
refactoring: Show only MQ BETA companies when BETA methodology is ena…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
martintomas committed Nov 7, 2023
1 parent e44d67b commit fd7aa24
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
9 changes: 8 additions & 1 deletion 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: @enable_beta_mq_assessments ? MQ::Assessment::BETA_METHODOLOGIES.keys.max : 4
data: max_level
}
]
end
Expand All @@ -50,6 +50,13 @@ def company_mq_assessments
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
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
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 fd7aa24

Please sign in to comment.