mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
chore: refactor analyze page
This commit is contained in:
parent
ccb04511bf
commit
3b3bb52523
15 changed files with 99 additions and 96 deletions
|
|
@ -14,7 +14,7 @@ module Analyze
|
|||
end
|
||||
|
||||
def columns
|
||||
[AllStudent, AllTeacher, AllAdmin, GroupedBarColumnPresenter]
|
||||
[AllStudent, AllTeacher, AllAdmin, Analyze::Graph::Column::AllData]
|
||||
end
|
||||
|
||||
def source
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ module Analyze
|
|||
["data not", "available"]
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.admin_score(school:, academic_year: academic_years[year_index])
|
||||
def score(academic_year)
|
||||
measure.admin_score(school:, academic_year:)
|
||||
end
|
||||
|
||||
def type
|
||||
|
|
|
|||
37
app/presenters/analyze/graph/column/all_data.rb
Normal file
37
app/presenters/analyze/graph/column/all_data.rb
Normal file
|
|
@ -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)
|
||||
end
|
||||
|
||||
scores.all? { |score| !score.meets_student_threshold? }
|
||||
scores.none? { |score| score.meets_student_threshold? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.student_score(school:, academic_year: academic_years[year_index])
|
||||
def score(academic_year)
|
||||
measure.student_score(school:, academic_year:)
|
||||
end
|
||||
|
||||
def type
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ module Analyze
|
|||
scores.all? { |score| !score.meets_student_threshold? && !score.meets_teacher_threshold? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
combined_score(school:, academic_year: academic_years[year_index])
|
||||
def score(academic_year)
|
||||
combined_score(school:, academic_year:)
|
||||
end
|
||||
|
||||
def type
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ module Analyze
|
|||
scores.all? { |score| !score.meets_teacher_threshold? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.teacher_score(school:, academic_year: academic_years[year_index])
|
||||
def score(academic_year)
|
||||
measure.teacher_score(school:, academic_year:)
|
||||
end
|
||||
|
||||
def type
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ module Analyze
|
|||
module Column
|
||||
module EllColumn
|
||||
module ScoreForEll
|
||||
def score(year_index)
|
||||
academic_year = academic_years[year_index]
|
||||
def score(academic_year)
|
||||
meets_student_threshold = sufficient_student_responses?(academic_year:)
|
||||
return Score::NIL_SCORE unless meets_student_threshold
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ module Analyze
|
|||
module Column
|
||||
module GenderColumn
|
||||
module ScoreForGender
|
||||
def score(year_index)
|
||||
academic_year = academic_years[year_index]
|
||||
def score(academic_year)
|
||||
meets_student_threshold = sufficient_student_responses?(academic_year:)
|
||||
return Score::NIL_SCORE unless meets_student_threshold
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ module Analyze
|
|||
module Column
|
||||
module Grade
|
||||
module ScoreForGrade
|
||||
def score(year_index)
|
||||
academic_year = academic_years[year_index]
|
||||
def score(academic_year)
|
||||
meets_student_threshold = sufficient_student_responses?(academic_year:)
|
||||
return Score::NIL_SCORE unless meets_student_threshold
|
||||
|
||||
|
|
|
|||
|
|
@ -20,14 +20,6 @@ module Analyze
|
|||
@number_of_columns = number_of_columns
|
||||
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
|
||||
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
|
||||
year = yearly_score.year
|
||||
|
|
@ -35,25 +27,31 @@ module Analyze
|
|||
score: yearly_score.score,
|
||||
x_position: bar_x(index),
|
||||
color: bar_color(year))
|
||||
end
|
||||
end.reject(&:blank?).select { |bar| bar.score.average&.positive? }
|
||||
end
|
||||
|
||||
def label
|
||||
%w[All Data]
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
false
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def show_insufficient_data_message?
|
||||
scores = academic_years.map do |year|
|
||||
measure.score(school:, academic_year: year)
|
||||
end
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
scores.all? do |score|
|
||||
!score.meets_teacher_threshold? && !score.meets_student_threshold? && !score.meets_admin_data_threshold?
|
||||
end
|
||||
def score(academic_year)
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def basis
|
||||
"student surveys"
|
||||
end
|
||||
|
||||
def type
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def column_midpoint
|
||||
|
|
@ -105,14 +103,6 @@ module Analyze
|
|||
number_of_columns
|
||||
end
|
||||
|
||||
def basis
|
||||
"student surveys"
|
||||
end
|
||||
|
||||
def type
|
||||
:all_data
|
||||
end
|
||||
|
||||
def show_popover?
|
||||
%i[student teacher].include? type
|
||||
end
|
||||
|
|
@ -130,17 +120,6 @@ module Analyze
|
|||
["survey response", "rate below 25%"]
|
||||
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
|
||||
Respondent.by_school_and_year(school:, academic_year: academic_years)&.enrollment_by_grade&.keys
|
||||
end
|
||||
|
|
@ -149,12 +128,9 @@ module Analyze
|
|||
|
||||
YearlyScore = Struct.new(:year, :score)
|
||||
def yearly_scores
|
||||
yearly_scores = academic_years.each_with_index.map do |year, index|
|
||||
YearlyScore.new(year, score(index))
|
||||
end
|
||||
yearly_scores.reject do |yearly_score|
|
||||
yearly_score.score.blank?
|
||||
end
|
||||
yearly_scores = academic_years.each.map do |year|
|
||||
YearlyScore.new(year, score(year))
|
||||
end.reject { |year| year.score.nil? || year.score.blank? }
|
||||
end
|
||||
|
||||
def bar_color(year)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ module Analyze
|
|||
module Column
|
||||
module IncomeColumn
|
||||
module ScoreForIncome
|
||||
def score(year_index)
|
||||
academic_year = academic_years[year_index]
|
||||
def score(academic_year)
|
||||
meets_student_threshold = sufficient_student_responses?(academic_year:)
|
||||
return Score::NIL_SCORE unless meets_student_threshold
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ module Analyze
|
|||
module Graph
|
||||
module Column
|
||||
module ScoreForRace
|
||||
def score(year_index)
|
||||
academic_year = academic_years[year_index]
|
||||
def score(academic_year)
|
||||
meets_student_threshold = sufficient_student_responses?(academic_year:)
|
||||
return Score::NIL_SCORE unless meets_student_threshold
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ module Analyze
|
|||
module Column
|
||||
module SpedColumn
|
||||
module ScoreForSped
|
||||
def score(year_index)
|
||||
academic_year = academic_years[year_index]
|
||||
def score(academic_year)
|
||||
meets_student_threshold = sufficient_student_responses?(academic_year:)
|
||||
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
|
||||
let(:school) { create(:school) }
|
||||
|
|
@ -9,65 +9,65 @@ RSpec.describe Analyze::Graph::Column::GenderColumn::Unknown, type: :model do
|
|||
let(:number_of_columns) { 1 }
|
||||
let(:gender) { create(:gender, qualtrics_code: 99) }
|
||||
|
||||
let(:subcategory) { create(:subcategory, subcategory_id: '1A') }
|
||||
let(:measure) { create(:measure, measure_id: '1A-iii', subcategory:) }
|
||||
let(:subcategory) { create(:subcategory, subcategory_id: "1A") }
|
||||
let(:measure) { create(:measure, measure_id: "1A-iii", subcategory:) }
|
||||
let(:scale) { create(:student_scale, measure:) }
|
||||
let(:survey_item) { create(:student_survey_item, scale:) }
|
||||
let(:teacher_scale) { create(:teacher_scale, measure:) }
|
||||
let(:teacher_survey_item) { create(:teacher_survey_item, scale:) }
|
||||
|
||||
context 'when no teacher responses exist' do
|
||||
context 'when there are insufficient unknown students' do
|
||||
it 'reports a score of 3 when the average is 3' do
|
||||
context "when no teacher responses exist" do
|
||||
context "when there are insufficient unknown students" 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:,
|
||||
number_of_columns:).score(0).average).to eq(nil)
|
||||
number_of_columns:).score(academic_year).average).to eq(nil)
|
||||
end
|
||||
it 'reports insufficient data' do
|
||||
it "reports insufficient data" do
|
||||
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
|
||||
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(false)
|
||||
end
|
||||
end
|
||||
context 'when there are sufficient unknown students' do
|
||||
context "when there are sufficient unknown students" do
|
||||
before :each do
|
||||
create_list(:survey_item_response, 10, school:, academic_year:, gender:, survey_item:)
|
||||
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:,
|
||||
number_of_columns:).score(0).average).to eq(3)
|
||||
number_of_columns:).score(academic_year).average).to eq(3)
|
||||
end
|
||||
|
||||
it 'reports sufficient data' do
|
||||
it "reports sufficient data" do
|
||||
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
|
||||
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when teacher responses exist' do
|
||||
context "when teacher responses exist" do
|
||||
before :each do
|
||||
create_list(:survey_item_response, 10, school:, academic_year:, survey_item: teacher_survey_item, likert_score: 5)
|
||||
end
|
||||
|
||||
context 'when there are insufficient unknown students' do
|
||||
it 'reports a score of 3 when the average is 3' do
|
||||
context "when there are insufficient unknown students" 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:,
|
||||
number_of_columns:).score(0).average).to eq(nil)
|
||||
number_of_columns:).score(academic_year).average).to eq(nil)
|
||||
end
|
||||
it 'reports insufficient data' do
|
||||
it "reports insufficient data" do
|
||||
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
|
||||
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(false)
|
||||
end
|
||||
end
|
||||
context 'when there are sufficient unknown students' do
|
||||
context "when there are sufficient unknown students" do
|
||||
before :each do
|
||||
create_list(:survey_item_response, 10, school:, academic_year:, gender:, survey_item:)
|
||||
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:,
|
||||
number_of_columns:).score(0).average).to eq(3)
|
||||
number_of_columns:).score(academic_year).average).to eq(3)
|
||||
end
|
||||
|
||||
it 'reports sufficient data' do
|
||||
it "reports sufficient data" do
|
||||
expect(Analyze::Graph::Column::GenderColumn::Unknown.new(school:, academic_years:, position:, measure:,
|
||||
number_of_columns:).sufficient_student_responses?(academic_year:)).to eq(true)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ describe GroupedBarColumnPresenter do
|
|||
end
|
||||
|
||||
let(:all_data_presenter) do
|
||||
GroupedBarColumnPresenter.new measure: measure_composed_of_student_and_teacher_items, school:, academic_years:,
|
||||
position: 0, number_of_columns: 3
|
||||
Analyze::Graph::Column::AllData.new measure: measure_composed_of_student_and_teacher_items, school:, academic_years:,
|
||||
position: 0, number_of_columns: 3
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
@ -120,8 +120,8 @@ describe GroupedBarColumnPresenter do
|
|||
end
|
||||
|
||||
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(1).average).to eq nil
|
||||
expect(all_data_presenter.score(academic_year).average).to eq 4.5
|
||||
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[1].range).to be another_academic_year.range
|
||||
end
|
||||
|
|
@ -133,8 +133,8 @@ describe GroupedBarColumnPresenter do
|
|||
academic_year: another_academic_year, likert_score: 3)
|
||||
end
|
||||
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(1).average).to eq 4
|
||||
expect(all_data_presenter.score(academic_year).average).to eq 4.5
|
||||
expect(all_data_presenter.score(another_academic_year).average).to eq 4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -144,12 +144,8 @@ describe GroupedBarColumnPresenter do
|
|||
it_behaves_like "measure_name"
|
||||
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
|
||||
expect(student_presenter.score(year_index).average).to eq nil
|
||||
expect(student_presenter.score(academic_year).average).to eq nil
|
||||
end
|
||||
|
||||
it "shows the irrelevancy message " do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue