Merge branch 'rpp-response-rate' to bring in changes to test files

This commit is contained in:
rebuilt 2023-03-15 15:00:25 -07:00
commit 4c4ccc01cc
47 changed files with 48818 additions and 1354 deletions

View file

@ -14,4 +14,8 @@ class District < ApplicationRecord
before_save do
self.slug ||= name.parameterize
end
def self.boston
District.find_by_name('Boston')
end
end

View file

@ -3,4 +3,6 @@
class Respondent < ApplicationRecord
belongs_to :school
belongs_to :academic_year
validates :school, uniqueness: { scope: :academic_year }
end

View file

@ -39,10 +39,6 @@ class ResponseRateCalculator
Survey.find_by(school:, academic_year:)
end
def raw_response_rate
(average_responses_per_survey_item / total_possible_responses.to_f * 100).round
end
def average_responses_per_survey_item
response_count / survey_item_count.to_f
end

View file

@ -3,6 +3,27 @@
class StudentResponseRateCalculator < ResponseRateCalculator
private
def raw_response_rate
# def rate
# check to see if enrollment data is available
# if not, run the dese loader to get the data
# then upload the enrollment data into the db
#
# if you still don't see enrollment for the school, raise an error and return 100 from this method
#
# Get the enrollment information from the db
# Get the list of all grades
# For each grade, get the survey items with data
#
#
# 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
def survey_item_count
@survey_item_count ||= begin
survey_items = SurveyItem.includes(%i[scale
@ -34,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

View file

@ -4,6 +4,7 @@ class Subcategory < ActiveRecord::Base
belongs_to :category, counter_cache: true
has_many :measures
has_many :survey_items, through: :measures
def score(school:, academic_year:)
scores = measures.map do |measure|

View file

@ -24,7 +24,41 @@ class SurveyItem < ActiveRecord::Base
scope :short_form_items, lambda {
where(on_short_form: true)
}
scope :early_education_surveys, lambda {
where("survey_item_id LIKE '%-%-es%'")
}
scope :survey_items_for_grade, lambda { |school, academic_year, grade|
includes(:survey_item_responses)
.where("survey_item_responses.grade": grade,
"survey_item_responses.school": school,
"survey_item_responses.academic_year": academic_year).distinct
}
scope :survey_item_ids_for_grade, lambda { |school, academic_year, grade|
survey_items_for_grade(school, academic_year, grade).pluck(:survey_item_id)
}
scope :survey_items_for_grade_and_subcategory, lambda { |school, academic_year, grade, subcategory|
includes(:survey_item_responses)
.where(
survey_item_id: subcategory.survey_items.pluck(:survey_item_id),
"survey_item_responses.school": school,
"survey_item_responses.academic_year": academic_year,
"survey_item_responses.grade": grade
)
}
scope :survey_type_for_grade, lambda { |school, academic_year, grade|
survey_items_set_by_grade = survey_items_for_grade(school, academic_year, grade).pluck(:survey_item_id).to_set
if survey_items_set_by_grade.size > 0 && survey_items_set_by_grade.subset?(early_education_surveys.pluck(:survey_item_id).to_set)
return :early_education
end
:regular
}
# TODO: rename this to Summary
def description
DataAvailability.new(survey_item_id, prompt, true)
end

View file

@ -13,17 +13,16 @@ class SurveyItemResponse < ActiveRecord::Base
has_one :measure, through: :survey_item
scope :exclude_boston, lambda {
boston = District.find_by_name('Boston')
where.not(school: boston.schools) if boston.present?
where.not(school: District.boston.schools) if District.boston.present?
}
scope :averages_for_grade, ->(survey_items, school, academic_year, grade) {
SurveyItemResponse.where(survey_item: survey_items, school:,
academic_year: , grade:).group(:survey_item).average(:likert_score)
scope :averages_for_grade, lambda { |survey_items, school, academic_year, grade|
SurveyItemResponse.where(survey_item: survey_items, school:,
academic_year:, grade:).group(:survey_item).average(:likert_score)
}
scope :averages_for_gender, ->(survey_items, school, academic_year, gender) {
SurveyItemResponse.where(survey_item: survey_items, school:,
academic_year: , gender:).group(:survey_item).average(:likert_score)
scope :averages_for_gender, lambda { |survey_items, school, academic_year, gender|
SurveyItemResponse.where(survey_item: survey_items, school:,
academic_year:, gender:).group(:survey_item).average(:likert_score)
}
end

View file

@ -26,4 +26,8 @@ class TeacherResponseRateCalculator < ResponseRateCalculator
total_responses.total_teachers
end
end
def raw_response_rate
(average_responses_per_survey_item / total_possible_responses.to_f * 100).round
end
end