diff --git a/lib/analytics/course_students_csv_builder.rb b/lib/analytics/course_students_csv_builder.rb index 82913f6438..43e24729bf 100644 --- a/lib/analytics/course_students_csv_builder.rb +++ b/lib/analytics/course_students_csv_builder.rb @@ -29,28 +29,40 @@ def generate_csv def populate_training_data courses_users.each do |courses_user| - training_progress = @training_progress_manager.course_training_progress(courses_user.user) - - unless training_progress.is_a?(Hash) - # Set default values if no training assigned or course is before Spring 2016 - @training_data[courses_user.user_id] = { - completed_count: "0", - assigned_count: "0", - modules: "" - } - next - end + populate_user_training_data(courses_user) + end + end - completed_modules = @training_progress_manager.completed_training_modules_names(courses_user.user).join(', ') + def populate_user_training_data(courses_user) + training_progress = @training_progress_manager.course_training_progress(courses_user.user) - @training_data[courses_user.user_id] = { - completed_count: training_progress[:completed_count], - assigned_count: training_progress[:assigned_count], - modules: completed_modules - } + if training_progress.is_a?(Hash) + completed_modules = @training_progress_manager + .completed_training_modules_names(courses_user.user) + .join(', ') + set_training_data(courses_user.user_id, training_progress[:completed_count], + training_progress[:assigned_count], completed_modules) + else + default_training_data(courses_user.user_id) end end + def set_training_data(user_id, completed_count, assigned_count, completed_modules) + @training_data[user_id] = { + completed_count:, + assigned_count:, + modules: completed_modules + } + end + + def default_training_data(user_id) + @training_data[user_id] = { + completed_count: '0', + assigned_count: '0', + modules: '' + } + end + def populate_created_articles # A user has created an article during the course if # the user is in the user_ids of new_articles_courses