Convert gender and race text into qualtrics codes during cleaning. Abide by 'prefer not to disclose' for self reported race. Give priority to self reported data but use SIS information as backup

This commit is contained in:
Nelson Jovel 2023-11-30 20:57:04 -08:00
parent 305ddf2b1a
commit e325f38c43
6 changed files with 62 additions and 9 deletions

View file

@ -2,4 +2,21 @@ class Gender < ApplicationRecord
scope :by_qualtrics_code, lambda {
all.map { |gender| [gender.qualtrics_code, gender] }.to_h
}
def self.qualtrics_code_from(word)
case word
when /Female|F|1/i
1
when /Male|M|2/i
2
when /Another\s*Gender|Gender Identity not listed above|3/i
4
when /Non-Binary|N|4/i
4
when %r{^#*N/*A$}i
nil
else
99
end
end
end

View file

@ -3,4 +3,29 @@ class Race < ApplicationRecord
has_many :student_races
has_many :students, through: :student_races
friendly_id :designation, use: [:slugged]
def self.qualtrics_code_from(word)
case word
when /Native\s*American|American\s*Indian|Alaskan\s*Native|1/i
1
when /Asian|Pacific\s*Island|2/i
2
when /Black|African\s*American|3/i
3
when /Hispanic|Latinx|4/i
4
when /White|Caucasian|5/i
5
when /Prefer not to disclose|6/i
6
when /Prefer to self-describe|7/i
7
when /Middle\s*Eastern|North\s*African|8/i
8
when %r{^#*N/*A$}i
nil
else
99
end
end
end

View file

@ -35,7 +35,15 @@ class Cleaner
row.district.short_name
end.to_set.to_a
districts.join(".").to_s + "." + survey_type.to_s + "." + range + ".csv"
schools = data.map do |row|
row.school.name
end.to_set
# Only add school to filename when there's a single school
school_name = ""
school_name = schools.first.parameterize + "." if schools.length == 1
districts.join(".").to_s + "." + school_name + survey_type.to_s + "." + range + ".csv"
end
def process_raw_file(file:)

View file

@ -200,6 +200,9 @@ class SurveyItemValues
matches.each do |match|
output ||= row[match]
end
return nil if output&.match?(%r{^#*N/*A}i) || output.blank?
output
end