From 5982369b2a958c6041fb0fb6dde9749f56f28e5a Mon Sep 17 00:00:00 2001 From: Charlie Groves Date: Tue, 12 Aug 2008 01:45:59 +0000 Subject: [PATCH] Allow the initial bucket range to be passed to the percentiler on creation. As long as the recorded values stay within the range, the percentiler won't do its 20% greater than range expansion, so the values reported by getRequiredScore will reflect the initial min-max. git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@728 c613c5cb-e716-0410-b11b-feb51c14d237 --- .../parlor/rating/util/Percentiler.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/java/com/threerings/parlor/rating/util/Percentiler.java b/src/java/com/threerings/parlor/rating/util/Percentiler.java index bed8f807..4cb55c91 100644 --- a/src/java/com/threerings/parlor/rating/util/Percentiler.java +++ b/src/java/com/threerings/parlor/rating/util/Percentiler.java @@ -42,6 +42,15 @@ public class Percentiler { } + /** + * Creates a percentiler that expects values to fall within the given range. + */ + public Percentiler(int min, int max) { + _min = min; + _max = max; + _fixedRange = true; + } + /** * Creates a percentiler from its serialized representation. */ @@ -88,13 +97,18 @@ public class Percentiler public void recordValue (float value, boolean logNewMax) { // if this is the first value ever recorded; note our min and max - if (_total == 0) { + if (_total == 0 && !_fixedRange) { _min = (int)Math.floor(value); - _max = Math.max((int)Math.ceil(value), _min+1); + _max = Math.max((int)Math.ceil(value), _min + 1); } // if this value is outside our bounds, we need to redistribute our buckets if (value < _min || value > _max) { + if (_fixedRange) { + log.warning("Recording value outside of initially fixed range", "min", _min, + "max", _max, "value", value); + _fixedRange = false; + } // expand by 20% in the direction of either our new minimum or new maximum int newmin = (value < _min) ? (_max - (int)Math.ceil((_max - value) * 1.2f)) : _min; int newmax = (value > _max) ? (_min + (int)Math.ceil((value - _min) * 1.2f)) : _max; @@ -384,6 +398,9 @@ public class Percentiler return idx; } + /** If this Percentiler was created with a fixed range. */ + protected boolean _fixedRange; + /** The total number of data points seen by this percentiler. */ protected long _total;