diff --git a/app/models/student_response_rate_calculator.rb b/app/models/student_response_rate_calculator.rb index cd05551a..03a75f34 100644 --- a/app/models/student_response_rate_calculator.rb +++ b/app/models/student_response_rate_calculator.rb @@ -18,6 +18,9 @@ class StudentResponseRateCalculator < ResponseRateCalculator # # All methods below will need to specify a grade + grades_with_sufficient_responses.map do |grade| + puts "Grade: #{grade}" + end (average_responses_per_survey_item / total_possible_responses.to_f * 100).round end @@ -52,4 +55,15 @@ class StudentResponseRateCalculator < ResponseRateCalculator total_responses.total_students end end + + def grades_with_sufficient_responses + SurveyItemResponse.where(school:, academic_year:, + survey_item: subcategory.survey_items.student_survey_items).where.not(grade: nil) + .group(:grade) + .select(:response_id) + .distinct(:response_id) + .count.reject do |_key, value| + value < 10 + end.keys + end end diff --git a/spec/models/response_rate_calculator_spec.rb b/spec/models/response_rate_calculator_spec.rb index 6c2a9cf8..f05ba7b5 100644 --- a/spec/models/response_rate_calculator_spec.rb +++ b/spec/models/response_rate_calculator_spec.rb @@ -18,6 +18,11 @@ describe ResponseRateCalculator, type: :model do let(:insufficient_student_survey_item_1) { create(:student_survey_item, scale: sufficient_scale_1) } let(:sufficient_student_survey_item_2) { create(:student_survey_item, scale: sufficient_scale_2) } + context '.grades_with_sufficient_responses' do + pending 'implement this' + before :each do + end + end context 'when a students take a regular survey' do context 'when the average number of student responses per question in a subcategory is equal to the student response threshold' do before :each do