From: Sasa M. <sa...@us...> - 2004-12-08 14:02:49
|
Update of /cvsroot/jrobin/src/org/jrobin/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23351/org/jrobin/data Modified Files: DataProcessor.java Source.java Log Message: Implemented 95th percentile for datasource values (see get95Percentile method in the DataAnalyzer class). Minor changes in the core package. Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Source.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Source.java 25 Nov 2004 12:14:54 -0000 1.1 --- Source.java 8 Dec 2004 14:02:37 -0000 1.2 *************** *** 30,33 **** --- 30,35 ---- import org.jrobin.core.Util; + import java.util.Arrays; + abstract class Source implements ConsolFuns { final private String name; *************** *** 78,81 **** --- 80,118 ---- } + final double getPercentile(int percentile) throws RrdException { + if(values == null) { + throw new RrdException("Could not calculate 95th percentile for datasource [" + + name + "], datasource values are still not available"); + } + if(percentile > 100 || percentile <= 0) { + throw new RrdException("Invalid percentile specified: " + percentile); + } + return getPercentile(values, percentile); + } + + private static double getPercentile(double[] values, int percentile) { + int count = values.length; + double[] valuesCopy = new double[count]; + for(int i = 0; i < count; i++) { + valuesCopy[i] = values[i]; + } + Arrays.sort(valuesCopy); + // NaN values are at the end, eliminate them from consideration + while(count > 0 && Double.isNaN(valuesCopy[count - 1])) { + count--; + } + // skip top [percentile]% values + int skipCount = (int) Math.ceil(((100 - percentile) * count) / 100.0); + count -= skipCount; + // if we have anything left... + if(count > 0) { + return valuesCopy[count - 1]; + } + else { + // not enough data available + return Double.NaN; + } + } + private double getTotal(double secondsPerPixel) { double sum = 0; *************** *** 115,118 **** return min; } - } --- 152,154 ---- Index: DataProcessor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/DataProcessor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DataProcessor.java 26 Nov 2004 13:47:51 -0000 1.3 --- DataProcessor.java 8 Dec 2004 14:02:37 -0000 1.4 *************** *** 240,243 **** --- 240,263 ---- /** + * 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 get95Percentile(String sourceName) throws RrdException { + Source source = getSource(sourceName); + return source.getPercentile(95); + } + + /** * Returns array of datasource names defined in this DataProcessor. * @return array of datasource names |