mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 13:38:18 -08:00
continue refactoring
This commit is contained in:
parent
b7abf2bc8b
commit
757638f6ca
13 changed files with 64 additions and 38 deletions
|
|
@ -4,3 +4,10 @@ detectors:
|
||||||
enabled: false
|
enabled: false
|
||||||
IrresponsibleModule:
|
IrresponsibleModule:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
exclude_paths:
|
||||||
|
- spec
|
||||||
|
- app/views/legacy
|
||||||
|
- app/controllers/legacy
|
||||||
|
- app/models/legacy
|
||||||
|
- db/migrate
|
||||||
|
- config
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,3 @@ Style/Documentation:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ResponseRateCalculator
|
class ResponseRateCalculator
|
||||||
TEACHER_RATE_THRESHOLD = 25
|
TEACHER_RATE_THRESHOLD = 25
|
||||||
STUDENT_RATE_THRESHOLD = 25
|
STUDENT_RATE_THRESHOLD = 25
|
||||||
attr_reader :subcategory, :school, :academic_year
|
attr_reader :subcategory, :school, :academic_year
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,8 @@ class Score < Struct.new(:average, :meets_teacher_threshold?, :meets_student_thr
|
||||||
|
|
||||||
average.between?(zone.low_benchmark, zone.high_benchmark)
|
average.between?(zone.low_benchmark, zone.high_benchmark)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blank?
|
||||||
|
average.nil? || average.zero? || average.nan?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class StudentResponseRateCalculator
|
class StudentResponseRateCalculator < ResponseRateCalculator
|
||||||
include ResponseRateCalculator
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def survey_item_count
|
def survey_item_count
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,8 @@ class SurveyItem < ActiveRecord::Base
|
||||||
scope :short_form_items, lambda {
|
scope :short_form_items, lambda {
|
||||||
where(on_short_form: true)
|
where(on_short_form: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def description
|
||||||
|
DataAvailability.new(survey_item_id, prompt, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class TeacherResponseRateCalculator
|
class TeacherResponseRateCalculator < ResponseRateCalculator
|
||||||
include ResponseRateCalculator
|
|
||||||
|
|
||||||
def survey_item_count
|
def survey_item_count
|
||||||
@survey_item_count ||= @subcategory.measures.map do |measure|
|
@survey_item_count ||= @subcategory.measures.map do |measure|
|
||||||
measure.teacher_survey_items.reject do |survey_item|
|
measure.teacher_survey_items.reject do |survey_item|
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,15 @@ class GroupedBarColumnPresenter
|
||||||
end
|
end
|
||||||
|
|
||||||
def score(year_index)
|
def score(year_index)
|
||||||
measure.score(school:, academic_year: academic_years[year_index])
|
measure.score(school:, academic_year: academic_years[year_index]) || 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def bars
|
def bars
|
||||||
@bars ||= yearly_scores.map.each_with_index do |item, index|
|
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
|
||||||
year = item[0]
|
year = yearly_score.year
|
||||||
score = item[1]
|
AnalyzeBarPresenter.new(measure:, academic_year: year,
|
||||||
AnalyzeBarPresenter.new(measure:, academic_year: year, score:, x_position: bar_x(index),
|
score: yearly_score.score,
|
||||||
|
x_position: bar_x(index),
|
||||||
color: bar_color(year))
|
color: bar_color(year))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -82,13 +83,13 @@ class GroupedBarColumnPresenter
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
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_with_index.map do |year, index|
|
||||||
[year, score(index)]
|
YearlyScore.new(year, score(index))
|
||||||
end
|
end
|
||||||
yearly_scores.reject do |yearly_score|
|
yearly_scores.reject do |yearly_score|
|
||||||
average = yearly_score[1].average
|
yearly_score.score.blank?
|
||||||
average.nil? || average.zero? || average.nan?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ class StudentSurveyPresenter < DataItemPresenter
|
||||||
end
|
end
|
||||||
|
|
||||||
def descriptions_and_availability
|
def descriptions_and_availability
|
||||||
survey_items.map do |survey_item|
|
survey_items.map(&:description)
|
||||||
DataAvailability.new(survey_item.survey_item_id, survey_item.prompt, true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,18 @@ class AdminDataLoader
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def self.valid_likert_score(likert_score:)
|
def self.valid_likert_score(likert_score:)
|
||||||
likert_score >= 1 && likert_score <= 5
|
likert_score >= 1 && likert_score <= 5
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.likert_score(row:)
|
def self.likert_score(row:)
|
||||||
likert_score = row['LikertScore'] || row['Likert Score'] || row['Likert_Score']
|
likert_score = (row['LikertScore'] || row['Likert Score'] || row['Likert_Score']).to_f
|
||||||
likert_score = likert_score.to_f
|
round_up_to_one(likert_score:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.round_up_to_one(likert_score:)
|
||||||
likert_score = 1 if likert_score.positive? && likert_score < 1
|
likert_score = 1 if likert_score.positive? && likert_score < 1
|
||||||
likert_score
|
likert_score
|
||||||
end
|
end
|
||||||
|
|
@ -40,13 +45,17 @@ class AdminDataLoader
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create_admin_data_value(row:, score:)
|
def self.create_admin_data_value(row:, score:)
|
||||||
admin_data_value = AdminDataValue.new
|
AdminDataValue.create!(likert_score: score,
|
||||||
admin_data_value.likert_score = score
|
academic_year: AcademicYear.find_by_range(ay(row:)),
|
||||||
admin_data_value.academic_year = AcademicYear.find_by_range ay(row:)
|
school: School.find_by_dese_id(dese_id(row:).to_i),
|
||||||
admin_data_value.school = School.find_by_dese_id dese_id(row:).to_i
|
admin_data_item: AdminDataItem.find_by_admin_data_item_id(admin_data_item(row:)))
|
||||||
admin_data_value.admin_data_item = AdminDataItem.find_by_admin_data_item_id admin_data_item(row:)
|
|
||||||
admin_data_value.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private_class_method :valid_likert_score
|
private_class_method :valid_likert_score
|
||||||
|
private_class_method :likert_score
|
||||||
|
private_class_method :round_up_to_one
|
||||||
|
private_class_method :ay
|
||||||
|
private_class_method :dese_id
|
||||||
|
private_class_method :admin_data_item
|
||||||
|
private_class_method :create_admin_data_value
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ class ResponseRateLoader
|
||||||
def self.reset(schools: School.all, academic_years: AcademicYear.all, subcategories: Subcategory.all)
|
def self.reset(schools: School.all, academic_years: AcademicYear.all, subcategories: Subcategory.all)
|
||||||
subcategories.each do |subcategory|
|
subcategories.each do |subcategory|
|
||||||
schools.each do |school|
|
schools.each do |school|
|
||||||
next if rails_env == 'test' && (school != milford)
|
next if test_env? && (school != milford)
|
||||||
|
|
||||||
academic_years.each do |academic_year|
|
academic_years.each do |academic_year|
|
||||||
next if rails_env == 'test' && (academic_year != test_year)
|
next if test_env? && (academic_year != test_year)
|
||||||
|
|
||||||
process_response_rate(subcategory:, school:, academic_year:)
|
process_response_rate(subcategory:, school:, academic_year:)
|
||||||
end
|
end
|
||||||
|
|
@ -35,13 +35,19 @@ class ResponseRateLoader
|
||||||
|
|
||||||
response_rate = ResponseRate.find_or_create_by!(subcategory:, school:, academic_year:)
|
response_rate = ResponseRate.find_or_create_by!(subcategory:, school:, academic_year:)
|
||||||
|
|
||||||
response_rate.update!(student_response_rate: student.rate, teacher_response_rate: teacher.rate,
|
response_rate.update!(student_response_rate: student.rate,
|
||||||
|
teacher_response_rate: teacher.rate,
|
||||||
meets_student_threshold: student.meets_student_threshold?,
|
meets_student_threshold: student.meets_student_threshold?,
|
||||||
meets_teacher_threshold: teacher.meets_teacher_threshold?)
|
meets_teacher_threshold: teacher.meets_teacher_threshold?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.test_env?
|
||||||
|
rails_env == 'test'
|
||||||
|
end
|
||||||
|
|
||||||
private_class_method :milford
|
private_class_method :milford
|
||||||
private_class_method :test_year
|
private_class_method :test_year
|
||||||
private_class_method :rails_env
|
private_class_method :rails_env
|
||||||
private_class_method :process_response_rate
|
private_class_method :process_response_rate
|
||||||
|
private_class_method :test_env?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2022_06_16_220352) do
|
ActiveRecord::Schema[7.0].define(version: 2022_06_16_220352) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
|
enable_extension "pg_stat_statements"
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
create_table "academic_years", id: :serial, force: :cascade do |t|
|
create_table "academic_years", id: :serial, force: :cascade do |t|
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,15 @@ describe GroupedBarColumnPresenter do
|
||||||
context 'for a grouped column presenter with both student and teacher responses' do
|
context 'for a grouped column presenter with both student and teacher responses' do
|
||||||
context 'with a single year'
|
context 'with a single year'
|
||||||
before do
|
before do
|
||||||
create(:survey_item_response, survey_item: student_survey_item_for_composite_measure, school:,
|
create(:survey_item_response,
|
||||||
academic_year:, likert_score: 4)
|
survey_item: student_survey_item_for_composite_measure,
|
||||||
create(:survey_item_response, survey_item: student_survey_item_for_composite_measure, school:,
|
school:,
|
||||||
academic_year:, likert_score: 5)
|
academic_year:,
|
||||||
|
likert_score: 4)
|
||||||
|
create(:survey_item_response,
|
||||||
|
survey_item: student_survey_item_for_composite_measure, school:,
|
||||||
|
academic_year:,
|
||||||
|
likert_score: 5)
|
||||||
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
|
||||||
|
|
@ -136,10 +141,6 @@ describe GroupedBarColumnPresenter do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a measure is based on student survey items' do
|
context 'when a measure is based on student survey items' do
|
||||||
before do
|
|
||||||
year_index = academic_years.find_index(academic_year)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when there is insufficient data to show a score' do
|
context 'when there is insufficient data to show a score' do
|
||||||
it_behaves_like 'measure_name'
|
it_behaves_like 'measure_name'
|
||||||
it_behaves_like 'column_midpoint'
|
it_behaves_like 'column_midpoint'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue