mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 15:38:21 -07:00
Update demographics table with lanugage options Create a lanugage table to hold the new languages Update the demographic loader to input languages into the database Update the cleaner to read the language column Update the parent table to hold a reference to a language Update the data uploader script to read the language from the csv and update the language information for any parent items that already exist (or create database entries if none already exist) update the analyze interface to add controls for selecting ‘parents by group’ and a dropdown for ‘parent by language’ Update the analyze controller to read the parent-by-group parameter Create a graph for the parent-by-group view Bubble up averages for language calculations. Make sure n-size only counts responses for a given measure.
61 lines
1.7 KiB
Ruby
61 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class DemographicLoader
|
|
def self.load_data(filepath:)
|
|
CSV.parse(File.read(filepath), headers: true) do |row|
|
|
process_race(row:)
|
|
process_gender(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)
|
|
create_from_column(column: "Housing", row:, model: Housing)
|
|
create_from_column(column: "Language", row:, model: Language)
|
|
end
|
|
end
|
|
|
|
def self.process_race(row:)
|
|
qualtrics_code = row["Race Qualtrics Code"].to_i
|
|
designation = row["Race/Ethnicity"]
|
|
return unless qualtrics_code && designation
|
|
|
|
if qualtrics_code.between?(6, 7)
|
|
UnknownRace.new(qualtrics_code:, designation:)
|
|
else
|
|
KnownRace.new(qualtrics_code:, designation:)
|
|
end
|
|
end
|
|
|
|
def self.process_gender(row:)
|
|
qualtrics_code = row["Gender Qualtrics Code"].to_i
|
|
designation = row["Sex/Gender"]
|
|
return unless qualtrics_code && designation
|
|
|
|
gender = ::Gender.find_or_create_by!(qualtrics_code:, designation:)
|
|
gender.save
|
|
end
|
|
|
|
def self.create_from_column(column:, row:, model:)
|
|
designation = row[column]
|
|
return unless designation
|
|
|
|
model.find_or_create_by!(designation:)
|
|
end
|
|
end
|
|
|
|
class KnownRace
|
|
def initialize(qualtrics_code:, designation:)
|
|
known = Race.find_or_create_by!(qualtrics_code:)
|
|
known.designation = designation
|
|
known.slug = designation.parameterize
|
|
known.save
|
|
end
|
|
end
|
|
|
|
class UnknownRace
|
|
def initialize(qualtrics_code:, designation:)
|
|
unknown = Race.find_or_create_by!(qualtrics_code: 99)
|
|
unknown.designation = "Race/Ethnicity Not Listed"
|
|
unknown.slug = designation.parameterize
|
|
unknown.save
|
|
end
|
|
end
|