chore: various fixes for race and gender categorization during cleaning.

Also add tests for race and gender categorization
This commit is contained in:
Nelson Jovel 2023-12-08 13:12:19 -08:00
parent 8364d26e11
commit 8a0ba0dbea
4 changed files with 274 additions and 15 deletions

View file

@ -5,9 +5,9 @@ class Gender < ApplicationRecord
def self.qualtrics_code_from(word)
case word
when /Female|F|1/i
when /Female|^F|1/i
1
when /Male|M|2/i
when /Male|^M|2/i
2
when /Another\s*Gender|Gender Identity not listed above|3|7/i
4 # We categorize any self reported gender as non-binary

View file

@ -4,13 +4,17 @@ class Race < ApplicationRecord
has_many :students, through: :student_races
friendly_id :designation, use: [:slugged]
scope :by_qualtrics_code, lambda {
all.map { |race| [race.qualtrics_code, race] }.to_h
}
# TODO: look for alaska native
# Todo: split up possibilities by first a comma and then the word and
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|Hawaiian|2/i
when /^Asian|Pacific\s*Island|Hawaiian|2/i
2
when /Black|African\s*American|3/i
3