Class: Sorting::GuideProgress::ByMessages
- Defined in:
- lib/mumuki/classroom/models/sorting/guide_progress.rb
Class Method Summary collapse
- .add_progress_count ⇒ Object
- .filter_guide_assignments ⇒ Object
- .filter_unread_notifications ⇒ Object
- .generate_guide_progress ⇒ Object
- .group_by_students_uid ⇒ Object
- .lookup_assignments ⇒ Object
- .lookup_notifications ⇒ Object
- .order_by(ordering) ⇒ Object
- .pipeline ⇒ Object
- .progress_to_document_root ⇒ Object
- .unwind_notifications ⇒ Object
Class Method Details
.add_progress_count ⇒ Object
22 23 24 25 26 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 22 def self.add_progress_count { 'progresses.unread': '$count' } end |
.filter_guide_assignments ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 50 def self.filter_guide_assignments { 'assignments': { '$filter': { 'as': 'assignment', 'input': '$assignments', 'cond': { '$eq': %w($$assignment.guide.slug $guide.slug), } } } } end |
.filter_unread_notifications ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 80 def self.filter_unread_notifications { 'notifications': { '$filter': { 'as': 'notification', 'input': '$notifications', 'cond': { '$and': [ {'$eq': %w($$notification.organization $organization)}, {'$eq': %w($$notification.sender $student.uid)}, {'$eq': %w($$notification.course $course)}, {'$eq': ['$$notification.read', false]} ] } } } } end |
.generate_guide_progress ⇒ Object
28 29 30 31 32 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 28 def self.generate_guide_progress { 'progresses': {'$arrayElemAt': ['$progresses', 0]}, } end |
.group_by_students_uid ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 34 def self.group_by_students_uid { '_id': '$student.uid', 'progresses': {'$push': '$$ROOT'}, 'count': { '$sum': { '$cond': { 'if': {'$anyElementTrue': ['$assignments']}, 'then': 1, 'else': 0 } } } } end |
.lookup_assignments ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 64 def self.lookup_assignments { 'from': 'assignments', 'localField': 'notifications.assignment_id', 'foreignField': '_id', 'as': 'assignments' } end |
.lookup_notifications ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 99 def self.lookup_notifications { 'from': 'notifications', 'localField': 'organization', 'foreignField': 'organization', 'as': 'notifications' } end |
.order_by(ordering) ⇒ Object
108 109 110 111 112 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 108 def self.order_by(ordering) {'unread': ordering, 'student.last_name': ordering, 'student.first_name': ordering} end |
.pipeline ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 4 def self.pipeline [ {'$lookup': lookup_notifications}, {'$addFields': filter_unread_notifications}, {'$unwind': unwind_notifications}, {'$lookup': lookup_assignments}, {'$addFields': filter_guide_assignments}, {'$group': group_by_students_uid}, {'$addFields': generate_guide_progress}, {'$addFields': add_progress_count}, {'$replaceRoot': progress_to_document_root}, ] end |
.progress_to_document_root ⇒ Object
18 19 20 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 18 def self.progress_to_document_root {'newRoot': '$progresses'} end |
.unwind_notifications ⇒ Object
73 74 75 76 77 78 |
# File 'lib/mumuki/classroom/models/sorting/guide_progress.rb', line 73 def self.unwind_notifications { 'path': '$notifications', 'preserveNullAndEmptyArrays': true } end |