feat: add ability to filter export data by student survey item type. Ability added to 'by grade' 'by item' and 'survey item responses' reports

This commit is contained in:
Nelson Jovel 2024-08-21 14:04:44 -07:00
parent cd91496279
commit aee0bc9883
4 changed files with 16 additions and 10 deletions

View file

@ -1,15 +1,15 @@
# Report::SurveyItemResponse.create(schools: District.find_by_name("Lee Public Schools").schools, academic_years: AcademicYear.where(range: "2023-24 Spring"), filename: "test.csv")
module Report
class SurveyItemResponse
def self.create(schools:, academic_years:, filename:)
data = to_csv(schools:, academic_years:)
def self.create(schools:, academic_years:, filename:, use_student_survey_items:)
data = 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
end
def self.to_csv(schools:, academic_years:)
def self.to_csv(schools:, academic_years:, use_student_survey_items:)
data = []
data << ["Response ID", "Race", "Gender", "Grade", "School ID", "District", "Academic Year", "Student Physical Safety",
"Student Emotional Safety", "Student Sense of Belonging", "Student-Teacher Relationships", "Valuing of Learning", "Academic Challenge", "Content Specialists & Support Staff", "Cultural Responsiveness", "Engagement In School", "Appreciation For Diversity", "Civic Participation", "Perseverance & Determination", "Growth Mindset", "Participation In Creative & Performing Arts", "Valuing Creative & Performing Arts", "Social & Emotional Health"]
@ -19,6 +19,8 @@ module Report
jobs = Queue.new
schools.each { |school| jobs << school }
use_student_survey_items = use_student_survey_items.to_set
workers = pool_size.times.map do
Thread.new do
while school = jobs.pop(true)
@ -42,6 +44,8 @@ module Report
response_hash.each do |_key, responses|
mutex.synchronize do
next unless responses.map(&:survey_item_id).to_set.subset?(use_student_survey_items)
row = []
info = responses.first
response_id = info.response_id