Skip to content

Commit 57681f8

Browse files
author
clareconstantine
authored
Merge pull request code-dot-org#26881 from code-dot-org/fix-survey-results-error
Fix error loading survey results
2 parents cee370b + cc04f15 commit 57681f8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

dashboard/app/helpers/pd/workshop_survey_results_helper.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def generate_workshop_daily_session_summary(workshop)
206206

207207
related_workshops = find_related_workshops(workshop)
208208

209-
summary[:all_my_workshops] = generate_workshops_survey_summary(related_workshops, questions) if related_workshops
209+
summary[:all_my_workshops] = generate_workshops_survey_summary(related_workshops, questions) if related_workshops.present?
210210

211211
summary[:facilitators] = Hash[*workshop.facilitators.pluck(:id, :name).flatten]
212212

@@ -392,7 +392,11 @@ def generate_facilitator_averages(summary)
392392
# responses, which the reduce_summary function does (see below)
393393
flattened_this_workshop_histograms = reduce_summary(summary[:this_workshop].values.flat_map(&:values).select {|x| x.is_a? Hash})
394394

395-
flattened_all_my_workshop_histograms = reduce_summary(summary[:all_my_workshops].values.flat_map(&:values).select {|x| x.is_a? Hash})
395+
flattened_all_my_workshop_histograms = if summary[:all_my_workshops]
396+
reduce_summary(summary[:all_my_workshops].values.flat_map(&:values).select {|x| x.is_a? Hash})
397+
else
398+
{}
399+
end
396400

397401
# Questions are also sorted by day and general vs. facilitator - that distinction needs
398402
# to be removed. Then we need to map each response option to the value that we assign it
@@ -453,8 +457,8 @@ def generate_facilitator_averages(summary)
453457

454458
facilitator_averages[facilitator][question_group[:primary_id]] = {this_workshop: (total_answer_for_this_workshop_sum / total_responses_for_this_workshop.to_f).round(2)}
455459

456-
total_responses_for_all_workshops = histogram_for_all_my_workshops.values.reduce(:+) || 0
457-
total_answer_for_all_workshops_sum = histogram_for_all_my_workshops.map do |k, v|
460+
total_responses_for_all_workshops = histogram_for_all_my_workshops&.values&.reduce(:+) || 0
461+
total_answer_for_all_workshops_sum = histogram_for_all_my_workshops&.map do |k, v|
458462
option = question[:option_map][k]
459463

460464
if option.nil?
@@ -468,9 +472,11 @@ def generate_facilitator_averages(summary)
468472

469473
0
470474
end
471-
end.reduce(:+) || 0
475+
end&.reduce(:+) || 0
472476

473-
facilitator_averages[facilitator][question_group[:primary_id]][:all_my_workshops] = (total_answer_for_all_workshops_sum / total_responses_for_all_workshops.to_f).round(2)
477+
facilitator_averages[facilitator][question_group[:primary_id]][:all_my_workshops] = if total_answer_for_all_workshops_sum != 0 && total_responses_for_all_workshops != 0
478+
(total_answer_for_all_workshops_sum / total_responses_for_all_workshops.to_f).round(2)
479+
end
474480
end
475481

476482
# Finally, keep hold of the question text to render in the averages table

0 commit comments

Comments
 (0)