From: Sasa M. <sa...@us...> - 2004-12-15 14:42:53
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6428/org/jrobin/core Modified Files: FetchData.java Util.java Log Message: Minor changes necessary to integrate FetchData class with the new data.* package. Index: FetchData.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/FetchData.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** FetchData.java 25 Nov 2004 14:26:06 -0000 1.15 --- FetchData.java 15 Dec 2004 14:42:44 -0000 1.16 *************** *** 26,29 **** --- 26,32 ---- package org.jrobin.core; + import org.jrobin.data.Aggregator; + import org.jrobin.data.Aggregates; + import java.io.IOException; import java.io.OutputStream; *************** *** 297,301 **** /** ! * Returns aggregated value from the fetched data for a single datasource. * * @param dsName Datasource name --- 300,304 ---- /** ! * Returns single aggregated value from the fetched data for a single datasource. * * @param dsName Datasource name *************** *** 306,387 **** * for the given datasource name * @throws RrdException Thrown if the given datasource name cannot be found in fetched data. - * @deprecated This method may calculate averages slightly different from values displayed in the - * corresponding graph. Use {@link org.jrobin.data.DataProcessor DataProcessor} class instead. */ public double getAggregate(String dsName, String consolFun) throws RrdException { ! if(consolFun.equals(CF_MAX)) { ! return getMax(dsName); ! } ! else if(consolFun.equals(CF_MIN)) { ! return getMin(dsName); ! } ! else if(consolFun.equals(CF_LAST)) { ! return getLast(dsName); ! } ! else if(consolFun.equals(CF_FIRST)) { ! return getFirst(dsName); ! } ! else if(consolFun.equals(CF_AVERAGE)) { ! return getAverage(dsName); ! } ! else if(consolFun.equals(CF_TOTAL)) { ! return getTotal(dsName); ! } ! else { ! throw new RrdException("Unsupported consolidation function [" + consolFun + "]"); ! } ! } ! ! private double getMax(String dsName) throws RrdException { ! double values[] = getValues(dsName), max = Double.NaN; ! for(int i = 1; i < values.length; i++) { ! max = Util.max(max, values[i]); ! } ! return max; ! } ! ! private double getMin(String dsName) throws RrdException { ! double values[] = getValues(dsName), min = Double.NaN; ! for(int i = 1; i < values.length; i++) { ! min = Util.min(min, values[i]); ! } ! return min; ! } ! ! private double getLast(String dsName) throws RrdException { ! double values[] = getValues(dsName); ! return values[values.length - 1]; ! } ! ! private double getFirst(String dsName) throws RrdException { ! double values[] = getValues(dsName); ! return values[1]; } ! private double getAverage(String dsName) throws RrdException { ! double values[] = getValues(dsName), totalVal = 0D; ! long tStart = request.getFetchStart(), tEnd = request.getFetchEnd(), totalSecs = 0; ! for(int i = 1; i < values.length; i++) { ! long t1 = Math.max(tStart, timestamps[i - 1]), t2 = Math.min(tEnd, timestamps[i]); ! double value = values[i]; ! if(!Double.isNaN(value)) { ! totalSecs += (t2 - t1); ! totalVal += (t2 - t1) * value; ! } ! } ! return totalSecs > 0? totalVal / totalSecs: Double.NaN; } ! private double getTotal(String dsName) throws RrdException { ! double vals[] = getValues(dsName), totalVal = 0D; ! long tStart = request.getFetchStart(), tEnd = request.getFetchEnd(); ! for(int i = 1; i < vals.length; i++) { ! long t1 = Math.max(tStart, timestamps[i - 1]), t2 = Math.min(tEnd, timestamps[i]); ! double value = vals[i]; ! if(!Double.isNaN(value)) { ! totalVal += (t2 - t1) * value; ! } ! } ! return totalVal; } --- 309,351 ---- * for the given datasource name * @throws RrdException Thrown if the given datasource name cannot be found in fetched data. */ public double getAggregate(String dsName, String consolFun) throws RrdException { ! Aggregator aggregator = new Aggregator(getTimestamps(), getValues(dsName)); ! Aggregates agg = aggregator.getAggregates(request.getFetchStart(), request.getFetchEnd()); ! return agg.getAggregate(consolFun); } ! /** ! * Returns all aggregated values (MIN, MAX, LAST, FIRST, AVERAGE or TOTAL) calculated from the fetched data ! * for a single datasource. ! * ! * @param dsName Datasource name. ! * @return Simple object containing all aggregated values. ! * @throws RrdException Thrown if the given datasource name cannot be found in the fetched data. ! */ ! public Aggregates getAggregates(String dsName) throws RrdException { ! Aggregator aggregator = new Aggregator(getTimestamps(), getValues(dsName)); ! Aggregates agg = aggregator.getAggregates(request.getFetchStart(), request.getFetchEnd()); ! return agg; } ! /** ! * 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:<p> ! * <a href="http://www.red.net/support/resourcecentre/leasedline/percentile.php">Rednet</a> or<br> ! * <a href="http://www.bytemark.co.uk/support/tech/95thpercentile.html">Bytemark</a>. ! * ! * @param dsName Datasource name ! * @return 95th percentile of fetched source values ! * @throws RrdException Thrown if invalid source name is supplied ! */ ! public double get95Percentile(String dsName) throws RrdException { ! Aggregator aggregator = new Aggregator(getTimestamps(), getValues(dsName)); ! return aggregator.get95Percentile(request.getFetchStart(), request.getFetchEnd()); } Index: Util.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Util.java 25 Nov 2004 12:14:53 -0000 1.29 --- Util.java 15 Dec 2004 14:42:44 -0000 1.30 *************** *** 90,94 **** * Rounds the given timestamp to the nearest whole "e;step"e;. Rounded value is obtained * from the following expression:<p> ! * <code>timestamp - timestamp % step;</code> * @param timestamp Timestamp in seconds * @param step Step in seconds --- 90,94 ---- * Rounds the given timestamp to the nearest whole "e;step"e;. Rounded value is obtained * from the following expression:<p> ! * <code>timestamp - timestamp % step;</code><p> * @param timestamp Timestamp in seconds * @param step Step in seconds *************** *** 123,127 **** } ! static double sum(double x, double y) { return Double.isNaN(x)? y: Double.isNaN(y)? x: x + y; } --- 123,133 ---- } ! /** ! * Calculates sum of two doubles, but treats NaNs as zeros. ! * @param x First double ! * @param y Second double ! * @return Sum(x,y) calculated as <code>Double.isNaN(x)? y: Double.isNaN(y)? x: x + y;</code> ! */ ! public static double sum(double x, double y) { return Double.isNaN(x)? y: Double.isNaN(y)? x: x + y; } *************** *** 142,146 **** /** ! * Formats double as a string using exponential notation. Used for debugging * throught the project. * @param x value to be formatted --- 148,152 ---- /** ! * Formats double as a string using exponential notation (RRDTool like). Used for debugging * throught the project. * @param x value to be formatted |