continue refactoring

pull/1/head
Nelson Jovel 3 years ago
parent b7abf2bc8b
commit 757638f6ca

@ -4,3 +4,10 @@ detectors:
enabled: false
IrresponsibleModule:
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

@ -1,6 +1,6 @@
# frozen_string_literal: true
module ResponseRateCalculator
class ResponseRateCalculator
TEACHER_RATE_THRESHOLD = 25
STUDENT_RATE_THRESHOLD = 25
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)
end
def blank?
average.nil? || average.zero? || average.nan?
end
end

@ -1,8 +1,6 @@
# frozen_string_literal: true
class StudentResponseRateCalculator
include ResponseRateCalculator
class StudentResponseRateCalculator < ResponseRateCalculator
private
def survey_item_count

@ -24,4 +24,8 @@ class SurveyItem < ActiveRecord::Base
scope :short_form_items, lambda {
where(on_short_form: true)
}
def description
DataAvailability.new(survey_item_id, prompt, true)
end
end

@ -1,8 +1,6 @@
# frozen_string_literal: true
class TeacherResponseRateCalculator
include ResponseRateCalculator
class TeacherResponseRateCalculator < ResponseRateCalculator
def survey_item_count
@survey_item_count ||= @subcategory.measures.map do |measure|
measure.teacher_survey_items.reject do |survey_item|

@ -16,14 +16,15 @@ class GroupedBarColumnPresenter
end
def score(year_index)
measure.score(school:, academic_year: academic_years[year_index])
measure.score(school:, academic_year: academic_years[year_index]) || 0
end
def bars
@bars ||= yearly_scores.map.each_with_index do |item, index|
year = item[0]
score = item[1]
AnalyzeBarPresenter.new(measure:, academic_year: year, score:, x_position: bar_x(index),
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
year = yearly_score.year
AnalyzeBarPresenter.new(measure:, academic_year: year,
score: yearly_score.score,
x_position: bar_x(index),
color: bar_color(year))
end
end
@ -82,13 +83,13 @@ class GroupedBarColumnPresenter
private
YearlyScore = Struct.new(:year, :score)
def yearly_scores
yearly_scores = academic_years.each_with_index.map do |year, index|
[year, score(index)]
YearlyScore.new(year, score(index))
end
yearly_scores.reject do |yearly_score|
average = yearly_score[1].average
average.nil? || average.zero? || average.nan?
yearly_score.score.blank?
end
end

@ -25,8 +25,6 @@ class StudentSurveyPresenter < DataItemPresenter
end
def descriptions_and_availability
survey_items.map do |survey_item|
DataAvailability.new(survey_item.survey_item_id, survey_item.prompt, true)
end
survey_items.map(&:description)
end
end

@ -16,13 +16,18 @@ class AdminDataLoader
end
end
private
def self.valid_likert_score(likert_score:)
likert_score >= 1 && likert_score <= 5
end
def self.likert_score(row:)
likert_score = row['LikertScore'] || row['Likert Score'] || row['Likert_Score']
likert_score = likert_score.to_f
likert_score = (row['LikertScore'] || row['Likert Score'] || row['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
end
@ -40,13 +45,17 @@ class AdminDataLoader
end
def self.create_admin_data_value(row:, score:)
admin_data_value = AdminDataValue.new
admin_data_value.likert_score = score
admin_data_value.academic_year = AcademicYear.find_by_range ay(row:)
admin_data_value.school = School.find_by_dese_id dese_id(row:).to_i
admin_data_value.admin_data_item = AdminDataItem.find_by_admin_data_item_id admin_data_item(row:)
admin_data_value.save!
AdminDataValue.create!(likert_score: score,
academic_year: AcademicYear.find_by_range(ay(row:)),
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:)))
end
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

@ -4,10 +4,10 @@ class ResponseRateLoader
def self.reset(schools: School.all, academic_years: AcademicYear.all, subcategories: Subcategory.all)
subcategories.each do |subcategory|
schools.each do |school|
next if rails_env == 'test' && (school != milford)
next if test_env? && (school != milford)
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:)
end
@ -35,13 +35,19 @@ class ResponseRateLoader
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_teacher_threshold: teacher.meets_teacher_threshold?)
end
def self.test_env?
rails_env == 'test'
end
private_class_method :milford
private_class_method :test_year
private_class_method :rails_env
private_class_method :process_response_rate
private_class_method :test_env?
end

@ -12,6 +12,7 @@
ActiveRecord::Schema[7.0].define(version: 2022_06_16_220352) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
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 'with a single year'
before do
create(:survey_item_response, survey_item: student_survey_item_for_composite_measure, school:,
academic_year:, likert_score: 4)
create(:survey_item_response, survey_item: student_survey_item_for_composite_measure, school:,
academic_year:, likert_score: 5)
create(:survey_item_response,
survey_item: student_survey_item_for_composite_measure,
school:,
academic_year:,
likert_score: 4)
create(:survey_item_response,
survey_item: student_survey_item_for_composite_measure, school:,
academic_year:,
likert_score: 5)
end
it 'returns a score that is an average of the likert scores ' do
@ -136,10 +141,6 @@ describe GroupedBarColumnPresenter do
end
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
it_behaves_like 'measure_name'
it_behaves_like 'column_midpoint'

Loading…
Cancel
Save