Handle the case where histogram score can be null
This will leave out the student that never attempt the question and fixes the error with histogram rendering.
This commit is contained in:
@@ -11,7 +11,7 @@ describe 'Histogram', ->
|
||||
|
||||
describe 'calculate', ->
|
||||
beforeEach ->
|
||||
@histogram = new Histogram(1, [[1, 1], [2, 2], [3, 3]])
|
||||
@histogram = new Histogram(1, [[null, 1], [1, 1], [2, 2], [3, 3]])
|
||||
|
||||
it 'store the correct value for data', ->
|
||||
expect(@histogram.data).toEqual [[1, Math.log(2)], [2, Math.log(3)], [3, Math.log(4)]]
|
||||
|
||||
@@ -8,6 +8,7 @@ class @Histogram
|
||||
|
||||
calculate: ->
|
||||
for [score, count] in @rawData
|
||||
continue if score == null
|
||||
log_count = Math.log(count + 1)
|
||||
@data.push [score, log_count]
|
||||
@xTicks.push [score, score.toString()]
|
||||
|
||||
Reference in New Issue
Block a user