The overall response rate is artifically lower because we are including the number of all the students at the school, not just the number of students that took the survey. Updated the overall response rate presenter to return the count of only the grades that took the student survey.

This commit is contained in:
rebuilt 2023-05-23 20:13:19 -07:00
parent 0a5500ecc9
commit f6f56367fc
2 changed files with 135 additions and 22 deletions

View file

@ -14,6 +14,8 @@ class ResponseRatePresenter
end
def percentage
return 0 if respondents_count.zero?
cap_at_100(actual_count.to_f / respondents_count.to_f * 100).round
end
@ -37,9 +39,30 @@ class ResponseRatePresenter
end
def respondents_count
respondents = Respondent.find_by(school:, academic_year:)
count = respondents.total_students if focus == :student
return 0 if respondents.nil?
count = enrollment if focus == :student
count = respondents.total_teachers if focus == :teacher
count
end
def enrollment
SurveyItemResponse.where(school:, academic_year:, grade: grades,
survey_item: SurveyItem.student_survey_items)
.select(:grade)
.distinct
.pluck(:grade)
.reject(&:nil?)
.map do |grade|
respondents.counts_by_grade[grade]
end.sum.to_f
end
def respondents
Respondent.find_by(school:, academic_year:)
end
def grades
respondents.counts_by_grade.keys
end
end