-
Notifications
You must be signed in to change notification settings - Fork 11
/
offering_student_status.rb
85 lines (72 loc) · 2.23 KB
/
offering_student_status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
class Report::OfferingStudentStatus
attr_accessor :learner
attr_accessor :student
attr_accessor :offering
# loosely based on offering_status.rb#student_activities
def sub_sections
runnable = offering.runnable
if runnable.is_a?(::ExternalActivity) && runnable.template
runnable = runnable.template
end
if runnable.is_a? ::Investigation
runnable.activities.student_only
else
[runnable]
end
end
def display_report_link?
(offering && offering.student_report_enabled? && offering_reportable?)
end
def offering_reportable?
(offering && offering.individual_reportable?)
end
# this is redundant with the Report::Learner object, but that object doesn't handle
# students that don't have learners for the offering
def complete_percent
if learner
# check if this is a reportable thing, if not then base the percent on the existance of the learner
if offering_reportable?
learner.report_learner.complete_percent || 0
else
# return 99.99 because all we can tell is whether it is in progress
# if we return 100 then the progress bar will indicate it is compelete
# 99.99 is enough to fill up the progress bar but keep the in_progress color
99.99
end
else
0
end
end
def number_correct
if learner && offering_reportable?
num_correct = learner.report_learner.num_correct || 0
else
nil
end
end
# the runnable is passed because in somecases we want the progress for a sub part of the
# this learners runnable
def activity_complete_percent(activity)
if learner
# this is not efficient it has to do queries for each activity
learner_activity = learner.learner_activities.find{|la| la.activity_id == activity.id}
# Since there is a learner for this it actually has been started so perhaps
# we shouldn't return 0 here
learner_activity ? learner_activity.complete_percent : 0
else
0
end
end
def last_run
if learner
return learner.report_learner.last_run
end
return nil
end
def never_run
return last_run ? false : true
end
def last_run_string(opts={})
Report::Learner.build_last_run_string(last_run, opts)
end
end