chore: refactor analyze page

mciea-main
Nelson Jovel 2 years ago
parent 5dcb163ab8
commit b77d6134df

@ -13,7 +13,7 @@ module Analyze
end end
def columns def columns
[AllStudent, AllTeacher, AllAdmin, GroupedBarColumnPresenter] [AllStudent, AllTeacher, AllAdmin, Analyze::Graph::Column::AllData]
end end
end end
end end

@ -26,8 +26,8 @@ module Analyze
["data not", "available"] ["data not", "available"]
end end
def score(year_index) def score(academic_year)
measure.admin_score(school:, academic_year: academic_years[year_index]) measure.admin_score(school:, academic_year:)
end end
def type def type

@ -0,0 +1,37 @@
module Analyze
module Graph
module Column
class AllData < GroupedBarColumnPresenter
def label
%w[All Data]
end
def show_irrelevancy_message?
false
end
def show_insufficient_data_message?
scores = academic_years.map do |year|
measure.score(school:, academic_year: year)
end
scores.none? do |score|
score.meets_teacher_threshold? || score.meets_student_threshold? || score.meets_admin_data_threshold?
end
end
def score(academic_year)
measure.score(school:, academic_year:) || 0
end
def type
:all_data
end
def basis
"student surveys"
end
end
end
end
end

@ -17,11 +17,11 @@ module Analyze
measure.score(school:, academic_year: year) measure.score(school:, academic_year: year)
end end
scores.all? { |score| !score.meets_student_threshold? } scores.none? { |score| score.meets_student_threshold? }
end end
def score(year_index) def score(academic_year)
measure.student_score(school:, academic_year: academic_years[year_index]) measure.student_score(school:, academic_year:)
end end
def type def type

@ -20,8 +20,8 @@ module Analyze
scores.all? { |score| !score.meets_student_threshold? && !score.meets_teacher_threshold? } scores.all? { |score| !score.meets_student_threshold? && !score.meets_teacher_threshold? }
end end
def score(year_index) def score(academic_year)
combined_score(school:, academic_year: academic_years[year_index]) combined_score(school:, academic_year:)
end end
def type def type

@ -24,8 +24,8 @@ module Analyze
scores.all? { |score| !score.meets_teacher_threshold? } scores.all? { |score| !score.meets_teacher_threshold? }
end end
def score(year_index) def score(academic_year)
measure.teacher_score(school:, academic_year: academic_years[year_index]) measure.teacher_score(school:, academic_year:)
end end
def type def type

@ -3,8 +3,7 @@ module Analyze
module Column module Column
module EllColumn module EllColumn
module ScoreForEll module ScoreForEll
def score(year_index) def score(academic_year)
academic_year = academic_years[year_index]
meets_student_threshold = sufficient_student_responses?(academic_year:) meets_student_threshold = sufficient_student_responses?(academic_year:)
return Score::NIL_SCORE unless meets_student_threshold return Score::NIL_SCORE unless meets_student_threshold

@ -3,8 +3,7 @@ module Analyze
module Column module Column
module GenderColumn module GenderColumn
module ScoreForGender module ScoreForGender
def score(year_index) def score(academic_year)
academic_year = academic_years[year_index]
meets_student_threshold = sufficient_student_responses?(academic_year:) meets_student_threshold = sufficient_student_responses?(academic_year:)
return Score::NIL_SCORE unless meets_student_threshold return Score::NIL_SCORE unless meets_student_threshold

@ -3,8 +3,7 @@ module Analyze
module Column module Column
module Grade module Grade
module ScoreForGrade module ScoreForGrade
def score(year_index) def score(academic_year)
academic_year = academic_years[year_index]
meets_student_threshold = sufficient_student_responses?(academic_year:) meets_student_threshold = sufficient_student_responses?(academic_year:)
return Score::NIL_SCORE unless meets_student_threshold return Score::NIL_SCORE unless meets_student_threshold

@ -20,14 +20,6 @@ module Analyze
@number_of_columns = number_of_columns @number_of_columns = number_of_columns
end end
def academic_year_for_year_index(year_index)
academic_years[year_index]
end
def score(year_index)
measure.score(school:, academic_year: academic_years[year_index]) || 0
end
def bars def bars
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index| @bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
year = yearly_score.year year = yearly_score.year
@ -35,11 +27,11 @@ module Analyze
score: yearly_score.score, score: yearly_score.score,
x_position: bar_x(index), x_position: bar_x(index),
color: bar_color(year)) color: bar_color(year))
end end.reject(&:blank?).select { |bar| bar.score.average&.positive? }
end end
def label def label
%w[All Data] raise NotImplementedError
end end
def basis def basis
@ -47,17 +39,23 @@ module Analyze
end end
def show_irrelevancy_message? def show_irrelevancy_message?
false raise NotImplementedError
end end
def show_insufficient_data_message? def show_insufficient_data_message?
scores = academic_years.map do |year| raise NotImplementedError
measure.score(school:, academic_year: year) end
end
scores.all? do |score| def score(academic_year)
!score.meets_teacher_threshold? && !score.meets_student_threshold? && !score.meets_admin_data_threshold? raise NotImplementedError
end end
def basis
"student surveys"
end
def type
raise NotImplementedError
end end
def column_midpoint def column_midpoint
@ -109,14 +107,6 @@ module Analyze
number_of_columns number_of_columns
end end
def basis
"student surveys"
end
def type
:all_data
end
def show_popover? def show_popover?
%i[student teacher].include? type %i[student teacher].include? type
end end
@ -134,17 +124,6 @@ module Analyze
["survey response", "rate below 25%"] ["survey response", "rate below 25%"]
end end
def sufficient_data?(year_index)
case basis
when "student"
score(year_index).meets_student_threshold
when "teacher"
score(year_index).meets_teacher_threshold
else
true
end
end
def grades def grades
Respondent.by_school_and_year(school:, academic_year: academic_years)&.enrollment_by_grade&.keys Respondent.by_school_and_year(school:, academic_year: academic_years)&.enrollment_by_grade&.keys
end end
@ -153,12 +132,9 @@ module Analyze
YearlyScore = Struct.new(:year, :score) YearlyScore = Struct.new(:year, :score)
def yearly_scores def yearly_scores
yearly_scores = academic_years.each_with_index.map do |year, index| yearly_scores = academic_years.each.map do |year|
YearlyScore.new(year, score(index)) YearlyScore.new(year, score(year))
end end.reject { |year| year.score.nil? || year.score.blank? }
yearly_scores.reject do |yearly_score|
yearly_score.score.blank?
end
end end
def bar_color(year) def bar_color(year)

@ -3,8 +3,7 @@ module Analyze
module Column module Column
module IncomeColumn module IncomeColumn
module ScoreForIncome module ScoreForIncome
def score(year_index) def score(academic_year)
academic_year = academic_years[year_index]
meets_student_threshold = sufficient_student_responses?(academic_year:) meets_student_threshold = sufficient_student_responses?(academic_year:)
return Score::NIL_SCORE unless meets_student_threshold return Score::NIL_SCORE unless meets_student_threshold

@ -2,8 +2,7 @@ module Analyze
module Graph module Graph
module Column module Column
module ScoreForRace module ScoreForRace
def score(year_index) def score(academic_year)
academic_year = academic_years[year_index]
meets_student_threshold = sufficient_student_responses?(academic_year:) meets_student_threshold = sufficient_student_responses?(academic_year:)
return Score::NIL_SCORE unless meets_student_threshold return Score::NIL_SCORE unless meets_student_threshold

@ -3,8 +3,7 @@ module Analyze
module Column module Column
module SpedColumn module SpedColumn
module ScoreForSped module ScoreForSped
def score(year_index) def score(academic_year)
academic_year = academic_years[year_index]
meets_student_threshold = sufficient_student_responses?(academic_year:) meets_student_threshold = sufficient_student_responses?(academic_year:)
return Score::NIL_SCORE unless meets_student_threshold return Score::NIL_SCORE unless meets_student_threshold

@ -1,4 +1,4 @@
require 'rails_helper' require "rails_helper"
RSpec.describe Analyze::Graph::Column::GenderColumn::Unknown, type: :model do RSpec.describe Analyze::Graph::Column::GenderColumn::Unknown, type: :model do
let(:school) { create(:school) } let(:school) { create(:school) }
@ -9,65 +9,65 @@ RSpec.describe Analyze::Graph::Column::GenderColumn::Unknown, type: :model do
let(:number_of_columns) { 1 } let(:number_of_columns) { 1 }
let(:gender) { create(:gender, qualtrics_code: 99) } let(:gender) { create(:gender, qualtrics_code: 99) }
let(:subcategory) { create(:subcategory, subcategory_id: '1A') } let(:subcategory) { create(:subcategory, subcategory_id: "1A") }
let(:measure) { create(:measure, measure_id: '1A-iii', subcategory:) } let(:measure) { create(:measure, measure_id: "1A-iii", subcategory:) }
let(:scale) { create(:student_scale, measure:) } let(:scale) { create(:student_scale, measure:) }
let(:survey_item) { create(:student_survey_item, scale:) } let(:survey_item) { create(:student_survey_item, scale:) }
let(:teacher_scale) { create(:teacher_scale, measure:) } let(:teacher_scale) { create(:teacher_scale, measure:) }
let(:teacher_survey_item) { create(:teacher_survey_item, scale:) } let(:teacher_survey_item) { create(:teacher_survey_item, scale:) }
context 'when no teacher responses exist' do context "when no teacher responses exist" do
context 'when there are insufficient unknown students' do context "when there are insufficient unknown students" do
it 'reports a score of 3 when the average is 3' do it "reports a score of 3 when the average is 3" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).score(0).average).to eq(nil) number_of_columns:).score(academic_year).average).to eq(nil)
end end
it 'reports insufficient data' do it "reports insufficient data" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(false) number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(false)
end end
end end
context 'when there are sufficient unknown students' do context "when there are sufficient unknown students" do
before :each do before :each do
create_list(:survey_item_response, 10, school:, academic_year:, gender:, survey_item:) create_list(:survey_item_response, 10, school:, academic_year:, gender:, survey_item:)
end end
it 'reports a score of 3 when the average is 3' do it "reports a score of 3 when the average is 3" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).score(0).average).to eq(3) number_of_columns:).score(academic_year).average).to eq(3)
end end
it 'reports sufficient data' do it "reports sufficient data" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(true) number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(true)
end end
end end
end end
context 'when teacher responses exist' do context "when teacher responses exist" do
before :each do before :each do
create_list(:survey_item_response, 10, school:, academic_year:, survey_item: teacher_survey_item, likert_score: 5) create_list(:survey_item_response, 10, school:, academic_year:, survey_item: teacher_survey_item, likert_score: 5)
end end
context 'when there are insufficient unknown students' do context "when there are insufficient unknown students" do
it 'reports a score of 3 when the average is 3' do it "reports a score of 3 when the average is 3" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).score(0).average).to eq(nil) number_of_columns:).score(academic_year).average).to eq(nil)
end end
it 'reports insufficient data' do it "reports insufficient data" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(false) number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(false)
end end
end end
context 'when there are sufficient unknown students' do context "when there are sufficient unknown students" do
before :each do before :each do
create_list(:survey_item_response, 10, school:, academic_year:, gender:, survey_item:) create_list(:survey_item_response, 10, school:, academic_year:, gender:, survey_item:)
end end
it 'reports a score of 3 when the average is 3' do it "reports a score of 3 when the average is 3" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).score(0).average).to eq(3) number_of_columns:).score(academic_year).average).to eq(3)
end end
it 'reports sufficient data' do it "reports sufficient data" do
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:, expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(true) number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(true)
end end

@ -73,8 +73,8 @@ describe GroupedBarColumnPresenter do
end end
let(:all_data_presenter) do let(:all_data_presenter) do
GroupedBarColumnPresenter.new measure: measure_composed_of_student_and_teacher_items, school:, academic_years:, Analyze::Graph::Column::AllData.new measure: measure_composed_of_student_and_teacher_items, school:, academic_years:,
position: 0, number_of_columns: 3 position: 0, number_of_columns: 3
end end
before do before do
@ -120,8 +120,8 @@ describe GroupedBarColumnPresenter do
end end
it "returns a score that is an average of the likert scores " do it "returns a score that is an average of the likert scores " do
expect(all_data_presenter.score(0).average).to eq 4.5 expect(all_data_presenter.score(academic_year).average).to eq 4.5
expect(all_data_presenter.score(1).average).to eq nil expect(all_data_presenter.score(another_academic_year).average).to eq nil
expect(all_data_presenter.academic_years[0].range).to be academic_year.range expect(all_data_presenter.academic_years[0].range).to be academic_year.range
expect(all_data_presenter.academic_years[1].range).to be another_academic_year.range expect(all_data_presenter.academic_years[1].range).to be another_academic_year.range
end end
@ -133,8 +133,8 @@ describe GroupedBarColumnPresenter do
academic_year: another_academic_year, likert_score: 3) academic_year: another_academic_year, likert_score: 3)
end end
it "returns independent scores for each year of data" do it "returns independent scores for each year of data" do
expect(all_data_presenter.score(0).average).to eq 4.5 expect(all_data_presenter.score(academic_year).average).to eq 4.5
expect(all_data_presenter.score(1).average).to eq 4 expect(all_data_presenter.score(another_academic_year).average).to eq 4
end end
end end
end end
@ -144,12 +144,8 @@ describe GroupedBarColumnPresenter do
it_behaves_like "measure_name" it_behaves_like "measure_name"
it_behaves_like "column_midpoint" it_behaves_like "column_midpoint"
it "returns an emtpy set of bars" do
expect(student_presenter.bars).to eq []
end
it "returns an emty score" do it "returns an emty score" do
expect(student_presenter.score(year_index).average).to eq nil expect(student_presenter.score(academic_year).average).to eq nil
end end
it "shows the irrelevancy message " do it "shows the irrelevancy message " do

Loading…
Cancel
Save