feat: add parent survey gauges

This commit is contained in:
Nelson Jovel 2024-09-05 16:20:25 -07:00
parent 695f8b69a2
commit c85ddddd8d
12 changed files with 305 additions and 9 deletions

View file

@ -27,7 +27,7 @@ class Cleaner
def filename(headers:, data:, filepath:)
output = []
survey_item_ids = headers.filter(&:present?).filter do |header|
header.start_with?("s-", "t-")
header.start_with?("s-", "t-", "p-")
end.reject { |item| item.end_with? "-1" }
survey_type = SurveyItem.survey_type(survey_item_ids:)
range = data.first.academic_year.range
@ -129,7 +129,7 @@ class Cleaner
def remove_unwanted_headers(headers:)
headers.to_set.to_a.compact.reject do |item|
item.start_with? "Q"
end.reject { |header| header.match?(/^[st]-\w*-\w*-1$/i) }
end.reject { |header| header.match?(/^[stp]-\w*-\w*-1$/i) }
end
def write_csv(data:, output_filepath:, filename:, prefix: "")
@ -152,7 +152,7 @@ class Cleaner
def survey_items(headers:)
survey_item_ids = headers
.filter(&:present?)
.filter { |header| header.start_with? "t-", "s-" }
.filter { |header| header.start_with? "t-", "s-", "p-" }
@survey_items ||= SurveyItem.where(survey_item_id: survey_item_ids)
end

View file

@ -208,7 +208,7 @@ class SurveyItemValues
def sanitized_headers
@sanitized_headers ||= headers.select(&:present?)
.reject { |key, _value| key.start_with? "Q" }
.reject { |key, _value| key.match?(/^[st]-\w*-\w*-1$/i) }
.reject { |key, _value| key.match?(/^[stp]-\w*-\w*-1$/i) }
end
def to_a
@ -228,6 +228,10 @@ class SurveyItemValues
.filter(&:present?)
.filter { |header| header.start_with? "t-" }.count > 0
return :parent if headers
.filter(&:present?)
.filter { |header| header.start_with? "p-" }.count > 0
:student
end
@ -236,7 +240,7 @@ class SurveyItemValues
end
def survey_item_ids
@survey_item_ids ||= sanitized_headers.filter { |header| header.start_with?("t-", "s-") }
@survey_item_ids ||= sanitized_headers.filter { |header| header.start_with?("t-", "s-", "p-") }
end
def valid_duration?
@ -246,6 +250,7 @@ class SurveyItemValues
return span_in_seconds >= 300 if survey_type == :teacher
return span_in_seconds >= 240 if survey_type == :standard
return span_in_seconds >= 100 if survey_type == :short_form
return span_in_seconds >= 120 if survey_type == :parent
true
end
@ -261,6 +266,7 @@ class SurveyItemValues
return progress >= 11 if survey_type == :standard
return progress >= 5 if survey_type == :short_form
return progress >= 5 if survey_type == :early_education
return true if survey_type == :parent
false
end
@ -269,6 +275,7 @@ class SurveyItemValues
return true if grade.nil?
return true if respondent_type == :teacher
return true if survey_type == :parent
respondents = Respondent.where(school:, academic_year:).first
if respondents.present? && respondents.enrollment_by_grade[grade].present?
@ -283,6 +290,7 @@ class SurveyItemValues
def valid_sd?
return true if survey_type == :early_education
return true if survey_type == :parent
survey_item_headers = headers.filter(&:present?).filter { |header| header.start_with?("s-", "t-") }
likert_scores = []

View file

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