From b0dcb25553a323dd79658a93dc8ef5cf1787c0db Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 1 May 2009 22:57:37 +0000 Subject: [PATCH] Don't let toBucketIndex freak out if someone requests the percentile for a value out of our seen range. That's OK. Also switch to PrintWriter from PrintStream when dumping. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@834 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../threerings/parlor/rating/util/Percentiler.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/java/com/threerings/parlor/rating/util/Percentiler.java b/src/java/com/threerings/parlor/rating/util/Percentiler.java index 30b6ea0a..0e475448 100644 --- a/src/java/com/threerings/parlor/rating/util/Percentiler.java +++ b/src/java/com/threerings/parlor/rating/util/Percentiler.java @@ -21,7 +21,7 @@ package com.threerings.parlor.rating.util; -import java.io.PrintStream; +import java.io.PrintWriter; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -211,7 +211,13 @@ public class Percentiler */ public int getPercentile (float value) { - return _percentile[toBucketIndex(value)]; + if (value < _min) { + return 0; + } else if (value > _max) { + return 100; + } else { + return _percentile[toBucketIndex(value)]; + } } /** @@ -330,7 +336,7 @@ public class Percentiler /** * Dumps out our data in a format that can be used to generate a gnuplot. */ - public void dumpGnuPlot (PrintStream out) + public void dumpGnuPlot (PrintWriter out) { float delta = (_max - _min) / (float)BUCKET_COUNT; for (int ii = 0; ii < BUCKET_COUNT; ii++) { @@ -341,7 +347,7 @@ public class Percentiler /** * Dumps a text representation of this percentiler to the supplied print stream. */ - public void dump (PrintStream out) + public void dump (PrintWriter out) { // obtain our maximum count int max = 0;