Browse files

Fix ntileFunc bug. Off by one calculating rank

  • Loading branch information...
1 parent 5898b10 commit fea81c08f9f56ea42d5777d40cbfb769772a0d32 Daniel Einspanjer committed Dec 3, 2010
Showing with 16 additions and 17 deletions.
  1. +15 −16 function-contrib-gollum/stats.textile
  2. +1 −1 mapreduce/js/stats.js
View
31 function-contrib-gollum/stats.textile
@@ -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];
@@ -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,
@@ -104,7 +104,6 @@ JSON.stringify(eventStats, null, 2);
h3. TODO
-* debug percentile99
* Truncate percentages (configurable?)
* Add argument for short circuiting sort?
View
2 mapreduce/js/stats.js
@@ -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];

0 comments on commit fea81c0

Please sign in to comment.