diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 97758223..68fad040 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -23,18 +23,7 @@ class DashboardController < SqmApplicationController end def presenter_for_measure(measure) - sufficient_data = SurveyItemResponse.sufficient_data?(measure: measure, academic_year: academic_year, school: school) - - unless sufficient_data - return MeasureGraphRowPresenter.new( - measure: measure, - sufficient_data: false - ) - end - - score = SurveyItemResponse.for_measure(measure) - .where(academic_year: academic_year, school: school) - .average(:likert_score) + score = sufficient_data?(measure: measure) ? score(measure: measure) : nil MeasureGraphRowPresenter.new( measure: measure, @@ -42,4 +31,14 @@ class DashboardController < SqmApplicationController ) end + def sufficient_data?(measure:) + SurveyItemResponse.sufficient_data?(measure: measure, academic_year: academic_year, school: school) + end + + def score(measure:) + SurveyItemResponse.for_measure(measure) + .where(academic_year: academic_year, school: school) + .average(:likert_score) + end + end diff --git a/app/helpers/variance_helper.rb b/app/helpers/variance_helper.rb index 75684a4c..5ce84b4d 100644 --- a/app/helpers/variance_helper.rb +++ b/app/helpers/variance_helper.rb @@ -44,6 +44,6 @@ module VarianceHelper end def measures_with_insufficient_data(presenters:) - presenters.filter { |presenter| !presenter.sufficient_data? } + presenters.filter { |presenter| presenter.score == nil } end end diff --git a/app/presenters/measure_graph_row_presenter.rb b/app/presenters/measure_graph_row_presenter.rb index 9a57cf6f..f11ab77d 100644 --- a/app/presenters/measure_graph_row_presenter.rb +++ b/app/presenters/measure_graph_row_presenter.rb @@ -1,13 +1,15 @@ class MeasureGraphRowPresenter include Comparable - def initialize(measure:, score: 0, sufficient_data: true) + + attr_reader :score + + def initialize(measure:, score:) @measure = measure @score = score - @sufficient_data = sufficient_data end def sufficient_data? - @sufficient_data + @score != nil end def measure_name diff --git a/spec/views/dashboard/index.html.erb_spec.rb b/spec/views/dashboard/index.html.erb_spec.rb index f3d8646c..47465584 100644 --- a/spec/views/dashboard/index.html.erb_spec.rb +++ b/spec/views/dashboard/index.html.erb_spec.rb @@ -16,10 +16,10 @@ describe 'dashboard/index.html.erb' do context 'when there are measures for which, in the given academic year, the school has insufficient responses' do let(:measure_graph_row_presenters) { [ - MeasureGraphRowPresenter.new(measure: support_for_teaching, score: 0, sufficient_data: false), - MeasureGraphRowPresenter.new(measure: create(:measure), score: 0, sufficient_data: true), - MeasureGraphRowPresenter.new(measure: effective_leadership, score: 0, sufficient_data: false), - MeasureGraphRowPresenter.new(measure: professional_qualifications, score: 0, sufficient_data: false) + MeasureGraphRowPresenter.new(measure: support_for_teaching, score: nil), + MeasureGraphRowPresenter.new(measure: create(:measure), score: rand), + MeasureGraphRowPresenter.new(measure: effective_leadership, score: nil), + MeasureGraphRowPresenter.new(measure: professional_qualifications, score: nil) ] } @@ -31,7 +31,7 @@ describe 'dashboard/index.html.erb' do context 'when there are no measures for which, in the given academic year, the school has insufficient responses' do let(:measure_graph_row_presenters) { [ - MeasureGraphRowPresenter.new(measure: create(:measure), score: 0, sufficient_data: true) + MeasureGraphRowPresenter.new(measure: create(:measure), score: rand) ] }