Skip to content

Commit

Permalink
Fix grader csv download for marks spreadsheets (#7257)
Browse files Browse the repository at this point in the history
  • Loading branch information
donny-wong authored Oct 6, 2024
1 parent f7fca63 commit 0b91f84
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Fix incorrect calculation of token penalties when submissions are on time (#7216)
- Ensured submissions that have been released cannot be recollected from the repo browser (#7254)
- Fix bug where renaming a group to an existing group in a different assignment resulted in incorrect repository mapping (#7224)
- Fix Marks Spreadsheet csv bug of showing incorrect marks (#7257)

### 🔧 Internal changes

Expand Down
9 changes: 4 additions & 5 deletions app/models/grade_entry_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ def export_as_csv(role)
.group_by { |x| x[0] }
num_items = self.grade_entry_items.count
elsif role.ta?
grade_data = role.grade_entry_students
.joins(:user)
.joins(:grades)
.joins(:grade_entry_items)
.where(grade_entry_form: self)
grade_data = self.grades
.joins(:grade_entry_item, grade_entry_student: :user)
.joins(grade_entry_student: :grade_entry_student_tas)
.where('grade_entry_student_tas.ta_id': role.id)
.pluck('users.user_name', 'grade_entry_items.position', 'grades.grade')
.group_by { |x| x[0] }
num_items = self.grade_entry_items.count
Expand Down
43 changes: 43 additions & 0 deletions spec/models/grade_entry_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,47 @@
end
end
end

describe 'when TA downloads a csv file of the grades' do
let(:ta) { create(:ta) }
let!(:student1) { create(:student) }
let!(:student2) { create(:student) }
let!(:grade_entry_form_with_data) { create(:grade_entry_form_with_data) }

before do
grade_entry_student1 = GradeEntryStudent.find_by(role: student1)
grade_entry_student2 = GradeEntryStudent.find_by(role: student2)

GradeEntryStudentTa.create(grade_entry_student: grade_entry_student1, ta: ta)
GradeEntryStudentTa.create(grade_entry_student: grade_entry_student2, ta: ta)

item2 = create(:grade_entry_item, name: 'Test2', position: 2, grade_entry_form: grade_entry_form_with_data)

grade_entry_student1.grades.create(grade: Random.rand(item2.out_of), grade_entry_item: item2)
grade_entry_student1.save

grade_entry_student2.grades.create(grade: Random.rand(item2.out_of), grade_entry_item: item2)
grade_entry_student2.save

grade_spreadsheet = grade_entry_form_with_data.export_as_csv(ta)
results = CSV.parse(grade_spreadsheet, headers: false).drop(2)

@res_marks = {}
results.each do |x|
mark1 = x[6] == '' ? nil : x[6].to_f
mark2 = x[7] == '' ? nil : x[7].to_f
@res_marks[x[0]] = [mark1, mark2]
end

@student_marks = {}
@student_marks[student1.user.user_name] =
[grade_entry_student1.grades.first.grade, grade_entry_student1.grades.second.grade]
@student_marks[student2.user.user_name] =
[grade_entry_student2.grades.first.grade, grade_entry_student2.grades.second.grade]
end

it 'correctly displays the marks' do
expect(@res_marks).to eq(@student_marks)
end
end
end

0 comments on commit 0b91f84

Please sign in to comment.