sqm-dashboards/app/models/subcategory.rb
rebuilt 128748addd Update logic for calculating student response rate. Remove references
to survey table.  We no longer check or keep track of the survey type.
Instead we look in the database to see if a survey item has at least 10
responses.  If it does, that survey item was presented to the respondent
and we count it, and all responses when calculating the response rate.

Remove response rate timestamp from caching logic because we no longer
add the response rate to the database. All response rates are calculated
on the fly

Update three_b_two scraper to use teacher only numbers

swap over to using https://profiles.doe.mass.edu/statereport/gradesubjectstaffing.aspx as the source of staffing information
2023-04-18 13:59:29 -07:00

28 lines
1.1 KiB
Ruby

# frozen_string_literal: true
class Subcategory < ActiveRecord::Base
belongs_to :category, counter_cache: true
has_many :measures
has_many :survey_items, through: :measures
def score(school:, academic_year:)
scores = measures.map do |measure|
measure.score(school:, academic_year:).average
end
scores = scores.reject(&:nil?)
scores.average
end
def response_rate(school:, academic_year:)
@response_rate ||= Hash.new do |memo, (school, academic_year)|
student = StudentResponseRateCalculator.new(subcategory: self, school:, academic_year:)
teacher = TeacherResponseRateCalculator.new(subcategory: self, school:, academic_year:)
memo[[school, academic_year]] = ResponseRate.new(school:, academic_year:, subcategory: self, 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
@response_rate[[school, academic_year]]
end
end