fix: correctly load survey items from sample framework file. Fix broken tests

This commit is contained in:
Nelson Jovel 2024-08-27 12:45:52 -07:00
parent 07836cc020
commit f689ee8ee5
7 changed files with 414 additions and 305 deletions

View file

@ -52,8 +52,9 @@ class Seeder
def seed_sqm_framework(csv_file)
admin_data_item_ids = []
CSV.parse(File.read(csv_file), headers: true) do |row|
next if row["Source"] == "No source"
category_id = row["Category ID"]&.strip
next if category_id.nil?
category = Category.find_or_create_by!(category_id:)
category_slugs = {
@ -71,7 +72,6 @@ class Seeder
subcategory.update! name: row["Subcategory"].strip, description: row["Subcategory Description"].strip
measure_id = row["Measure ID"]&.strip
next if measure_id.nil?
measure_name = row["Measures"].try(:strip)
watch_low = row["Item Watch Low"].try(:strip)
@ -81,19 +81,17 @@ class Seeder
on_short_form = row["On Short Form?"].try(:strip)
measure_description = row["Measure Description"].try(:strip)
next if row["Source"] == "No source"
measure = Measure.find_or_create_by!(measure_id:, subcategory:)
measure.name = measure_name
measure.description = measure_description
measure.save!
data_item_id = row["Survey Item ID"].strip
data_item_id = row["Survey Item ID"].downcase.strip
scale_id = data_item_id.split("-")[0..1].join("-")
scale = Scale.find_or_create_by!(scale_id:, measure:)
active_survey_item = row["Active admin & survey items"]
if %w[Teachers Students Parents].include? row["Source"] && %w[TRUE 1].include?(active_survey_item)
if %w[Teachers Students Parents].include?(row["Source"]) && %w[TRUE 1].include?(active_survey_item)
survey_item = SurveyItem.where(survey_item_id: data_item_id, scale:).first_or_create
survey_item.watch_low_benchmark = watch_low if watch_low
survey_item.growth_low_benchmark = growth_low if growth_low
@ -116,7 +114,6 @@ class Seeder
admin_data_item_ids << admin_data_item.id
end
end
AdminDataValue.where.not(admin_data_item_id: admin_data_item_ids).delete_all
AdminDataItem.where.not(id: admin_data_item_ids).delete_all
end

View file

@ -1,11 +1,11 @@
module Report
class Subcategory
def self.create_report(schools: School.all.includes(:district), academic_years: AcademicYear.all, subcategories: ::Subcategory.all, filename: "subcategories.csv")
data = to_csv(schools:, academic_years:, subcategories:, filename:)
csv = to_csv(schools:, academic_years:, subcategories:, filename:)
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: School.all.includes(:district), academic_years: AcademicYear.all, subcategories: ::Subcategory.all, filename: "subcategories.csv")
@ -74,7 +74,7 @@ module Report
end
end
def self.write_csv(data:, filepath:)
def self.write_csv(csv:, filepath:)
File.write(filepath, csv)
end

View file

@ -6,7 +6,8 @@ class Score < ApplicationRecord
belongs_to :academic_year
belongs_to :race
NIL_SCORE = Score.new(average: nil, meets_teacher_threshold: false, meets_student_threshold: false, meets_admin_data_threshold: false)
NIL_SCORE = Score.new(average: nil, meets_teacher_threshold: false, meets_student_threshold: false,
meets_admin_data_threshold: false)
enum group: {
all_students: 0,

View file

@ -25,13 +25,13 @@ class SubcategoryPresenter
end
def student_response_rate
return 'N / A' if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
return "N / A" if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
"#{@subcategory.response_rate(school: @school, academic_year: @academic_year).student_response_rate.round}%"
end
def teacher_response_rate
return 'N / A' if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
return "N / A" if Respondent.where(school: @school, academic_year: @academic_year).count.zero?
"#{@subcategory.response_rate(school: @school, academic_year: @academic_year).teacher_response_rate.round}%"
end