Skip to content

Commit

Permalink
refactor(statsType): simplification of type
Browse files Browse the repository at this point in the history
- submissionExists not used anymore
- ancestor and main stats jbuilder refactored
- since both are having quite similar structure, redefine some jbuilder
  • Loading branch information
bivanalhar committed Mar 26, 2024
1 parent c1f1a85 commit dab21cb
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 71 deletions.
11 changes: 11 additions & 0 deletions app/views/course/statistics/assessments/_answer.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true
json.grader do
json.id grader&.id || 0
json.name grader&.name || 'System'
end

json.answers answers.each do |answer|
json.id answer.id
json.grade answer.grade
json.maximumGrade @question_maximum_grade_hash[answer.question_id]
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
json.id assessment.id
json.title assessment.title
json.startAt assessment.start_at&.iso8601
json.endAt assessment.end_at&.iso8601
json.maximumGrade assessment.maximum_grade
json.url course_assessment_path(course, assessment)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
json.courseUser do
json.id course_user.id
json.name course_user.name
json.role course_user.role
json.isPhantom course_user.phantom?
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
if submission.nil?
json.workflowState 'unstarted'
else
json.workflowState submission.workflow_state
json.submittedAt submission.submitted_at&.iso8601
json.endAt end_at&.iso8601
json.totalGrade submission.grade
end
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
# frozen_string_literal: true
json.assessment do
json.id @assessment.id
json.title @assessment.title
json.startAt @assessment.start_at&.iso8601
json.endAt @assessment.end_at&.iso8601
json.maximumGrade @assessment.maximum_grade
json.url course_assessment_path(current_course, @assessment)
json.partial! 'assessment', assessment: @assessment, course: current_course
end

json.submissions @student_submissions_hash.each do |course_user, (submission, end_at)|
json.courseUser do
json.id course_user.id
json.name course_user.name
json.role course_user.role
json.isPhantom course_user.phantom?
end

if submission.nil?
json.workflowState 'unstarted'
else
json.workflowState submission.workflow_state
json.submittedAt submission.submitted_at&.iso8601
json.endAt end_at&.iso8601
json.totalGrade submission.grade
end
json.partial! 'course_user', course_user: course_user
json.partial! 'submission', submission: submission, end_at: end_at
end
Original file line number Diff line number Diff line change
@@ -1,50 +1,20 @@
# frozen_string_literal: true
json.assessment do
json.id @assessment.id
json.title @assessment.title
json.startAt @assessment.start_at&.iso8601
json.endAt @assessment.end_at&.iso8601
json.maximumGrade @assessment.maximum_grade
json.partial! 'assessment', assessment: @assessment, course: current_course
json.questionCount @assessment.question_count
json.url course_assessment_path(current_course, @assessment)
end

json.submissions @student_submissions_hash.each do |course_user, (submission, answers, end_at)|
json.courseUser do
json.id course_user.id
json.name course_user.name
json.role course_user.role
json.isPhantom course_user.phantom?
end
json.partial! 'course_user', course_user: course_user
json.partial! 'submission', submission: submission, end_at: end_at

json.groups course_user.groups do |group|
json.name group.name
end

json.submissionExists !submission.nil?

if submission.nil?
json.workflowState 'unstarted'
else
json.workflowState submission.workflow_state
json.submittedAt submission.submitted_at&.iso8601
json.endAt end_at&.iso8601
json.totalGrade submission.grade

if submission.workflow_state == 'published' && submission.grader_ids
# the graders are all the same regardless of question, so we just pick the first one
grader = @course_users_hash[submission.grader_ids.first]
json.grader do
json.id grader&.id || 0
json.name grader&.name || 'System'
end

json.answers answers.each do |answer|
json.id answer.id
json.grade answer.grade
json.maximumGrade @question_maximum_grade_hash[answer.question_id]
end
end
if !submission.nil? && submission.workflow_state == 'published' && submission.grader_ids
# the graders are all the same regardless of question, so we just pick the first one
json.partial! 'answer', grader: @course_users_hash[submission.grader_ids.first], answers: answers
end
end

Expand Down
1 change: 0 additions & 1 deletion client/app/types/course/statistics/assessmentStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export interface MainSubmissionInfo extends SubmissionInfo {
answers?: AnswerInfo[];
grader?: UserInfo;
groups: { name: string }[];
submissionExists: boolean;
}

export interface AncestorSubmissionInfo extends SubmissionInfo {
Expand Down
13 changes: 0 additions & 13 deletions spec/controllers/course/statistics/assessment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@
expect(json_result['submissions'][1]['workflowState']).to eq('attempting')
expect(json_result['submissions'][2]['workflowState']).to be_nil

# checking if the submission exists
expect(json_result['submissions'][0]['submissionExists']).to be_truthy
expect(json_result['submissions'][1]['submissionExists']).to be_truthy
expect(json_result['submissions'][2]['submissionExists']).to be_falsey

# only published submissions' answers will be included in the stats
expect(json_result['submissions'][0]['answers']).not_to be_nil
expect(json_result['submissions'][1]['answers']).to be_nil
Expand Down Expand Up @@ -102,11 +97,6 @@
expect(json_result['submissions'][1]['workflowState']).to eq('attempting')
expect(json_result['submissions'][2]['workflowState']).to be_nil

# checking if the submission exists
expect(json_result['submissions'][0]['submissionExists']).to be_truthy
expect(json_result['submissions'][1]['submissionExists']).to be_truthy
expect(json_result['submissions'][2]['submissionExists']).to be_falsey

# only published submissions' answers will be included in the stats
expect(json_result['submissions'][0]['answers']).not_to be_nil
expect(json_result['submissions'][1]['answers']).to be_nil
Expand Down Expand Up @@ -153,9 +143,6 @@
expect(subject).to have_http_status(:success)
json_result = JSON.parse(response.body)

# all the students data will be included here, including the non-existing submission one
expect(json_result['allStudents'].count).to eq(3)

# however, only the existing submissions will be shown
expect(json_result['submissions'].count).to eq(2)
end
Expand Down

0 comments on commit dab21cb

Please sign in to comment.