Class: Gaku::Exam
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gaku::Exam
- Includes:
- Notes, Pagination
- Defined in:
- app/models/gaku/exam.rb
Class Method Summary collapse
Instance Method Summary collapse
- #completed_by_student?(student) ⇒ Boolean
- #completed_by_students(students) ⇒ Object
- #completion(students) ⇒ Object
- #max_score ⇒ Object
- #total_records(students) ⇒ Object
- #total_weight ⇒ Object
- #total_weight_except(portion) ⇒ Object
- #ungraded(students) ⇒ Object
Class Method Details
.without_syllabuses ⇒ Object
29 30 31 32 |
# File 'app/models/gaku/exam.rb', line 29 def self.without_syllabuses includes(:syllabuses).where(standalone: false) .select { |p| p.syllabuses.length == 0 } end |
Instance Method Details
#completed_by_student?(student) ⇒ Boolean
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/gaku/exam.rb', line 87 def completed_by_student?(student) state = true exam_portions.each do |ep| student_eps = ep.exam_portion_scores.find do |eps| eps.student_id == student.id end state = false if check_record_completion?(student_eps) end state end |
#completed_by_students(students) ⇒ Object
78 79 80 81 82 83 84 |
# File 'app/models/gaku/exam.rb', line 78 def completed_by_students(students) completed = [] students.each do |student| completed.append(student.id) if self.completed_by_student?(student) end completed end |
#completion(students) ⇒ Object
52 53 54 55 56 |
# File 'app/models/gaku/exam.rb', line 52 def completion(students) total_records = total_records(students) completion_ratio = 1 - (ungraded(students) / total_records.to_f) (completion_ratio * 100).round(2) end |
#max_score ⇒ Object
48 49 50 |
# File 'app/models/gaku/exam.rb', line 48 def max_score exam_portions.reduce(0) { |sum, p| sum + p.max_score } end |
#total_records(students) ⇒ Object
74 75 76 |
# File 'app/models/gaku/exam.rb', line 74 def total_records(students) exam_portions.count * students.count end |
#total_weight ⇒ Object
34 35 36 |
# File 'app/models/gaku/exam.rb', line 34 def total_weight exam_portions.reduce(0) { |sum, p| p.weight ? sum + p.weight : sum } end |
#total_weight_except(portion) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/models/gaku/exam.rb', line 38 def total_weight_except(portion) exam_portions.reduce(0) do |sum, p| if portion == p sum else p.weight ? sum + p.weight : sum end end end |
#ungraded(students) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/models/gaku/exam.rb', line 58 def ungraded(students) ungraded = 0 students.each do |student| student_exam_eps = exam_portion_scores.select do |eps| eps.student_id == student.id end student_exam_eps.each do |eps| ungraded += 1 if check_record_completion?(eps) end end ungraded end |