You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/services/response_rate_loader.rb

30 lines
1.1 KiB

# frozen_string_literal: true
class ResponseRateLoader
def self.reset(schools: School.all, academic_years: AcademicYear.all, subcategories: Subcategory.all)
milford = School.find_by_slug 'milford-high-school'
test_year = AcademicYear.find_by_range '2020-21'
subcategories.each do |subcategory|
schools.each do |school|
next if ENV['RAILS_ENV'] == 'test' && !(school == milford)
academic_years.each do |academic_year|
next if ENV['RAILS_ENV'] == 'test' && !(academic_year == test_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.student_response_rate = student.rate
response_rate.teacher_response_rate = teacher.rate
response_rate.meets_student_threshold = student.meets_student_threshold?
response_rate.meets_teacher_threshold = teacher.meets_teacher_threshold?
response_rate.save
end
end
end
end
end