fix: make sure all likert scores get counted even when the survey item id has different capitalization. Add tests for uploading parent data. Change the parent response rate calcuation to count all students in the school instead of just for the grades that were given the student survey

This commit is contained in:
Nelson Jovel 2024-11-08 15:36:34 -08:00
parent 2994cd8df9
commit beb93aa8e8
12 changed files with 196 additions and 50 deletions

View file

@ -3,8 +3,8 @@ class SurveyItemValues
def initialize(row:, headers:, survey_items:, schools:, academic_years: AcademicYear.all)
@row = row
# Remove any newlines in headers
headers = headers.map { |item| item.delete("\n") if item.present? }
# Remove any newlines in headers and
@headers = normalize_headers(headers:)
@headers = include_all_headers(headers:)
@survey_items = survey_items
@schools = schools
@ -25,6 +25,13 @@ class SurveyItemValues
copy_data_to_main_column(main: /Gender/i, secondary: /Gender Secondary|Gender-1/i)
end
def normalize_headers(headers:)
headers
.select(&:present?)
.map { |item| item.strip }
.map { |item| item.downcase if item.match(/[stp]-/i) }
end
def copy_data_to_main_column(main:, secondary:)
main_column = headers.find { |header| main.match(header) }
row[main_column] = value_from(pattern: secondary) if row[main_column].nil?
@ -97,7 +104,7 @@ class SurveyItemValues
end
def likert_score(survey_item_id:)
row[survey_item_id] || row["#{survey_item_id}-1"]
row[survey_item_id] || row["#{survey_item_id}-1"] || value_from(pattern: /#{survey_item_id}/i)
end
def school
@ -196,7 +203,7 @@ class SurveyItemValues
output = nil
matches = headers.select do |header|
pattern.match(header)
end.map { |item| item.delete("\n") }
end
matches.each do |match|
output ||= row[match]&.strip

View file

@ -165,6 +165,7 @@ class SurveyResponsesDataLoader
.parse(headers)
.first
.filter(&:present?)
.map(&:downcase)
.filter { |header| header.start_with?("t-", "s-", "p-") }
end
end