Skip to content

Commit

Permalink
Fix ntileFunc bug. Off by one calculating rank
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Einspanjer committed Dec 3, 2010
1 parent 5898b10 commit fea81c0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions function-contrib-gollum/stats.textile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var Stats = function(data) {

var ntileFunc = function(percentile){
if (data.length == 1) return data[0];
var ntileRank = (percentile/100) * (data.length + 1);
var ntileRank = ((percentile/100) * (data.length - 1)) + 1;
var integralRank = Math.floor(ntileRank);
var fractionalRank = ntileRank - integralRank;
var lowerValue = data[integralRank-1];
Expand Down Expand Up @@ -72,28 +72,28 @@ var eventStats = Stats(numEvents);
/*
JSON.stringify(sizeStats, null, 2);
{
"count":8,
"min":0,
"max":8928,
"percentile25":12.5,
"median":271.5,
"percentile75":1061,
"percentile99":null, <-- bug here?
"mean":1412.375,
"sum":11299,
"variance":8220487.734374999,
"sdev":2867.1392945538937
"count": 8,
"min": 0,
"max": 8928,
"percentile25": 37.5,
"median": 271.5,
"percentile75": 717,
"percentile99": 8389.349999999999,
"mean": 1412.375,
"sum": 11299,
"variance": 8220487.734374999,
"sdev": 2867.1392945538937
}

JSON.stringify(eventStats, null, 2);
{
"count": 8,
"min": 0,
"max": 300,
"percentile25": 0.5,
"percentile25": 1.5,
"median": 17.5,
"percentile75": 45,
"percentile99": null,
"percentile75": 35,
"percentile99": 282.49999999999994,
"mean": 52.125,
"sum": 417,
"variance": 9049.109374999998,
Expand All @@ -104,7 +104,6 @@ JSON.stringify(eventStats, null, 2);

h3. TODO

* debug percentile99
* Truncate percentages (configurable?)
* Add argument for short circuiting sort?

2 changes: 1 addition & 1 deletion mapreduce/js/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var Stats = function(data) {

var ntileFunc = function(percentile){
if (data.length == 1) return data[0];
var ntileRank = (percentile/100) * (data.length + 1);
var ntileRank = ((percentile/100) * (data.length - 1)) + 1;
var integralRank = Math.floor(ntileRank);
var fractionalRank = ntileRank - integralRank;
var lowerValue = data[integralRank-1];
Expand Down

0 comments on commit fea81c0

Please sign in to comment.