From: Sasa M. <sa...@us...> - 2004-12-29 11:37:00
|
Update of /cvsroot/jrobin/src/org/jrobin/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23330/org/jrobin/data Modified Files: Aggregator.java DataProcessor.java Def.java SDef.java Source.java Log Message: Added custom percentile boundary (different from 95%) Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Source.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Source.java 15 Dec 2004 14:55:41 -0000 1.3 --- Source.java 29 Dec 2004 11:36:50 -0000 1.4 *************** *** 63,69 **** } ! double get95Percentile(long tStart, long tEnd) throws RrdException { Aggregator agg = new Aggregator(timestamps, values); ! return agg.get95Percentile(tStart, tEnd); } } --- 63,69 ---- } ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { Aggregator agg = new Aggregator(timestamps, values); ! return agg.getPercentile(tStart, tEnd, percentile); } } Index: Def.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Def.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Def.java 16 Dec 2004 11:16:03 -0000 1.4 --- Def.java 29 Dec 2004 11:36:50 -0000 1.5 *************** *** 107,115 **** } ! double get95Percentile(long tStart, long tEnd) throws RrdException { long[] t = getRrdTimestamps(); double[] v = getRrdValues(); Aggregator agg = new Aggregator(t, v); ! return agg.get95Percentile(tStart, tEnd); } --- 107,115 ---- } ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { long[] t = getRrdTimestamps(); double[] v = getRrdValues(); Aggregator agg = new Aggregator(t, v); ! return agg.getPercentile(tStart, tEnd, percentile); } Index: DataProcessor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/DataProcessor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DataProcessor.java 16 Dec 2004 11:16:03 -0000 1.6 --- DataProcessor.java 29 Dec 2004 11:36:50 -0000 1.7 *************** *** 61,64 **** --- 61,66 ---- */ public static final int DEFAUL_PIXEL_COUNT = 400; + private static final double DEFAULT_PERCENTILE = 95.0; // % + private int pixelCount = DEFAUL_PIXEL_COUNT; *************** *** 278,281 **** --- 280,285 ---- /** + * This method is just an alias for {@link #getPercentile(String)} method. + * * Used by ISPs which charge for bandwidth utilization on a "95th percentile" basis.<p> * *************** *** 293,298 **** */ public double get95Percentile(String sourceName) throws RrdException { Source source = getSource(sourceName); ! return source.get95Percentile(tStart, tEnd); } --- 297,337 ---- */ public double get95Percentile(String sourceName) throws RrdException { + return getPercentile(sourceName); + } + + /** + * Used by ISPs which charge for bandwidth utilization on a "95th percentile" basis.<p> + * + * The 95th percentile is the highest source value left when the top 5% of a numerically sorted set + * of source data is discarded. It is used as a measure of the peak value used when one discounts + * a fair amount for transitory spikes. This makes it markedly different from the average.<p> + * + * Read more about this topic at + * <a href="http://www.red.net/support/resourcecentre/leasedline/percentile.php">Rednet</a> or + * <a href="http://www.bytemark.co.uk/support/tech/95thpercentile.html">Bytemark</a>. + * + * @param sourceName Datasource name + * @return 95th percentile of fetched source values + * @throws RrdException Thrown if invalid source name is supplied + */ + public double getPercentile(String sourceName) throws RrdException { + return getPercentile(sourceName, DEFAULT_PERCENTILE); + } + + /** + * The same as {@link #getPercentile(String)} but with a possibility to define custom percentile boundary + * (different from 95). + * @param sourceName Datasource name. + * @param percentile Boundary percentile. Value of 95 (%) is suitable in most cases, but you are free + * to provide your own percentile boundary between zero and 100. + * @return Requested percentile of fetched source values + * @throws RrdException Thrown if invalid sourcename is supplied, or if the percentile value makes no sense. + */ + public double getPercentile(String sourceName, double percentile) throws RrdException { + if(percentile <= 0.0 || percentile > 100.0) { + throw new RrdException("Invalid percentile [" + percentile + "], sohuld be between 0 and 100"); + } Source source = getSource(sourceName); ! return source.getPercentile(tStart, tEnd, percentile); } Index: Aggregator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Aggregator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Aggregator.java 16 Dec 2004 11:16:03 -0000 1.2 --- Aggregator.java 29 Dec 2004 11:36:50 -0000 1.3 *************** *** 72,76 **** } ! double get95Percentile(long tStart, long tEnd) { List valueList = new ArrayList(); // create a list of included datasource values (different from NaN) --- 72,76 ---- } ! double getPercentile(long tStart, long tEnd, double percentile) { List valueList = new ArrayList(); // create a list of included datasource values (different from NaN) *************** *** 91,96 **** // sort array Arrays.sort(valuesCopy); ! // skip top 5% values ! count -= (int) Math.ceil(count * 0.05); // if we have anything left... if (count > 0) { --- 91,97 ---- // sort array Arrays.sort(valuesCopy); ! // skip top (100% - percentile) values ! double topPercentile = (100.0 - percentile) / 100.0; ! count -= (int) Math.ceil(count * topPercentile); // if we have anything left... if (count > 0) { Index: SDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/SDef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SDef.java 15 Dec 2004 14:55:41 -0000 1.2 --- SDef.java 29 Dec 2004 11:36:50 -0000 1.3 *************** *** 64,68 **** } ! double get95Percentile(long tStart, long tEnd) throws RrdException { return value; } --- 64,68 ---- } ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { return value; } |