mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-08 23:18:18 -07:00
Fix: make sure values don't get reordered after copying over row values from survey item variants. This fixes a problem where cleaner would produce a row with likert scores that got shifted to align with the wrong column
This commit is contained in:
parent
ed421ceea8
commit
c4b90a711c
1 changed files with 16 additions and 23 deletions
|
|
@ -51,7 +51,7 @@ class SurveyItemValues
|
|||
def dese_id
|
||||
@dese_id ||= begin
|
||||
dese_id = nil
|
||||
dese_headers = ['DESE ID', 'Dese ID', 'DeseId', 'DeseID', 'School', 'school']
|
||||
dese_headers = ["DESE ID", "Dese ID", "DeseId", "DeseID", "School", "school"]
|
||||
school_headers = headers.select { |header| /School-\s\w/.match(header) }
|
||||
dese_headers << school_headers
|
||||
dese_headers.flatten.each do |header|
|
||||
|
|
@ -106,7 +106,10 @@ class SurveyItemValues
|
|||
|
||||
def to_a
|
||||
copy_likert_scores_from_variant_survey_items
|
||||
row.remove_unwanted_columns
|
||||
headers.select(&:present?)
|
||||
.reject { |key, _value| key.start_with? "Q" }
|
||||
.reject { |key, _value| key.end_with? "-1" }
|
||||
.map { |header| row[header] }
|
||||
end
|
||||
|
||||
def duration
|
||||
|
|
@ -119,23 +122,23 @@ class SurveyItemValues
|
|||
|
||||
def respondent_type
|
||||
return :teacher if headers
|
||||
.filter(&:present?)
|
||||
.filter { |header| header.start_with? 't-' }.count > 0
|
||||
.filter(&:present?)
|
||||
.filter { |header| header.start_with? "t-" }.count > 0
|
||||
|
||||
:student
|
||||
end
|
||||
|
||||
def survey_type
|
||||
survey_item_ids = headers
|
||||
.filter(&:present?)
|
||||
.reject { |header| header.end_with?('-1') }
|
||||
.filter { |header| header.start_with?('t-', 's-') }
|
||||
.filter(&:present?)
|
||||
.reject { |header| header.end_with?("-1") }
|
||||
.filter { |header| header.start_with?("t-", "s-") }
|
||||
|
||||
SurveyItem.survey_type(survey_item_ids:)
|
||||
end
|
||||
|
||||
def valid_duration?
|
||||
return true if duration.nil? || duration == '' || duration.downcase == 'n/a' || duration.downcase == 'na'
|
||||
return true if duration.nil? || duration == "" || duration.downcase == "n/a" || duration.downcase == "na"
|
||||
|
||||
span_in_seconds = duration.to_i
|
||||
return span_in_seconds >= 300 if survey_type == :teacher
|
||||
|
|
@ -146,8 +149,8 @@ class SurveyItemValues
|
|||
end
|
||||
|
||||
def valid_progress?
|
||||
progress = row['Progress']
|
||||
return true if progress.nil? || progress == '' || progress.downcase == 'n/a' || progress.downcase == 'na'
|
||||
progress = row["Progress"]
|
||||
return true if progress.nil? || progress == "" || progress.downcase == "n/a" || progress.downcase == "na"
|
||||
|
||||
progress = progress.to_i
|
||||
progress.to_i >= 25
|
||||
|
|
@ -172,7 +175,7 @@ class SurveyItemValues
|
|||
def valid_sd?
|
||||
return true if survey_type == :early_education
|
||||
|
||||
survey_item_headers = headers.filter(&:present?).filter { |header| header.start_with?('s-', 't-') }
|
||||
survey_item_headers = headers.filter(&:present?).filter { |header| header.start_with?("s-", "t-") }
|
||||
likert_scores = []
|
||||
survey_item_headers.each do |header|
|
||||
likert_scores << likert_score(survey_item_id: header).to_i
|
||||
|
|
@ -190,20 +193,10 @@ class SurveyItemValues
|
|||
private
|
||||
|
||||
def copy_likert_scores_from_variant_survey_items
|
||||
headers.filter(&:present?).filter { |header| header.end_with? '-1' }.each do |header|
|
||||
headers.filter(&:present?).filter { |header| header.end_with? "-1" }.each do |header|
|
||||
likert_score = row[header]
|
||||
main_item = header.gsub('-1', '')
|
||||
main_item = header.gsub("-1", "")
|
||||
row[main_item] = likert_score if likert_score.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module RowMonkeyPatches
|
||||
def remove_unwanted_columns
|
||||
to_h.filter do |key, _value|
|
||||
key.present?
|
||||
end.reject { |key, _value| key.start_with? 'Q' }.reject { |key, _value| key.end_with? '-1' }.values
|
||||
end
|
||||
end
|
||||
|
||||
CSV::Row.include RowMonkeyPatches
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue