From 3a5a368a35096a76ef2101ba4eaa59537e8357f0 Mon Sep 17 00:00:00 2001 From: rebuilt Date: Thu, 27 Mar 2025 15:20:40 -0700 Subject: [PATCH] feat: Update demographics file with housing statuses. Create housing class. Update survey_item_values.rb to parse housing info. Update cleaner to output housing info. --- app/models/housing.rb | 17 +++++++++++++++ app/services/cleaner.rb | 4 ++-- app/services/demographic_loader.rb | 1 + app/services/survey_item_values.rb | 10 +++++++++ data/demographics.csv | 22 ++++++++++---------- db/migrate/20250327205800_create_housings.rb | 9 ++++++++ db/schema.rb | 8 ++++++- spec/factories.rb | 4 ++++ spec/models/housing_spec.rb | 5 +++++ 9 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 app/models/housing.rb create mode 100644 db/migrate/20250327205800_create_housings.rb create mode 100644 spec/models/housing_spec.rb diff --git a/app/models/housing.rb b/app/models/housing.rb new file mode 100644 index 00000000..a5dbe10d --- /dev/null +++ b/app/models/housing.rb @@ -0,0 +1,17 @@ +class Housing < ApplicationRecord + def self.to_designation(housing) + return "Unknown" if housing.blank? + + housing = housing + case housing + in /^1$/i + "Own" + in /^2$/i + "Rent" + in /^99$|^100$/i + "Unknown" + else + "Unknown" + end + end +end diff --git a/app/services/cleaner.rb b/app/services/cleaner.rb index 8ebe2efa..a190a37a 100644 --- a/app/services/cleaner.rb +++ b/app/services/cleaner.rb @@ -65,7 +65,7 @@ class Cleaner .filter { |header| header.start_with? "s-" } .count > 0 - has_grade_header = headers.filter(&:present?).find {|header| header.match?(/grade/i) }.present? + has_grade_header = headers.filter(&:present?).find { |header| header.match?(/grade/i) }.present? if is_student_survey && has_grade_header == false puts "could not find the Grade header. Stopping execution" exit @@ -79,7 +79,7 @@ class Cleaner headers = headers.to_set headers = headers.merge(Set.new(["Raw Income", "Income", "Raw ELL", "ELL", "Raw SpEd", "SpEd", "Progress Count", - "Race", "Gender"])).to_a + "Race", "Gender", "Raw Housing Status", "Housing Status"])).to_a filtered_headers = include_all_headers(headers:) filtered_headers = remove_unwanted_headers(headers: filtered_headers) log_headers = (filtered_headers + ["Valid Duration?", "Valid Progress?", "Valid Grade?", diff --git a/app/services/demographic_loader.rb b/app/services/demographic_loader.rb index 33232438..36170251 100644 --- a/app/services/demographic_loader.rb +++ b/app/services/demographic_loader.rb @@ -8,6 +8,7 @@ class DemographicLoader 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) + create_from_column(column: "Housing", row:, model: Housing) end end diff --git a/app/services/survey_item_values.rb b/app/services/survey_item_values.rb index 779da43e..e619bb62 100644 --- a/app/services/survey_item_values.rb +++ b/app/services/survey_item_values.rb @@ -20,6 +20,8 @@ class SurveyItemValues row["Progress Count"] = progress row["Race"] ||= races.join(",") row["Gender"] ||= gender + row["Raw Housing Status"] = raw_housing + row["Housing Status"] = housing 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) @@ -195,6 +197,14 @@ class SurveyItemValues @sped ||= Sped.to_designation(raw_sped) end + def raw_housing + @raw_housing ||= value_from(pattern: /Housing/i) + end + + def housing + @housing ||= Housing.to_designation(raw_housing) + end + def number_of_children @number_of_children ||= value_from(pattern: /Number\s*Of\s*Children/i).to_i end diff --git a/data/demographics.csv b/data/demographics.csv index 742624b4..e2a005aa 100644 --- a/data/demographics.csv +++ b/data/demographics.csv @@ -1,11 +1,11 @@ -Race Qualtrics Code,Race/Ethnicity,Gender Qualtrics Code,Sex/Gender,Income,ELL,Special Ed Status -1,American Indian or Alaskan Native,2,Male,Economically Disadvantaged - N,ELL,Special Education -2,Asian or Pacific Islander,1,Female,Economically Disadvantaged - Y,Not ELL,Not Special Education -3,Black or African American,4,Non-Binary,Unknown,Unknown,Unknown -4,Hispanic or Latinx,99,Unknown,,, -5,White or Caucasian,,,,, -6,Prefer not to disclose,,,,, -7,Prefer to self-describe,,,,, -8,Middle Eastern,,,,, -99,Race/Ethnicity Not Listed,,,,, -100,Multiracial,,,,, +Race Qualtrics Code,Race/Ethnicity,Gender Qualtrics Code,Sex/Gender,Income,ELL,Special Ed Status,Housing +1,American Indian or Alaskan Native,2,Male,Economically Disadvantaged - N,ELL,Special Education,Own +2,Asian or Pacific Islander,1,Female,Economically Disadvantaged - Y,Not ELL,Not Special Education,Rent +3,Black or African American,4,Non-Binary,Unknown,Unknown,Unknown,Unknown +4,Hispanic or Latinx,99,Unknown,,,, +5,White or Caucasian,,,,,, +6,Prefer not to disclose,,,,,, +7,Prefer to self-describe,,,,,, +8,Middle Eastern,,,,,, +99,Race/Ethnicity Not Listed,,,,,, +100,Multiracial,,,,,, diff --git a/db/migrate/20250327205800_create_housings.rb b/db/migrate/20250327205800_create_housings.rb new file mode 100644 index 00000000..1a42d59e --- /dev/null +++ b/db/migrate/20250327205800_create_housings.rb @@ -0,0 +1,9 @@ +class CreateHousings < ActiveRecord::Migration[8.0] + def change + create_table :housings do |t| + t.string :designation + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0a83f791..f16565ab 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_01_15_011457) do +ActiveRecord::Schema[8.0].define(version: 2025_03_27_205800) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -88,6 +88,12 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_15_011457) do t.index ["slug"], name: "index_genders_on_slug", unique: true end + create_table "housings", force: :cascade do |t| + t.string "designation" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "incomes", force: :cascade do |t| t.string "designation" t.datetime "created_at", null: false diff --git a/spec/factories.rb b/spec/factories.rb index 4d32450c..e9aa534b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,4 +1,8 @@ FactoryBot.define do + factory :housing do + designation { "MyString" } + end + factory :parent do response_id { "MyString" } number_of_children { 1 } diff --git a/spec/models/housing_spec.rb b/spec/models/housing_spec.rb new file mode 100644 index 00000000..44f9b4c3 --- /dev/null +++ b/spec/models/housing_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Housing, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end