fix: ECP-124 Update grade range to be the union of grades found in the database and the enrollment of the school. "Subcategory - School & District"

# Fixed reported grades
	     # Runs faster
      "Measure - District only"
	      # Should only be run per district
	      # Runs faster
	      # Fixed reported grades
      "Measure - School & District"
	      # Reports the grades that took the survey for that school+year; not the grades that responded to the measure
	      # Runs faster
	      # Fixed reported grades
      "Beyond Learning Loss"
      		# Runs faster
      "Beyond Learning Loss - Response Rate"
      		# Fixed reported grades
      "Survey Item - By Item"
	      # may be able to speed it up by getting all averages in a single request
	      # Fixed reported grades
      "Survey Item - By Grade"
      		# Fixed reported grades
	      #may be able to speed it up by getting all averages in a single request
      "Survey Entries - by Measure"
      		# No changes
main-eol
rebuilt 7 months ago
parent 0f457becf0
commit 058cbb0f6e

@ -30,7 +30,7 @@ class ExportsController < ApplicationController
report = params[:report]
if ["Survey Item - By Item", "Survey Item - By Grade", "Survey Entries - by Measure"].include?(report)
use_student_survey_items = student_survey_types[params[:student_survey_type]]
use_student_survey_items = student_survey_types[params[:student_survey_type]] || ::SurveyItem.student_survey_items.pluck(:id)
reports[report].call(schools, academic_years, use_student_survey_items)
else
reports[report].call(schools, academic_years)
@ -88,8 +88,7 @@ class ExportsController < ApplicationController
filename: "beyond_learning_loss_response_rate_#{Date.today}.csv"
},
"Survey Item - By Item" => lambda { |schools, academic_years, use_student_survey_items|
data = Report::SurveyItemByItem.to_csv(schools:, academic_years:,
use_student_survey_items:)
data = Report::SurveyItemByItem.to_csv(schools:, academic_years:, use_student_survey_items:)
send_data data, disposition: "attachment",
filename: "survey_item_by_item_#{Date.today}.csv"
},

@ -21,10 +21,18 @@ module Report
Thread.new do
while school = jobs.pop(true)
academic_years.each do |academic_year|
scales.each do |scale|
respondents = Respondent.by_school_and_year(school:, academic_year:)
next if respondents.nil?
respondents = Respondent.by_school_and_year(school:, academic_year:)
next if respondents.nil?
begin_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
all_grades = Respondent.grades_that_responded_to_survey(academic_year:, school:)
grades = "#{all_grades.first}-#{all_grades.last}"
scales.each do |scale|
response_rate = scale.measure.subcategory.response_rate(school:, academic_year:)
next unless response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold?
@ -37,16 +45,8 @@ module Report
scale.score(school:, academic_year:)
end
begin_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
row = [response_rate, scale, school, academic_year]
all_grades = respondents.enrollment_by_grade.keys
grades = "#{all_grades.first}-#{all_grades.last}"
mutex.synchronize do
data << [school.district.name,
school.name,

@ -48,7 +48,8 @@ module Report
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
all_grades = respondents.enrollment_by_grade.keys
all_grades = Respondent.grades_that_responded_to_survey(academic_year:, school:)
grades = "#{all_grades.first}-#{all_grades.last}"
mutex.synchronize do

@ -21,26 +21,25 @@ module Report
Thread.new do
while school = jobs.pop(true)
academic_years.each do |academic_year|
measures.each do |measure|
respondents = Respondent.by_school_and_year(school:, academic_year:)
next if respondents.nil?
respondents = Respondent.by_school_and_year(school:, academic_year:)
next if respondents.nil?
response_rate = measure.subcategory.response_rate(school:, academic_year:)
next unless response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold?
begin_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
all_grades = Respondent.grades_that_responded_to_survey(academic_year: academic_year, school: school)
grades = "#{all_grades.first}-#{all_grades.last}"
measures.each do |measure|
score = measure.score(school:, academic_year:)
zone = measure.zone(school:, academic_year:).type.to_s.capitalize
begin_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
response_rate = measure.subcategory.response_rate(school:, academic_year:)
next unless response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold?
row = [response_rate, measure, school, academic_year]
all_grades = respondents.enrollment_by_grade.keys
grades = "#{all_grades.first}-#{all_grades.last}"
mutex.synchronize do
data << [measure.name,
measure.measure_id,

@ -20,21 +20,17 @@ module Report
workers = pool_size.times.map do
Thread.new do
while measure = jobs.pop(true)
academic_years.each do |academic_year|
respondents = Respondent.where(school: schools, academic_year:)
enrollment = respondents.map do | respondent| respondent.enrollment_by_grade.keys end.flatten.compact.uniq.sort
grades_with_responses = ::SurveyItemResponse.where(school: schools, academic_year:).where.not(grade: nil).pluck(:grade).uniq.sort
all_grades = (enrollment & grades_with_responses).sort
grades = "#{all_grades.first}-#{all_grades.last}"
all_grades = Respondent.grades_that_responded_to_survey(academic_year: academic_years, school: schools)
grades = "#{all_grades.first}-#{all_grades.last}"
district = schools.first.district
academic_years.each do |academic_year|
begin_date = ::SurveyItemResponse.where(school: schools,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school: schools,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
district = schools.first.district
row = [measure, district, academic_year]
mutex.synchronize do

@ -21,26 +21,25 @@ module Report
Thread.new do
while school = jobs.pop(true)
academic_years.each do |academic_year|
subcategories.each do |subcategory|
respondents = Respondent.by_school_and_year(school:, academic_year:)
next if respondents.nil?
respondents = Respondent.by_school_and_year(school:, academic_year:)
next if respondents.nil?
response_rate = subcategory.response_rate(school:, academic_year:)
next unless response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold?
begin_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
all_grades = Respondent.grades_that_responded_to_survey(academic_year:, school:)
grades = "#{all_grades.first}-#{all_grades.last}"
subcategories.each do |subcategory|
score = subcategory.score(school:, academic_year:)
zone = subcategory.zone(school:, academic_year:).type.to_s.capitalize
begin_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).first&.recorded_date&.to_date
end_date = ::SurveyItemResponse.where(school:,
academic_year:).where.not(recorded_date: nil).order(:recorded_date).last&.recorded_date&.to_date
date_range = "#{begin_date} - #{end_date}"
response_rate = subcategory.response_rate(school:, academic_year:)
next unless response_rate.meets_student_threshold? || response_rate.meets_teacher_threshold?
row = [response_rate, subcategory, school, academic_year]
all_grades = respondents.enrollment_by_grade.keys
grades = "#{all_grades.first}-#{all_grades.last}"
mutex.synchronize do
data << [school.district.name,
school.name,

@ -15,13 +15,7 @@ module Report
# also get a map of grade->survey_id
sufficient_survey_items = {}
grades = []
schools.each do |school|
academic_years.each do |academic_year|
grades.concat(school.grades(academic_year:))
end
end
grades = grades.uniq.reject { |grade| grade == -1 }.reject(&:nil?) # remove preschool and nil grades
grades = Respondent.grades_that_responded_to_survey(academic_year: academic_years, school: schools)
grades.each do |grade|
sufficient_survey_items[grade] ||= Set.new

@ -39,13 +39,7 @@ module Report
"Academic Year"
]
grades = []
schools.each do |school|
academic_years.each do |academic_year|
grades.concat(school.grades(academic_year:))
end
end
grades = grades.uniq.reject { |grade| grade == -1 }.reject(&:nil?) # remove preschool and nil grades
grades = Respondent.grades_that_responded_to_survey(academic_year: academic_years, school: schools)
grades.each do |value|
if value == 0

@ -34,4 +34,12 @@ class Respondent < ApplicationRecord
def total_educators
(total_teachers || 0) + (total_esp || 0)
end
def self.grades_that_responded_to_survey(academic_year:, school:)
respondents = Respondent.where(school:, academic_year:)
enrollment = respondents.map { |respondent| respondent.enrollment_by_grade.keys }.flatten.compact.uniq.sort
grades_with_responses = ::SurveyItemResponse.where(school:, academic_year:).where.not(grade: nil).pluck(:grade).uniq.sort
(enrollment & grades_with_responses).sort
end
end

Loading…
Cancel
Save