mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-13 01:10:39 -07:00
chore: since it's now possible for there to be multiple district and dese id columns separated by a dash and a number, be more explicit when we only want to filter out survey item ids that end in a -1
This commit is contained in:
parent
a3f9e46414
commit
1b82ff9413
2 changed files with 16 additions and 17 deletions
|
|
@ -43,7 +43,7 @@ class Cleaner
|
|||
log_csv = []
|
||||
data = []
|
||||
|
||||
headers = CSV.parse(file.first).first.push("Raw Income").push("Income").push("Raw ELL").push("ELL").push("Raw SpEd").push("SpEd").push("Progress Count")
|
||||
headers = CSV.parse(file.first).first.push("Raw Income").push("Income").push("Raw ELL").push("ELL").push("Raw SpEd").push("SpEd").push("Progress Count").uniq
|
||||
filtered_headers = include_all_headers(headers:)
|
||||
filtered_headers = remove_unwanted_headers(headers: filtered_headers)
|
||||
log_headers = (filtered_headers + ["Valid Duration?", "Valid Progress?", "Valid Grade?",
|
||||
|
|
@ -70,7 +70,7 @@ class Cleaner
|
|||
|
||||
def include_all_headers(headers:)
|
||||
alternates = headers.filter(&:present?)
|
||||
.filter { |header| header.end_with? "-1" }
|
||||
.filter { |header| header.match? /^[st]-\w*-\w*-1$/i }
|
||||
alternates.each do |header|
|
||||
main = header.sub(/-1\z/, "")
|
||||
headers.push(main) unless headers.include?(main)
|
||||
|
|
@ -86,7 +86,7 @@ class Cleaner
|
|||
def remove_unwanted_headers(headers:)
|
||||
headers.to_set.to_a.compact.reject do |item|
|
||||
item.start_with? "Q"
|
||||
end.reject { |item| item.end_with? "-1" }
|
||||
end.reject { |header| header.match? /^[st]-\w*-\w*-1$/i }
|
||||
end
|
||||
|
||||
def write_csv(data:, output_filepath:, filename:, prefix: "")
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class SurveyItemValues
|
|||
# We don't ensure that ids in the form of s-tint-q1 have a matching pair because not all questions have variants
|
||||
def include_all_headers(headers:)
|
||||
alternates = headers.filter(&:present?)
|
||||
.filter { |header| header.end_with? "-1" }
|
||||
.filter { |header| header.match?(/^[st]-\w*-\w*-1$/i) }
|
||||
alternates.each do |header|
|
||||
main = header.sub(/-1\z/, "")
|
||||
headers.push(main) unless headers.include?(main)
|
||||
|
|
@ -192,11 +192,14 @@ class SurveyItemValues
|
|||
output
|
||||
end
|
||||
|
||||
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) }
|
||||
end
|
||||
|
||||
def to_a
|
||||
headers.select(&:present?)
|
||||
.reject { |key, _value| key.start_with? "Q" }
|
||||
.reject { |key, _value| key.end_with? "-1" }
|
||||
.map { |header| row[header] }
|
||||
sanitized_headers.map { |header| row[header] }
|
||||
end
|
||||
|
||||
def duration
|
||||
|
|
@ -216,12 +219,11 @@ class SurveyItemValues
|
|||
end
|
||||
|
||||
def survey_type
|
||||
survey_item_ids = headers
|
||||
.filter(&:present?)
|
||||
.reject { |header| header.end_with?("-1") }
|
||||
.filter { |header| header.start_with?("t-", "s-") }
|
||||
@survey_type ||= SurveyItem.survey_type(survey_item_ids:)
|
||||
end
|
||||
|
||||
SurveyItem.survey_type(survey_item_ids:)
|
||||
def survey_item_ids
|
||||
@survey_item_ids ||= sanitized_headers.filter { |header| header.start_with?("t-", "s-") }
|
||||
end
|
||||
|
||||
def valid_duration?
|
||||
|
|
@ -236,10 +238,7 @@ class SurveyItemValues
|
|||
end
|
||||
|
||||
def progress
|
||||
headers.filter(&:present?)
|
||||
.reject { |header| header.end_with?("-1") }
|
||||
.filter { |header| header.start_with?("t-", "s-") }
|
||||
.reject { |header| row[header].nil? }.count
|
||||
survey_item_ids.reject { |header| row[header].nil? }.count
|
||||
end
|
||||
|
||||
def valid_progress?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue