@@ -206,7 +206,7 @@ def generate_workshop_daily_session_summary(workshop)
206
206
207
207
related_workshops = find_related_workshops ( workshop )
208
208
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?
210
210
211
211
summary [ :facilitators ] = Hash [ *workshop . facilitators . pluck ( :id , :name ) . flatten ]
212
212
@@ -392,7 +392,11 @@ def generate_facilitator_averages(summary)
392
392
# responses, which the reduce_summary function does (see below)
393
393
flattened_this_workshop_histograms = reduce_summary ( summary [ :this_workshop ] . values . flat_map ( &:values ) . select { |x | x . is_a? Hash } )
394
394
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
396
400
397
401
# Questions are also sorted by day and general vs. facilitator - that distinction needs
398
402
# 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)
453
457
454
458
facilitator_averages [ facilitator ] [ question_group [ :primary_id ] ] = { this_workshop : ( total_answer_for_this_workshop_sum / total_responses_for_this_workshop . to_f ) . round ( 2 ) }
455
459
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 |
458
462
option = question [ :option_map ] [ k ]
459
463
460
464
if option . nil?
@@ -468,9 +472,11 @@ def generate_facilitator_averages(summary)
468
472
469
473
0
470
474
end
471
- end . reduce ( :+ ) || 0
475
+ end & .reduce ( :+ ) || 0
472
476
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
474
480
end
475
481
476
482
# Finally, keep hold of the question text to render in the averages table
0 commit comments