feat: add special education disaggregation

This commit is contained in:
rebuilt 2023-10-05 14:51:36 -07:00
parent c582126d2a
commit 48e795fcfb
27 changed files with 399 additions and 62 deletions

View file

@ -43,7 +43,7 @@ class Cleaner
log_csv = []
data = []
headers = CSV.parse(file.first).first.push("Raw Income").push("Income").push("Raw ELL").push("ELL")
headers = CSV.parse(file.first).first.push("Raw Income").push("Income").push("Raw ELL").push("ELL").push("Raw SpEd").push("SpEd")
filtered_headers = include_all_headers(headers:)
filtered_headers = remove_unwanted_headers(headers: filtered_headers)
log_headers = (filtered_headers + ["Valid Duration?", "Valid Progress?", "Valid Grade?",

View file

@ -5,8 +5,9 @@ class DemographicLoader
CSV.parse(File.read(filepath), headers: true) do |row|
process_race(row:)
process_gender(row:)
process_income(row:)
process_ell(row:)
create_from_column(column: "Income", row:, model: Income)
create_from_column(column: "ELL", row:, model: Ell)
create_from_column(column: "Special Ed Status", row:, model: Sped)
end
end
@ -31,18 +32,11 @@ class DemographicLoader
gender.save
end
def self.process_income(row:)
designation = row["Income"]
def self.create_from_column(column:, row:, model:)
designation = row[column]
return unless designation
Income.find_or_create_by!(designation:)
end
def self.process_ell(row:)
designation = row["ELL"]
return unless designation
Ell.find_or_create_by!(designation:)
model.find_or_create_by!(designation:)
end
end

View file

@ -15,6 +15,8 @@ class SurveyItemValues
row["Raw Income"] = raw_income
row["Raw ELL"] = raw_ell
row["ELL"] = ell
row["Raw SpEd"] = raw_sped
row["SpEd"] = sped
copy_data_to_main_column(main: /Race/i, secondary: /Race Secondary|Race-1/i)
copy_data_to_main_column(main: /Gender/i, secondary: /Gender Secondary|Gender-1/i)
@ -163,6 +165,21 @@ class SurveyItemValues
end
end
def raw_sped
@raw_sped ||= value_from(pattern: /Special\s*Ed\s*Status|Raw\s*SpEd/i)
end
def sped
@sped ||= case raw_sped
in /active/i
"Special Education"
in /^NA$|^#NA$/i
"Unknown"
else
"Not Special Education"
end
end
def value_from(pattern:)
output = nil
matches = headers.select do |header|

View file

@ -62,6 +62,10 @@ class SurveyResponsesDataLoader
@ells ||= Ell.by_designation
end
def speds
@speds ||= Sped.by_designation
end
def process_row(row:, rules:)
return unless row.dese_id?
return unless row.school.present?
@ -91,12 +95,14 @@ class SurveyResponsesDataLoader
grade = row.grade
income = incomes[row.income.parameterize]
ell = ells[row.ell]
sped = speds[row.sped]
if survey_item_response.present?
survey_item_response.update!(likert_score:, grade:, gender:, recorded_date: row.recorded_date, income:, ell:)
survey_item_response.update!(likert_score:, grade:, gender:, recorded_date: row.recorded_date, income:, ell:,
sped:)
[]
else
SurveyItemResponse.new(response_id: row.response_id, academic_year: row.academic_year, school: row.school, survey_item:,
likert_score:, grade:, gender:, recorded_date: row.recorded_date, income:, ell:)
likert_score:, grade:, gender:, recorded_date: row.recorded_date, income:, ell:, sped:)
end
end