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

rpp-main
Nelson Jovel 1 year ago
parent 6a8396f4df
commit 4407954058

@ -37,7 +37,7 @@ class ExportsController < ApplicationController
report = params[:report] report = params[:report]
if report == "Survey Item - By Item" if ["Survey Item - By Item", "Survey Item - By Grade", "Survey Item Response"].include?(report)
use_student_survey_items = student_survey_types[params[:student_survey_type]] use_student_survey_items = student_survey_types[params[:student_survey_type]]
reports[report].call(schools, academic_years, use_student_survey_items) reports[report].call(schools, academic_years, use_student_survey_items)
else else
@ -78,14 +78,15 @@ class ExportsController < ApplicationController
send_data data, disposition: "attachment", send_data data, disposition: "attachment",
filename: "survey_item_by_item_#{Date.today}.csv" filename: "survey_item_by_item_#{Date.today}.csv"
}, },
"Survey Item - By Grade" => lambda { |schools, academic_years| "Survey Item - By Grade" => lambda { |schools, academic_years, use_student_survey_items|
data = Report::SurveyItemByGrade.to_csv(schools:, academic_years:, data = Report::SurveyItemByGrade.to_csv(schools:, academic_years:,
use_student_survey_items: ::SurveyItem.student_survey_items.pluck(:id)) use_student_survey_items:)
send_data data, send_data data,
disposition: "attachment", filename: "survey_item_by_grade_#{Date.today}.csv" disposition: "attachment", filename: "survey_item_by_grade_#{Date.today}.csv"
}, },
"Survey Item Response" => lambda { |schools, academic_years|
data = Report::SurveyItemResponse.to_csv(schools:, academic_years:) "Survey Item Response" => lambda { |schools, academic_years, use_student_survey_items|
data = Report::SurveyItemResponse.to_csv(schools:, academic_years:, use_student_survey_items:)
send_data data, disposition: "attachment", filename: "survey_item_response_#{Date.today}.csv" send_data data, disposition: "attachment", filename: "survey_item_response_#{Date.today}.csv"
} } } }
end end

@ -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") # 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 module Report
class SurveyItemResponse class SurveyItemResponse
def self.create(schools:, academic_years:, filename:) def self.create(schools:, academic_years:, filename:, use_student_survey_items:)
data = to_csv(schools:, academic_years:) data = to_csv(schools:, academic_years:, use_student_survey_items:)
FileUtils.mkdir_p Rails.root.join("tmp", "reports") FileUtils.mkdir_p Rails.root.join("tmp", "reports")
filepath = Rails.root.join("tmp", "reports", filename) filepath = Rails.root.join("tmp", "reports", filename)
write_csv(data:, filepath:) write_csv(data:, filepath:)
data data
end end
def self.to_csv(schools:, academic_years:) def self.to_csv(schools:, academic_years:, use_student_survey_items:)
data = [] data = []
data << ["Response ID", "Race", "Gender", "Grade", "School ID", "District", "Academic Year", "Student Physical Safety", 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"] "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 jobs = Queue.new
schools.each { |school| jobs << school } schools.each { |school| jobs << school }
use_student_survey_items = use_student_survey_items.to_set
workers = pool_size.times.map do workers = pool_size.times.map do
Thread.new do Thread.new do
while school = jobs.pop(true) while school = jobs.pop(true)
@ -42,6 +44,8 @@ module Report
response_hash.each do |_key, responses| response_hash.each do |_key, responses|
mutex.synchronize do mutex.synchronize do
next unless responses.map(&:survey_item_id).to_set.subset?(use_student_survey_items)
row = [] row = []
info = responses.first info = responses.first
response_id = info.response_id response_id = info.response_id

@ -14,6 +14,7 @@ class ExportsPresenter
@selected_school ||= @schools.first @selected_school ||= @schools.first
@schools_grouped_by = params["school_group"] @schools_grouped_by = params["school_group"]
@show_student_survey_types = params[:report] == "Survey Item - By Item" @show_student_survey_types = ["Survey Item - By Item", "Survey Item - By Grade",
"Survey Item Response"].include?(params[:report])
end end
end end

@ -1,4 +1,4 @@
<h1>Exports page</h1> <h1 class="mt-5">Exports page</h1>
<%= turbo_frame_tag "results" do %> <%= turbo_frame_tag "results" do %>
<%= form_with(action: exports_path, <%= form_with(action: exports_path,
method: :get, method: :get,

Loading…
Cancel
Save