chore: rename counts_by_grade to enrollment_by_grade for clarity

mciea-main
Nelson Jovel 2 years ago
parent 1d0bac126b
commit 0359dae88a

@ -31,7 +31,7 @@ module Report
row = [response_rate, subcategory, school, academic_year] row = [response_rate, subcategory, school, academic_year]
all_grades = respondents.counts_by_grade.keys all_grades = respondents.enrollment_by_grade.keys
grades = "#{all_grades.first}-#{all_grades.last}" grades = "#{all_grades.first}-#{all_grades.last}"
mutex.synchronize do mutex.synchronize do
data << [school.district.name, data << [school.district.name,

@ -6,8 +6,8 @@ class Respondent < ApplicationRecord
validates :school, uniqueness: { scope: :academic_year } validates :school, uniqueness: { scope: :academic_year }
def counts_by_grade def enrollment_by_grade
@counts_by_grade ||= {}.tap do |row| @enrollment_by_grade ||= {}.tap do |row|
attributes = %i[pk k one two three four five six seven eight nine ten eleven twelve] attributes = %i[pk k one two three four five six seven eight nine ten eleven twelve]
grades = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] grades = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
attributes.zip(grades).each do |attribute, grade| attributes.zip(grades).each do |attribute, grade|

@ -21,6 +21,6 @@ class School < ApplicationRecord
end end
def grades(academic_year:) def grades(academic_year:)
Respondent.find_by(school: self, academic_year:)&.counts_by_grade&.keys || (-1..12).to_a Respondent.find_by(school: self, academic_year:)&.enrollment_by_grade&.keys || (-1..12).to_a
end end
end end

@ -30,11 +30,11 @@ class StudentResponseRateCalculator < ResponseRateCalculator
end end
def enrollment_by_grade def enrollment_by_grade
@enrollment_by_grade ||= respondents.counts_by_grade @enrollment_by_grade ||= respondents.enrollment_by_grade
end end
def total_enrollment def total_enrollment
respondents.counts_by_grade.sum respondents.enrollment_by_grade.sum
end end
def survey_items_have_sufficient_responses? def survey_items_have_sufficient_responses?

@ -146,7 +146,7 @@ module Analyze
end end
def grades(year_index) def grades(year_index)
Respondent.find_by(school:, academic_year: academic_years[year_index]).counts_by_grade.keys Respondent.find_by(school:, academic_year: academic_years[year_index]).enrollment_by_grade.keys
end end
private private

@ -86,7 +86,7 @@ class ResponseRatePresenter
.pluck(:grade) .pluck(:grade)
.reject(&:nil?) .reject(&:nil?)
.map do |grade| .map do |grade|
respondents.counts_by_grade[grade] respondents.enrollment_by_grade[grade]
end.sum.to_f end.sum.to_f
end end
@ -95,6 +95,6 @@ class ResponseRatePresenter
end end
def grades def grades
respondents.counts_by_grade.keys respondents.enrollment_by_grade.keys
end end
end end

@ -288,8 +288,8 @@ class SurveyItemValues
return true if respondent_type == :teacher return true if respondent_type == :teacher
respondents = Respondent.where(school:, academic_year:).first respondents = Respondent.where(school:, academic_year:).first
if respondents.present? && respondents.counts_by_grade[grade].present? if respondents.present? && respondents.enrollment_by_grade[grade].present?
enrollment = respondents.counts_by_grade[grade] enrollment = respondents.enrollment_by_grade[grade]
end end
return false if enrollment.nil? return false if enrollment.nil?

@ -8,9 +8,9 @@ RSpec.describe Respondent, type: :model do
context 'when the student respondents include one or more counts for the number of respondents' do context 'when the student respondents include one or more counts for the number of respondents' do
it 'returns a hash with only the grades that have a non-zero count of students' do it 'returns a hash with only the grades that have a non-zero count of students' do
expect(single_grade_of_respondents.one).to eq(10) expect(single_grade_of_respondents.one).to eq(10)
expect(single_grade_of_respondents.counts_by_grade).to eq({ 1 => 10 }) expect(single_grade_of_respondents.enrollment_by_grade).to eq({ 1 => 10 })
expect(two_grades_of_respondents.counts_by_grade).to eq({ -1 => 10, 0 => 5 }) expect(two_grades_of_respondents.enrollment_by_grade).to eq({ -1 => 10, 0 => 5 })
expect(three_grades_of_respondents.counts_by_grade).to eq({ 1 => 10, 2 => 5, 12 => 6 }) expect(three_grades_of_respondents.enrollment_by_grade).to eq({ 1 => 10, 2 => 5, 12 => 6 })
end end
end end
end end

Loading…
Cancel
Save