From: Sasa M. <sa...@us...> - 2004-12-16 11:16:19
|
Update of /cvsroot/jrobin/src/org/jrobin/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4926/org/jrobin/data Modified Files: Aggregator.java DataProcessor.java Def.java Log Message: Minor changes and improvements. Code polishing and optimizations. Index: DataProcessor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/DataProcessor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DataProcessor.java 15 Dec 2004 14:55:41 -0000 1.5 --- DataProcessor.java 16 Dec 2004 11:16:03 -0000 1.6 *************** *** 465,468 **** --- 465,484 ---- /** + * Adds DEF datasource with datasource values already available in the FetchData object. This method is + * used internally by JRobin and probably has no purpose outside of it. + * + * @param name Source name. + * @param fetchData Fetched data containing values for the given source name. + */ + public void addDatasource(String name, FetchData fetchData) { + Def def = new Def(name, fetchData); + sources.put(name, def); + } + + ///////////////////////////////////////////////////////////////// + // CALCULATIONS + ///////////////////////////////////////////////////////////////// + + /** * Method that should be called once all datasources are defined. Data will be fetched from * RRD files, RPN expressions will be calculated, etc. *************** *** 606,610 **** long tEndFixed = (tEnd == 0) ? Util.getTime() : tEnd; for (int i = 0; i < defSources.length; i++) { ! if (defSources[i].getValues() == null) { // not fetched yet Set dsNames = new HashSet(); --- 622,626 ---- long tEndFixed = (tEnd == 0) ? Util.getTime() : tEnd; for (int i = 0; i < defSources.length; i++) { ! if (!defSources[i].isLoaded()) { // not fetched yet Set dsNames = new HashSet(); *************** *** 644,650 **** throw new RrdException("Could not adjust zero ending timestamp, no DEF source provided"); } ! tEnd = defSources[0].getLastValidTimestamp(); for (int i = 1; i < defSources.length; i++) { ! tEnd = Math.min(tEnd, defSources[i].getLastValidTimestamp()); } if (tEnd <= tStart) { --- 660,666 ---- throw new RrdException("Could not adjust zero ending timestamp, no DEF source provided"); } ! tEnd = defSources[0].getArchiveEndTime(); for (int i = 1; i < defSources.length; i++) { ! tEnd = Math.min(tEnd, defSources[i].getArchiveEndTime()); } if (tEnd <= tStart) { Index: Def.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Def.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Def.java 15 Dec 2004 14:55:41 -0000 1.3 --- Def.java 16 Dec 2004 11:16:03 -0000 1.4 *************** *** 35,39 **** private String path, dsName, consolFun, backend; private FetchData fetchData; ! private long lastValidTimestamp, fetchStep; Def(String name, String path, String dsName, String consolFunc) { --- 35,43 ---- private String path, dsName, consolFun, backend; private FetchData fetchData; ! ! Def(String name, FetchData fetchData) { ! this(name, null, name, null, null); ! setFetchData(fetchData); ! } Def(String name, String path, String dsName, String consolFunc) { *************** *** 76,83 **** } ! void setFetchData(FetchData fetchData) throws IOException { this.fetchData = fetchData; - this.lastValidTimestamp = fetchData.getMatchingArchive().getEndTime(); - this.fetchStep = fetchData.getMatchingArchive().getArcStep(); } --- 80,85 ---- } ! void setFetchData(FetchData fetchData) { this.fetchData = fetchData; } *************** *** 90,99 **** } ! long getLastValidTimestamp() { ! return lastValidTimestamp; } long getFetchStep() { ! return fetchStep; } --- 92,101 ---- } ! long getArchiveEndTime() { ! return fetchData.getArcEndTime(); } long getFetchStep() { ! return fetchData.getStep(); } *************** *** 111,113 **** --- 113,119 ---- return agg.get95Percentile(tStart, tEnd); } + + boolean isLoaded() { + return fetchData != null; + } } Index: Aggregator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Aggregator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Aggregator.java 15 Dec 2004 14:55:41 -0000 1.1 --- Aggregator.java 16 Dec 2004 11:16:03 -0000 1.2 *************** *** 33,55 **** import java.util.Arrays; ! /** ! * Class used to calculate aggregated values (MIN, MAX, LAST, FIRST, AVERAGE, TOTAL and 95-PERCENTILE) for ! * the given arrays of timestamps and associated datasource values. ! */ ! public class Aggregator implements ConsolFuns { private long timestamps[], step; private double[] values; ! /** ! * Constructs Aggregator object. Note that you have to supply two arrays to the constructor: an array ! * of timestamps and an array of datasource values. Aggregator assumes that:<p> ! * <ul> ! * <li>these two arrays have the same length ! * <li>the time step between consecutive timestamps is constant. ! * </ul> ! * @param timestamps Array of timestamps (in seconds, without milliseconds) ! * @param values Array of corresponding datasource values ! */ ! public Aggregator(long[] timestamps, double[] values) { assert timestamps.length == values.length: "Incompatible timestamps/values arrays (unequal lengths)"; assert timestamps.length >= 2: "At least two timestamps must be supplied"; --- 33,41 ---- import java.util.Arrays; ! class Aggregator implements ConsolFuns { private long timestamps[], step; private double[] values; ! Aggregator(long[] timestamps, double[] values) { assert timestamps.length == values.length: "Incompatible timestamps/values arrays (unequal lengths)"; assert timestamps.length >= 2: "At least two timestamps must be supplied"; *************** *** 59,70 **** } ! /** ! * Returns an object representing all aggregated values (MIN, MAX, LAST, FIRST, AVERAGE, TOTAL) ! * calculated from arrays supplied in the constructor. ! * @param tStart Starting timestamp of aggregation interval ! * @param tEnd Ending timestamp of aggregation interval ! * @return Object containing all aggregated values. ! */ ! public Aggregates getAggregates(long tStart, long tEnd) { Aggregates agg = new Aggregates(); long totalSeconds = 0; --- 45,49 ---- } ! Aggregates getAggregates(long tStart, long tEnd) { Aggregates agg = new Aggregates(); long totalSeconds = 0; *************** *** 93,112 **** } ! /** ! * 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 tStart Starting timestamp of aggregation interval ! * @param tEnd Ending timestamp of aggregation interval ! * @return 95-percentile value ! */ ! public double get95Percentile(long tStart, long tEnd) { List valueList = new ArrayList(); // create a list of included datasource values (different from NaN) --- 72,76 ---- } ! double get95Percentile(long tStart, long tEnd) { List valueList = new ArrayList(); // create a list of included datasource values (different from NaN) |