fix: correct a problem where survey items with insufficient responses were contributing to the response rate calculation

rpp-main
Nelson Jovel 2 years ago
parent 946b0833fd
commit 978b69b095

@ -43,8 +43,12 @@ class StudentResponseRateCalculator < ResponseRateCalculator
quarter_of_grade = enrollment_by_grade[grade] / 4
threshold = threshold > quarter_of_grade ? quarter_of_grade : threshold
si = SurveyItemResponse.student_survey_items_with_sufficient_responses_by_grade(school:, academic_year:,
threshold:)
si = SurveyItemResponse.student_survey_items_with_sufficient_responses_by_grade(school:,
academic_year:)
si = si.reject do |_key, value|
value < threshold
end
ssi = @subcategory.survey_items.student_survey_items.map(&:id)
grade_array = Array.new(ssi.length, grade)

@ -70,13 +70,12 @@ class SurveyItemResponse < ActiveRecord::Base
@teacher_survey_items_with_sufficient_responses[[school, academic_year]]
end
def self.student_survey_items_with_sufficient_responses_by_grade(school:, academic_year:, threshold:)
def self.student_survey_items_with_sufficient_responses_by_grade(school:, academic_year:)
@student_survey_items_with_sufficient_responses_by_grade ||= Hash.new do |memo, (school, academic_year)|
hash = SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
.student_survey_items
.where("survey_item_responses.school": school, "survey_item_responses.academic_year": academic_year)
.group(:grade, :id)
.having("count(*) >= #{threshold}")
.count
memo[[school, academic_year]] = hash
end

Loading…
Cancel
Save