Skip to content

Commit

Permalink
correctly label choice task and pairwise comparison options
Browse files Browse the repository at this point in the history
  • Loading branch information
kodvinci committed Dec 6, 2023
1 parent e1fa3c0 commit 2bcca41
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 40 additions & 1 deletion app/models/survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ def option_labels(response)
labels << vq.options.map { |o| sanitize o.text }
else
response.text.split(Settings.list_delimiter).each do |option_index|
labels << if vq.other? && option_index.to_i == vq.other_index
labels << if vq.question_type == 'CHOICE_TASK'
choice_task_labels(vq, option_index.to_i)
elsif vq.question_type == 'PAIRWISE_COMPARISON'
pairwise_comparison_labels(vq, option_index)
elsif vq.other? && option_index.to_i == vq.other_index
'Other'
else
sanitize(label_text(vq, option_index))
Expand All @@ -196,6 +200,41 @@ def option_labels(response)
labels.join(Settings.list_delimiter)
end

def choice_task_labels(question, index)
label = ''
oios = question.option_set.option_in_option_sets[index]
oios.option_collages.each do |oc|
label += ' || ' if label.present?
oc.collage.diagrams.each do |d|
label += d.option.identifier
label += ' & ' unless d == oc.collage.diagrams.last
end
end
"(#{label})"
end

def pairwise_comparison_labels(question, index)
option_identifiers = []
question.option_in_option_sets.each do |oios|
oios.option_collages.each do |oc|
oc.collage.diagrams.each do |d|
option_identifiers << d.option.identifier
end
end
end
if index == '1.0'
"Strongly prefer #{option_identifiers[0]}"
elsif index == '2.0'
"Somewhat prefer #{option_identifiers[0]}"
elsif index == '3.0'
"No preference between #{option_identifiers[0]} and #{option_identifiers[1]}"
elsif index == '4.0'
"Somewhat prefer #{option_identifiers[1]}"
elsif index == '5.0'
"Strongly prefer #{option_identifiers[1]}"
end
end

def label_text(versioned_question, option_index)
versioned_question.options[option_index.to_i].try(:text)
end
Expand Down
2 changes: 2 additions & 0 deletions app/workers/survey_export_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class SurveyExportWorker

def perform(survey_uuid)
survey = Survey.includes(:responses).where(uuid: survey_uuid).try(:first)
return unless survey

SurveyExport.create(survey_id: survey.id) unless survey.survey_export
survey.reload

Expand Down

0 comments on commit 2bcca41

Please sign in to comment.