gradebook: better sorting for total columns

fixes CNVS-9300

Test plan:
  * make a course with 2 assignments:
    * one has 10 points possible
    * one has 100 points possible
  * give a student 10/10 on the first assignment (no score on the
    second)
  * give another student 20/100 on the second assignment
  * sort by total grade
  * it should sort by percent
  * switch the total grade to display as points
  * it should sort by points

Change-Id: Ie0651fcefb3c0880a017c438b40aa169158f34ba
Reviewed-on: https://gerrit.instructure.com/36664
Reviewed-by: Cameron Sutter <csutter@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Amber Taniuchi <amber@instructure.com>
Product-Review: Cameron Matheson <cameron@instructure.com>
This commit is contained in:
Cameron Matheson 2014-06-19 15:16:18 -06:00
parent 2e6f306172
commit 553baa39d3
2 changed files with 60 additions and 5 deletions

View File

@ -1057,13 +1057,11 @@ define [
data.sortCol.field
@sortRowsBy (a, b) =>
[b, a] = [a, b] if not data.sortAsc
[b, a] = [a, b] unless data.sortAsc
@localeSort(a[sortProp], b[sortProp])
else
@sortRowsBy (a, b) ->
aScore = a[data.sortCol.field]?.score
bScore = b[data.sortCol.field]?.score
numberCompare(aScore, bScore, descending: !data.sortAsc)
@sortRowsBy (a, b) =>
@gradeSort(a, b, data.sortCol.field, data.sortAsc)
@grid.onKeyDown.subscribe ->
# TODO: start editing automatically when a number or letter is typed
@ -1108,6 +1106,28 @@ define [
window.I18n.locale,
sensitivity: 'accent', numeric: true
gradeSort: (a, b, field, asc) =>
scoreForSorting = (obj) =>
percent = (obj) ->
if obj[field].possible > 0
obj[field].score / obj[field].possible
else
null
switch
when field == "total_grade"
if @options.show_total_grade_as_points
obj[field].score
else
percent(obj)
when field.match /^assignment_group/
percent(obj)
else
# TODO: support assignment grading types
obj[field].score
numberCompare(scoreForSorting(a), scoreForSorting(b), descending: !asc)
# show warnings for bad grading setups
setAssignmentWarnings: =>
if @weightedGroups()

View File

@ -0,0 +1,35 @@
define ['compiled/gradebook2/Gradebook'], (Gradebook) ->
module "Gradebook2"
test "gradeSort - total_grade", ->
gradeSort = (showTotalGradeAsPoints, a, b, field, asc) ->
asc = true unless asc?
Gradebook.prototype.gradeSort.call options:
show_total_grade_as_points: showTotalGradeAsPoints
, a, b, field, asc
ok gradeSort(false
, {total_grade: {score: 10, possible: 20}}
, {total_grade: {score: 5, possible: 10}}
, 'total_grade') == 0
, "total_grade sorts by percent (normally)"
ok gradeSort(true
, {total_grade: {score: 10, possible: 20}}
, {total_grade: {score: 5, possible: 10}}
, 'total_grade') > 0
, "total_grade sorts by score when if show_total_grade_as_points"
ok gradeSort(true
, {assignment_group_1: {score: 10, possible: 20}}
, {assignment_group_1: {score: 5, possible: 10}}
, 'assignment_group_1') == 0
, "assignment groups are always sorted by percent"
ok gradeSort(false
, {assignment1: {score: 5, possible: 10}}
, {assignment1: {score: 10, possible: 20}}
, 'assignment1') < 0
, "other fields are sorted by score"