mirror of
https://github.com/edcommonwealth/Dashboard.git
synced 2026-03-07 13:38:12 -08:00
55 lines
1.7 KiB
Ruby
55 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Dashboard
|
|
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 test_env? && (school != milford)
|
|
|
|
academic_years.each do |academic_year|
|
|
next if test_env? && (academic_year != test_year)
|
|
|
|
process_response_rate(subcategory:, school:, academic_year:)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def self.milford
|
|
School.find_by_slug "milford-high-school"
|
|
end
|
|
|
|
def self.test_year
|
|
AcademicYear.find_by_range "2020-21"
|
|
end
|
|
|
|
def self.rails_env
|
|
@rails_env ||= ENV["RAILS_ENV"]
|
|
end
|
|
|
|
def self.process_response_rate(subcategory:, school:, academic_year:)
|
|
student = StudentResponseRateCalculator.new(subcategory:, school:, academic_year:)
|
|
teacher = TeacherResponseRateCalculator.new(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,
|
|
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
|
|
end
|