mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-08 23:18:18 -07:00
fix: correct a problem where survey items with insufficient responses were contributing to the response rate calculation
This commit is contained in:
parent
cf9dd9042d
commit
ec5c1bd1ef
3 changed files with 70 additions and 55 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue