Module: WithSubmissionProcess

Included in:
Mumuki::Classroom::Submission
Defined in:
lib/mumuki/classroom/models/concerns/with_submission_process.rb

Instance Method Summary collapse

Instance Method Details

#assignment_from(json) ⇒ Object



89
90
91
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 89

def assignment_from(json)
  assignment_without_submission_from.merge submission: submission_from(json)
end

#assignment_query(json) ⇒ Object



44
45
46
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 44

def assignment_query(json)
  guide_progress_query(json).merge 'exercise.eid': exercise_from(json)[:eid]
end

#assignment_without_submission_from(json) ⇒ Object



83
84
85
86
87
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 83

def assignment_without_submission_from(json)
  {guide: guide_from(json),
   student: student_from(json),
   exercise: exercise_from(json)}
end

#course_slug(json) ⇒ Object



71
72
73
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 71

def course_slug(json)
  json[:course]
end

#exercise_from(json) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 120

def exercise_from(json)
  exercise = json[:exercise]

  {eid: exercise[:eid],
   name: exercise[:name],
   number: exercise[:number]}.compact
end

#find_student_from(json) ⇒ Object



24
25
26
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 24

def find_student_from(json)
  Mumuki::Classroom::Student.find_by(organization: organization(json), course: course_slug(json), uid: uid(json))
end

#find_submission_course!(json) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


18
19
20
21
22
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 18

def find_submission_course!(json)
  student = Mumuki::Classroom::Student.last_updated_student_by(organization: organization(json), uid: uid(json))
  raise ActiveRecord::RecordNotFound, "Mumuki::Classroom::Student not found" unless student
  student.course
end

#guide_from(json) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 105

def guide_from(json)
  guide = json[:guide]

  classroom_guide = {
    slug: guide[:slug],
    name: guide[:name],
    parent: guide[:parent],
    language: {
      name: guide[:language][:name],
      devicon: guide[:language][:devicon]
    }.compact
  }
  classroom_guide.compact
end

#guide_progress_from(json) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 75

def guide_progress_from(json)
  {guide: guide_from(json),
   student: student_from(json),
   stats: stats_from(json),
   last_assignment: {exercise: exercise_from(json),
                     submission: submission_from(json)}}
end

#guide_progress_query(json) ⇒ Object



48
49
50
51
52
53
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 48

def guide_progress_query(json)
  {'organization': organization(json),
   'course': course_slug(json),
   'guide.slug': guide_from(json)[:slug],
   'student.uid': uid(json)}
end

#organization(json) ⇒ Object



14
15
16
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 14

def organization(json)
  json[:organization]
end

#process!(data) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 2

def process!(data)
  json = data.deep_symbolize_keys

  json[:course] = find_submission_course! json
  json[:student] = find_student_from json

  update_assignment json
  update_guide_progress json
  update_student_progress json
  update_student_last_assignment json
end

#stats_from(json) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 93

def stats_from(json)
  stats = json[:stats]

  {passed: stats[:passed],
   failed: stats[:failed],
   passed_with_warnings: stats[:passed_with_warnings]}.compact
end

#student_from(json) ⇒ Object



101
102
103
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 101

def student_from(json)
  json[:student].as_submission_json
end

#student_stats_for(json) ⇒ Object



63
64
65
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 63

def student_stats_for(json)
  Mumuki::Classroom::Assignment.stats_by guide_progress_query(json)
end

#submission_from(json) ⇒ Object



128
129
130
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 128

def submission_from(json)
  Mumuki::Classroom::FailedSubmission.new(json).as_assignment_submission
end

#uid(json) ⇒ Object



67
68
69
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 67

def uid(json)
  json[:submitter][:uid]
end

#update_assignment(json) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 36

def update_assignment(json)
  assignment = Mumuki::Classroom::Assignment
                 .where(assignment_query(json))
                 .first_or_create!(assignment_without_submission_from(json))
  assignment.upsert_attributes(assignment_without_submission_from(json))
  assignment.add_submission! submission_from(json)
end

#update_guide_progress(json) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 55

def update_guide_progress(json)
  json[:stats] = student_stats_for json
  Mumuki::Classroom::GuideProgress
    .where(guide_progress_query(json))
    .first_or_create!(guide_progress_from json)
    .upsert_attributes(guide_progress_from json)
end

#update_student_last_assignment(json) ⇒ Object



32
33
34
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 32

def update_student_last_assignment(json)
  Mumuki::Classroom::Student.find_by!(organization: organization(json), course: course_slug(json), uid: uid(json)).update_last_assignment_for
end

#update_student_progress(json) ⇒ Object



28
29
30
# File 'lib/mumuki/classroom/models/concerns/with_submission_process.rb', line 28

def update_student_progress(json)
  Mumuki::Classroom::Student.find_by!(organization: organization(json), course: course_slug(json), uid: uid(json)).update_all_stats
end