Show parent response rate

This commit is contained in:
Nelson Jovel 2024-10-31 20:05:26 -07:00
parent 7d4db37ee7
commit 0c661930e9
14 changed files with 113 additions and 50 deletions

View file

@ -67,11 +67,7 @@ class SurveyItemValues
end
def survey_item_response(survey_item:)
@survey_item_response ||= Hash.new do |memo, survey_item|
memo[survey_item] = survey_item_responses[[response_id, survey_item.id]]
end
@survey_item_response[survey_item]
survey_item_responses[[response_id, survey_item.id]]
end
def survey_item_responses
@ -192,6 +188,10 @@ class SurveyItemValues
@sped ||= Sped.to_designation(raw_sped)
end
def number_of_children
@number_of_children ||= value_from(pattern: /Number\s*Of\s*Children/i).to_i
end
def value_from(pattern:)
output = nil
matches = headers.select do |header|

View file

@ -87,10 +87,20 @@ 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 { |race| races[race] }
student.races += tmp_races
student = nil
parent = nil
if row.respondent_type == :student
student = Student.find_or_create_by(response_id: row.response_id, lasid: row.lasid)
student.races.delete_all
tmp_races = row.races.map { |race| races[race] }
student.races += tmp_races
end
if row.respondent_type == :parent
parent = Parent.find_or_create_by(response_id: row.response_id)
parent.number_of_children = row.number_of_children
parent.save
end
row
.survey_items
@ -103,12 +113,12 @@ class SurveyResponsesDataLoader
end
response = row.survey_item_response(survey_item:)
create_or_update_response(survey_item_response: response, likert_score:, row:, survey_item:, student:)
create_or_update_response(survey_item_response: response, likert_score:, row:, survey_item:, student:, parent:)
end
.compact
end
def create_or_update_response(survey_item_response:, likert_score:, row:, survey_item:, student:)
def create_or_update_response(survey_item_response:, likert_score:, row:, survey_item:, student:, parent:)
gender = genders[row.gender]
grade = row.grade
income = incomes[row.income.parameterize]
@ -124,6 +134,8 @@ class SurveyResponsesDataLoader
survey_item_response.ell = ell
survey_item_response.sped = sped
survey_item_response.student = student
survey_item_response.parent = parent
survey_item_response
else
SurveyItemResponse.new(
@ -138,7 +150,8 @@ class SurveyResponsesDataLoader
income:,
ell:,
sped:,
student:
student:,
parent:
)
end
end