1
1
require 'portable_csv'
2
2
3
3
class ParticipantsController < ApplicationController
4
+ include PointVisualisation
4
5
before_action :set_organization , only : [ :index ]
5
6
6
7
def index
@@ -61,8 +62,6 @@ def index
61
62
def show
62
63
@user = User . find ( params [ :id ] )
63
64
authorize! :view_participant_information , @user
64
- # TODO: bit ugly
65
- @awarded_points = Hash [ AwardedPoint . where ( id : AwardedPoint . all_awarded ( @user ) ) . to_a . sort! . group_by ( &:course_id ) . map { |k , v | [ k , v . map ( &:name ) ] } ]
66
65
67
66
if current_user . administrator?
68
67
add_breadcrumb 'Participants' , :participants_path
@@ -71,27 +70,7 @@ def show
71
70
add_breadcrumb 'My stats' , participant_path ( @user )
72
71
end
73
72
74
- @courses = [ ]
75
- @missing_points = { }
76
- @percent_completed = { }
77
- @group_completion_ratios = { }
78
- for course_id in @awarded_points . keys
79
- course = Course . find ( course_id )
80
- if !course . hide_submissions?
81
- @courses << course
82
-
83
- awarded = @awarded_points [ course . id ]
84
- missing = AvailablePoint . course_points ( course ) . order! . map ( &:name ) - awarded
85
- @missing_points [ course_id ] = missing
86
-
87
- if awarded . size + missing . size > 0
88
- @percent_completed [ course_id ] = 100 * ( awarded . size . to_f / ( awarded . size + missing . size ) )
89
- else
90
- @percent_completed [ course_id ] = 0
91
- end
92
- @group_completion_ratios [ course_id ] = course . exercise_group_completion_ratio_for_user ( @user )
93
- end
94
- end
73
+ define_point_stats ( @user )
95
74
96
75
if current_user . administrator? || current_user . id == @user . id
97
76
@submissions = @user . submissions . order ( 'created_at DESC' ) . includes ( :user ) . includes ( :course )
@@ -102,7 +81,6 @@ def show
102
81
@submissions = @submissions . limit ( 100 ) unless !!params [ :view_all ]
103
82
104
83
Submission . eager_load_exercises ( @submissions )
105
-
106
84
end
107
85
108
86
def me
0 commit comments