chore: refactor Race out of survey_item_values

mciea-main
Nelson Jovel 2 years ago
parent a295b8afb9
commit 317fe3239a

@ -1,5 +1,5 @@
class SurveyItemValues
attr_reader :row, :headers, :survey_items, :schools
attr_reader :row, :headers, :survey_items, :schools
def initialize(row:, headers:, survey_items:, schools:)
@row = row
@ -17,7 +17,7 @@ class SurveyItemValues
row["Raw SpEd"] = raw_sped
row["SpEd"] = sped
row["Progress Count"] = progress
row["Race"] ||= races.map { |race| race&.qualtrics_code }.join(",")
row["Race"] ||= races.join(",")
row["Gender"] ||= gender
copy_data_to_main_column(main: /Race/i, secondary: /Race Secondary|Race-1/i)
@ -139,6 +139,8 @@ class SurveyItemValues
race_codes ||= sis ||= value_from(pattern: /Race\s*-\s*Qcodes/i)
race_codes ||= value_from(pattern: /RACE/i) || ""
race_codes ||= []
race_codes = race_codes.split(",")
.map do |word|
word.split(/\s+and\s+/i)
@ -328,27 +330,27 @@ class SurveyItemValues
def process_races(codes:)
races = codes.map do |code|
code = code.to_i
code = 99 if [6, 7].include?(code) || code.nil? || code.zero?
Race.find_by_qualtrics_code(code)
code
end.uniq
races = add_unknown_race_if_other_races_missing(races:)
races = remove_unknown_race_if_other_races_present(races:)
add_multiracial_designation(races:)
end
def remove_unknown_race_if_other_races_present(races:)
races.delete(Race.find_by_qualtrics_code(99)) if races.length > 1
races.delete(99) if races.length > 1
races
end
def add_multiracial_designation(races:)
races << Race.find_by_qualtrics_code(100) if races.length > 1
races << 100 if races.length > 1
races
end
def add_unknown_race_if_other_races_missing(races:)
races << Race.find_by_qualtrics_code(99) if races.length == 0
races << 99 if races.length == 0
races
end
end

@ -9,7 +9,7 @@ class SurveyResponsesDataLoader
file.lazy.each_slice(500) do |lines|
survey_item_responses = CSV.parse(lines.join, headers:).map do |row|
process_row(row: SurveyItemValues.new(row:, headers: headers_array, survey_items: all_survey_items, schools:),
process_row(row: SurveyItemValues.new(row:, headers: headers_array, survey_items: all_survey_items, schools:),
rules:)
end
SurveyItemResponse.import survey_item_responses.compact.flatten, batch_size: 500
@ -29,7 +29,7 @@ class SurveyResponsesDataLoader
next unless line.present?
CSV.parse(line, headers:).map do |row|
survey_item_responses << process_row(row: SurveyItemValues.new(row:, headers: headers_array, survey_items: all_survey_items, schools:),
survey_item_responses << process_row(row: SurveyItemValues.new(row:, headers: headers_array, survey_items: all_survey_items, schools:),
rules:)
end
@ -54,6 +54,10 @@ class SurveyResponsesDataLoader
@genders = Gender.by_qualtrics_code
end
def races
@races = Race.by_qualtrics_code
end
def incomes
@incomes ||= Income.by_slug
end
@ -78,6 +82,13 @@ class SurveyResponsesDataLoader
end
def process_survey_items(row:)
student = Student.find_or_create_by(response_id: row.response_id, lasid: row.lasid)
student.races.delete_all
tmp_races = row.races.map do |race| races[race] end
tmp_races.each do |race|
student.races << race
end
row.survey_items.map do |survey_item|
likert_score = row.likert_score(survey_item_id: survey_item.survey_item_id) || next

@ -1,8 +1,8 @@
Start Date,End Date,Response Type,IP Address,Progress,Duration (in seconds),Finished,RecordedDate,ResponseId,LASID,Recipient Last Name,Recipient First Name,Recipient Email,External Data Reference,Location Latitude,Location Longitude,Distribution Channel,User Language,district,school,DESE ID,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,s-emsa-q1,s-emsa-q2,s-emsa-q3,s-tint-q1,s-tint-q2,#N/A,s-tint-q4,s-tint-q5,s-acpr-q1,s-acpr-q2,s-acpr-q3,s-acpr-q4,#N/A,#N/A,s-cure-q3,s-cure-q4,#N/A,s-sten-q2,s-sten-q3,s-sper-q1,s-sper-q2,s-sper-q3,s-sper-q4,s-civp-q1,s-civp-q2,s-civp-q3,s-civp-q4,s-grmi-q1,#N/A,#N/A,s-grmi-q4,s-appa-q1,s-appa-q2,#N/A,s-peff-q1,s-peff-q2,s-peff-q3,s-peff-q4,s-peff-q5,s-peff-q6,s-sbel-q1,s-sbel-q2,s-sbel-q3,s-sbel-q4,s-sbel-q5,s-phys-q1,s-phys-q1-1,s-phys-q2,s-phys-q3,s-phys-q4,s-vale-q1,s-vale-q2,s-vale-q3,s-vale-q4,s-acst-q1,s-acst-q2,s-acst-q3,s-acst-q4,s-acst-q5,s-grit-q1,s-grit-q2,s-grit-q3,s-grit-q4,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,race,What is your race/ethnicity?(Please select all that apply) - Selected Choice,grade,gender,Raw Income,Income,Raw ELL,ELL,Raw SpEd
2020-09-29 18:28:41,2020-09-29 18:48:28,0,73.249.89.226,6,1186,0,2020-09-30T18:48:50,student_survey_response_1,123456,,,,,,,anonymous,EN,1,8,1500025,,,,dddd,4,3,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,3,0,some non-integer response,6,,,,5,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,EN,,,,,1,888,11th,1,Free Lunch,Economically Disadvantaged Y,Does not apply,Not ELL,exited
2021-02-23 15:12:58,2021-02-23 15:13:17,0,50.207.254.114,0,19,0,2021-02-24T15:13:19,student_survey_response_2,234567,,,,,,,anonymous,EN,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,NA,,,,,,,,,,,,,,,,,,,,,EN,,,,,"2,3,4",888,10,,Not Eligible,Economically Disadvantaged N,,Unknown,Unknown
2021-03-31 9:50:19,2021-03-31 9:59:01,0,108.7.17.250,100,522,1,2021-03-31T09:59:02,student_survey_response_3,345678,,,,,42.53340149,-70.96530151,anonymous,EN,3,2,1500505,12,4,108,3300,7,1,,,,,,,,,,,,,,2,4,2,1,4,3,3,,,,,3,3,3,3,,,,,NA,,,,,,,,,3,2,3,3,2,1,3,3,4,1,3,3,4,4,2,4,3,3,4,3,3,3,4,3,3,3,3,3,,,,,,,,,,3,4,4,2,3,3,1,,3,,EN,Math teacher,,,,6,888,8,2,Reduced Lunch,Economically Disadvantaged Y,,Unknown,Unknown
2021-02-23 15:12:58,2021-02-23 15:13:17,0,50.207.254.114,0,19,0,2021-02-24T15:13:19,student_survey_response_2,234567,,,,,,,anonymous,EN,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,NA,,,,,,,,,,,,,,,,,,,,,EN,,,,,,888,10,,Not Eligible,Economically Disadvantaged N,,Unknown,Unknown
2021-03-31 9:50:19,2021-03-31 9:59:01,0,108.7.17.250,100,522,1,2021-03-31T09:59:02,student_survey_response_3,345678,,,,,42.53340149,-70.96530151,anonymous,EN,3,2,1500505,12,4,108,3300,7,1,,,,,,,,,,,,,,2,4,2,1,4,3,3,,,,,3,3,3,3,,,,,NA,,,,,,,,,3,2,3,3,2,1,3,3,4,1,3,3,4,4,2,4,3,3,4,3,3,3,4,3,3,3,3,3,,,,,,,,,,3,4,4,2,3,3,1,,3,,EN,Math teacher,,,,"2,3,4",888,8,2,Reduced Lunch,Economically Disadvantaged Y,,Unknown,Unknown
2021-03-31 9:50:09,2021-03-31 10:00:16,0,67.186.188.168,100,607,1,2021-03-31T10:00:17,student_survey_response_4,456789,,,,,42.63510132,-71.30139923,anonymous,EN,3,2,1500505,12,18,108,2064,7,1,,2,2,1,,,,,,,,,,,,,,,,,,,,,,,,,3,5,3,3,,,,,,,,,,4,4,3,4,5,1,,1,5,1,3,2,4,4,1,2,1,3,2,3,3,3,4,2,5,3,4,5,5,3,3,4,3,,,,,4,4,4,4,3,5,2,,2,,EN,,,,English teacher,7,888,8,3,,Unknown,LEP student not 1st year,ELL,active
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_5,567890,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,"1,2,3,4,5,8,6,7",888,7,4,Free Lunch,Economically Disadvantaged Y,EL Student First Year,ELL,active
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_6,,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,"1,2,3,4,5,8",888,3,NA,Not Eligible,Economically Disadvantaged N,Unknown,Unknown,NA
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_7,,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,,,4,,Reduced Lunch,Economically Disadvantaged Y,#N/A,Unknown,
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_7,,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,5,,4,7,Reduced Lunch,Economically Disadvantaged Y,#N/A,Unknown,

1 Start Date End Date Response Type IP Address Progress Duration (in seconds) Finished RecordedDate ResponseId LASID Recipient Last Name Recipient First Name Recipient Email External Data Reference Location Latitude Location Longitude Distribution Channel User Language district school DESE ID #N/A #N/A #N/A #N/A #N/A #N/A #N/A s-emsa-q1 s-emsa-q2 s-emsa-q3 s-tint-q1 s-tint-q2 #N/A s-tint-q4 s-tint-q5 s-acpr-q1 s-acpr-q2 s-acpr-q3 s-acpr-q4 #N/A #N/A s-cure-q3 s-cure-q4 #N/A s-sten-q2 s-sten-q3 s-sper-q1 s-sper-q2 s-sper-q3 s-sper-q4 s-civp-q1 s-civp-q2 s-civp-q3 s-civp-q4 s-grmi-q1 #N/A #N/A s-grmi-q4 s-appa-q1 s-appa-q2 #N/A s-peff-q1 s-peff-q2 s-peff-q3 s-peff-q4 s-peff-q5 s-peff-q6 s-sbel-q1 s-sbel-q2 s-sbel-q3 s-sbel-q4 s-sbel-q5 s-phys-q1 s-phys-q1-1 s-phys-q2 s-phys-q3 s-phys-q4 s-vale-q1 s-vale-q2 s-vale-q3 s-vale-q4 s-acst-q1 s-acst-q2 s-acst-q3 s-acst-q4 s-acst-q5 s-grit-q1 s-grit-q2 s-grit-q3 s-grit-q4 #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A race What is your race/ethnicity?(Please select all that apply) - Selected Choice grade gender Raw Income Income Raw ELL ELL Raw SpEd
2 2020-09-29 18:28:41 2020-09-29 18:48:28 0 73.249.89.226 6 1186 0 2020-09-30T18:48:50 student_survey_response_1 123456 anonymous EN 1 8 1500025 dddd 4 3 3 0 some non-integer response 6 5 1 EN 1 888 11th 1 Free Lunch Economically Disadvantaged – Y Does not apply Not ELL exited
3 2021-02-23 15:12:58 2021-02-23 15:13:17 0 50.207.254.114 0 19 0 2021-02-24T15:13:19 student_survey_response_2 234567 anonymous EN NA EN 2,3,4 888 10 Not Eligible Economically Disadvantaged – N Unknown Unknown
4 2021-03-31 9:50:19 2021-03-31 9:59:01 0 108.7.17.250 100 522 1 2021-03-31T09:59:02 student_survey_response_3 345678 42.53340149 -70.96530151 anonymous EN 3 2 1500505 12 4 108 3300 7 1 2 4 2 1 4 3 3 3 3 3 3 NA 3 2 3 3 2 1 3 3 4 1 3 3 4 4 2 4 3 3 4 3 3 3 4 3 3 3 3 3 3 4 4 2 3 3 1 3 EN Math teacher 6 2,3,4 888 8 2 Reduced Lunch Economically Disadvantaged – Y Unknown Unknown
5 2021-03-31 9:50:09 2021-03-31 10:00:16 0 67.186.188.168 100 607 1 2021-03-31T10:00:17 student_survey_response_4 456789 42.63510132 -71.30139923 anonymous EN 3 2 1500505 12 18 108 2064 7 1 2 2 1 3 5 3 3 4 4 3 4 5 1 1 5 1 3 2 4 4 1 2 1 3 2 3 3 3 4 2 5 3 4 5 5 3 3 4 3 4 4 4 4 3 5 2 2 EN English teacher 7 888 8 3 Unknown LEP student not 1st year ELL active
6 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31T10:01:36 student_survey_response_5 567890 42.65820313 -71.30580139 anonymous EN 3 2 1500505 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher 1,2,3,4,5,8,6,7 888 7 4 Free Lunch Economically Disadvantaged – Y EL Student First Year ELL active
7 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31T10:01:36 student_survey_response_6 42.65820313 -71.30580139 anonymous EN 3 2 1500505 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher 1,2,3,4,5,8 888 3 NA Not Eligible Economically Disadvantaged – N Unknown Unknown NA
8 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31T10:01:36 student_survey_response_7 42.65820313 -71.30580139 anonymous EN 3 2 1500505 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher 5 4 7 Reduced Lunch Economically Disadvantaged – Y #N/A Unknown

@ -224,15 +224,15 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "1" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1]
expect(values.races).to eq [1]
row = { "Race" => "Native American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1]
expect(values.races).to eq [1]
row = { "Race" => "American Indian or Alaskan Native" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1]
expect(values.races).to eq [1]
end
end
@ -240,19 +240,19 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "2" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [2]
expect(values.races).to eq [2]
row = { "Race" => "Asian" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [2]
expect(values.races).to eq [2]
row = { "Race" => "Pacific Islander" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [2]
expect(values.races).to eq [2]
row = { "Race" => "Pacific Island or Hawaiian Native" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [2]
expect(values.races).to eq [2]
end
end
@ -260,15 +260,15 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "3" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [3]
expect(values.races).to eq [3]
row = { "Race" => "Black" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [3]
expect(values.races).to eq [3]
row = { "Race" => "African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [3]
expect(values.races).to eq [3]
end
end
@ -276,15 +276,15 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "4" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [4]
expect(values.races).to eq [4]
row = { "Race" => "Hispanic" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [4]
expect(values.races).to eq [4]
row = { "Race" => "Latinx" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [4]
expect(values.races).to eq [4]
end
end
@ -292,15 +292,15 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "5" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5]
expect(values.races).to eq [5]
row = { "Race" => "White" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5]
expect(values.races).to eq [5]
row = { "Race" => "Caucasian" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5]
expect(values.races).to eq [5]
end
end
@ -308,11 +308,11 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "6" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "Prefer not to disclose" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
end
end
@ -320,11 +320,11 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "6" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "Prefer not to disclose" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
end
end
@ -332,11 +332,11 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "7" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "Prefer to self-describe" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
end
end
@ -344,15 +344,15 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "8" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [8]
expect(values.races).to eq [8]
row = { "Race" => "Middle Eastern" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [8]
expect(values.races).to eq [8]
row = { "Race" => "North African" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [8]
expect(values.races).to eq [8]
end
end
@ -360,23 +360,23 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "NA" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "#N/A" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "n/a" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "#na" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
row = { "Race" => "" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [99]
expect(values.races).to eq [99]
end
end
@ -384,42 +384,42 @@ RSpec.describe SurveyItemValues, type: :model do
it "returns the gender that maps to the gender provided" do
row = { "Race" => "1,2,3" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
expect(values.races).to eq [1, 2, 3, 100]
row = { "Race" => "Alaskan Native, Pacific Islander, Black" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
expect(values.races).to eq [1, 2, 3, 100]
row = { "Race" => "American Indian or Alaskan Native, Asian, African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
expect(values.races).to eq [1, 2, 3, 100]
row = { "Race" => "n/a" }
row = { "Race" => "American Indian or Alaskan Native, Asian and African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
expect(values.races).to eq [1, 2, 3, 100]
row = { "Race" => "American Indian or Alaskan Native and Asian and African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
expect(values.races).to eq [1, 2, 3, 100]
row = { "Race" => "American Indian or Alaskan Native and Asian, and African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [1, 2, 3, 100]
expect(values.races).to eq [1, 2, 3, 100]
row = { "Race" => "Asian, Caucasian and African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [2, 5, 3, 100]
expect(values.races).to eq [2, 5, 3, 100]
row = { "Race" => "Caucasian and Asian and African American" }
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5, 2, 3, 100]
expect(values.races).to eq [5, 2, 3, 100]
row = { "Race- SIS" => "Caucasian and Asian and African American", "HispanicLatino" => "true" }
headers.push("HispanicLatino")
headers.push("Race- SIS")
values = SurveyItemValues.new(row:, headers:, survey_items:, schools:)
expect(values.races.map { |race| race&.qualtrics_code }).to eq [5, 2, 3, 4, 100]
expect(values.races).to eq [5, 2, 3, 4, 100]
end
end
end

@ -136,6 +136,7 @@ describe SurveyResponsesDataLoader do
assigns_gender_to_responses
assigns_income_to_responses
assigns_ell_to_responses
assigns_races_to_students
is_idempotent_for_students
end
@ -370,16 +371,17 @@ def assigns_ell_to_responses
end
end
def assigns_ell_to_responses
results = { "student_survey_response_1" => not_ell,
"student_survey_response_3" => unknown_ell,
"student_survey_response_4" => yes_ell,
"student_survey_response_5" => yes_ell,
"student_survey_response_6" => unknown_ell,
"student_survey_response_7" => unknown_ell }
def assigns_races_to_students
results = { #"student_survey_response_1" => [american_indian],
# "student_survey_response_3" => [asian, black, latinx, multiracial],
# "student_survey_response_4" => [unknown_race],
# "student_survey_response_5" => [american_indian, asian, black, latinx, white, middle_eastern, multiracial],
# "student_survey_response_6" => [american_indian, asian, black, latinx, white, middle_eastern, multiracial],
"student_survey_response_7" => [white] }
results.each do |key, value|
ell = SurveyItemResponse.find_by_response_id(key).ell
expect(ell).to eq value
race = SurveyItemResponse.find_by_response_id(key).student.races.to_a
qualtrics = race.map(&:qualtrics_code)
expect(race).to eq value
end
end

Loading…
Cancel
Save