sqm-dashboards/app/models/response_rate_calculator.rb
rebuilt 65b8599c6e 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-08 10:59:48 -07:00

45 lines
1,015 B
Ruby

# frozen_string_literal: true
class ResponseRateCalculator
TEACHER_RATE_THRESHOLD = 25
STUDENT_RATE_THRESHOLD = 25
attr_reader :subcategory, :school, :academic_year
def initialize(subcategory:, school:, academic_year:)
@subcategory = subcategory
@school = school
@academic_year = academic_year
end
def rate
return 100 if population_data_unavailable?
return 0 unless survey_items_have_sufficient_responses?
return 0 unless total_possible_responses.positive?
cap_at_one_hundred(raw_response_rate)
end
def meets_student_threshold?
rate >= STUDENT_RATE_THRESHOLD
end
def meets_teacher_threshold?
rate >= TEACHER_RATE_THRESHOLD
end
private
def cap_at_one_hundred(response_rate)
response_rate > 100 ? 100 : response_rate
end
def average_responses_per_survey_item
response_count / survey_item_count.to_f
end
def population_data_unavailable?
Respondent.where(school: @school, academic_year: @academic_year).count.zero?
end
end