From ae5c8265839c5e1e359c644a0a2fa7271f71edf3 Mon Sep 17 00:00:00 2001 From: Nelson Jovel Date: Tue, 13 Aug 2024 09:30:51 -0700 Subject: [PATCH] fix: SurveyItemByItem.create_item_report now runs without errors --- app/models/report/survey_item_by_item.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/report/survey_item_by_item.rb b/app/models/report/survey_item_by_item.rb index 7191853c..875239dc 100644 --- a/app/models/report/survey_item_by_item.rb +++ b/app/models/report/survey_item_by_item.rb @@ -1,11 +1,11 @@ module Report class SurveyItemByItem def self.create_item_report(schools:, academic_years:, filename:, use_student_survey_items: ::SurveyItem.student_survey_items.pluck(:id)) - data = to_csv(schools:, academic_years:, use_student_survey_items:) + csv = to_csv(schools:, academic_years:, use_student_survey_items:) FileUtils.mkdir_p Rails.root.join("tmp", "reports") filepath = Rails.root.join("tmp", "reports", filename) - write_csv(data:, filepath:) - data + write_csv(csv:, filepath:) + csv end def self.to_csv(schools:, academic_years:, use_student_survey_items: ::SurveyItem.student_survey_items.pluck(:id)) @@ -63,6 +63,7 @@ module Report schools.each do |school| # for each survey item id survey_ids_to_grades.each do |id, school_grades| + school_grades = school_grades.reject(&:nil?) row = [] survey_item = survey_item_for_id(id) row.concat(survey_item_info(survey_item:)) # fills prompt + categories @@ -156,7 +157,7 @@ module Report @scales[scale_id] end - def self.write_csv(data:, filepath:) + def self.write_csv(csv:, filepath:) File.write(filepath, csv) end