diff --git a/.ruby-version b/.ruby-version index 9c25013d..47b322c9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.6 +3.4.1 diff --git a/Gemfile.lock b/Gemfile.lock index 1e91cc17..0df118be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -204,7 +204,7 @@ GEM activerecord (>= 4.0.0) globalid (1.2.1) activesupport (>= 6.1) - google-protobuf (4.28.2-x86_64-linux) + google-protobuf (4.28.2) bigdecimal rake (>= 13) guard (2.18.1) @@ -261,6 +261,7 @@ GEM matrix (0.4.2) method_source (1.0.0) mini_mime (1.1.5) + mini_portile2 (2.8.8) minitest (5.25.1) msgpack (1.7.2) multi_json (1.15.0) @@ -281,7 +282,8 @@ GEM newrelic_rpm (9.6.0) base64 nio4r (2.7.3) - nokogiri (1.16.7-x86_64-linux) + nokogiri (1.16.7) + mini_portile2 (~> 2.8.2) racc (~> 1.4) notiffany (0.1.3) nenv (~> 0.1) @@ -548,7 +550,7 @@ DEPENDENCIES watir RUBY VERSION - ruby 3.3.6p108 + ruby 3.4.1p0 BUNDLED WITH 2.5.11 diff --git a/app/models/report/survey_item_by_item.rb b/app/models/report/survey_item_by_item.rb index 84bf5128..caa02385 100644 --- a/app/models/report/survey_item_by_item.rb +++ b/app/models/report/survey_item_by_item.rb @@ -61,13 +61,13 @@ module Report data << headers survey_items_by_id = ::SurveyItem.by_id_includes_all - academic_years.each do |academic_year| - mutex = Thread::Mutex.new - pool_size = 2 - jobs = Queue.new - schools.each { |school| jobs << school } + mutex = Thread::Mutex.new + pool_size = 2 + jobs = Queue.new + schools.each { |school| jobs << school } + academic_years.each do |academic_year| workers = pool_size.times.map do Thread.new do while school = jobs.pop(true) @@ -108,8 +108,8 @@ module Report row.concat(padding) # filter out response rate at subcategory level <24.5% for school average - if ::StudentResponseRateCalculator.new(subcategory: survey_item.subcategory, school:, - academic_year:).meets_student_threshold? + if response_rate(subcategory: survey_item.subcategory, school:, + academic_year:).meets_student_threshold? row.append("#{survey_item.survey_item_responses.where( # We allow the nil (unknown) grades in the school survey item average # also filter less than 10 responses in the whole school @@ -154,6 +154,15 @@ module Report end end + def self.response_rate(subcategory:, school:, academic_year:) + @response_rate ||= Hash.new do |memo, (subcategory, school, academic_year)| + memo[[subcategory, school, academic_year]] = + ::StudentResponseRateCalculator.new(subcategory:, school:, academic_year:) + end + + @response_rate[[subcategory, school, academic_year]] + end + def self.write_csv(csv:, filepath:) File.write(filepath, csv) end