From: Tarus B. <ta...@us...> - 2006-12-21 18:02:48
|
Update of /cvsroot/jrobin/src/org/jrobin/data In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9082/org/jrobin/data Modified Files: Aggregates.java Aggregator.java CDef.java CubicSplineInterpolator.java DataProcessor.java Def.java LinearInterpolator.java Normalizer.java PDef.java Plottable.java RpnCalculator.java SDef.java Source.java Log Message: Adding the new 1.5.4 code Index: DataProcessor.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/DataProcessor.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** DataProcessor.java 6 Apr 2005 20:10:09 -0000 1.11 --- DataProcessor.java 21 Dec 2006 18:02:43 -0000 1.12 *************** *** 1,961 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) [...1825 lines suppressed...] ! System.out.println("Data processed in " + (System.currentTimeMillis() - laptime) + " milliseconds\n---"); ! System.out.println(dp.dump()); ! ! // aggregates ! System.out.println("\nAggregates for X"); ! Aggregates agg = dp.getAggregates("X"); ! System.out.println(agg.dump()); ! System.out.println("\nAggregates for Y"); ! agg = dp.getAggregates("Y"); ! System.out.println(agg.dump()); ! ! // 95-percentile ! System.out.println("\n95-percentile for X: " + Util.formatDouble(dp.get95Percentile("X"))); ! System.out.println("95-percentile for Y: " + Util.formatDouble(dp.get95Percentile("Y"))); ! ! // lastArchiveUpdateTime ! System.out.println("\nLast archive update time was: " + dp.getLastRrdArchiveUpdateTime()); ! } ! } ! Index: CDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/CDef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CDef.java 15 Dec 2004 14:55:41 -0000 1.2 --- CDef.java 21 Dec 2006 18:02:43 -0000 1.3 *************** *** 1,39 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! class CDef extends Source { ! private String rpnExpression; ! ! CDef(String name, String rpnExpression) { ! super(name); ! this.rpnExpression = rpnExpression; ! } ! ! String getRpnExpression() { ! return rpnExpression; ! } ! } --- 1,39 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! class CDef extends Source { ! private String rpnExpression; ! ! CDef(String name, String rpnExpression) { ! super(name); ! this.rpnExpression = rpnExpression; ! } ! ! String getRpnExpression() { ! return rpnExpression; ! } ! } Index: Aggregates.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Aggregates.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Aggregates.java 6 Apr 2005 20:10:09 -0000 1.2 --- Aggregates.java 21 Dec 2006 18:02:42 -0000 1.3 *************** *** 1,136 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.ConsolFuns; ! import org.jrobin.core.RrdException; ! import org.jrobin.core.Util; ! ! /** ! * Simple class which holds aggregated values (MIN, MAX, FIRST, LAST, AVERAGE and TOTAL). You ! * don't need to create objects of this class directly. Objects of this class are returned from ! * <code>getAggregates()</code> method in ! * {@link org.jrobin.core.FetchData#getAggregates(String) FetchData} and ! * {@link DataProcessor#getAggregates(String)} DataProcessor} classes. ! */ ! public class Aggregates implements ConsolFuns { ! double min = Double.NaN, max = Double.NaN; ! double first = Double.NaN, last = Double.NaN; ! double average = Double.NaN, total = Double.NaN; ! ! Aggregates() { ! // NOP; ! } ! ! /** ! * Returns the minimal value ! * @return Minimal value ! */ ! public double getMin() { ! return min; ! } ! ! /** ! * Returns the maximum value ! * @return Maximum value ! */ ! public double getMax() { ! return max; ! } ! ! /** ! * Returns the first falue ! * @return First value ! */ ! public double getFirst() { ! return first; ! } ! ! /** ! * Returns the last value ! * @return Last value ! */ ! public double getLast() { ! return last; ! } ! ! /** ! * Returns average ! * @return Average value ! */ ! public double getAverage() { ! return average; ! } ! ! /** ! * Returns total value ! * @return Total value ! */ ! public double getTotal() { ! return total; ! } ! ! /** ! * Returns single aggregated value for the give consolidation function ! * @param consolFun Consolidation function: MIN, MAX, FIRST, LAST, AVERAGE, TOTAL. These constanst ! * are conveniently defined in the {@link org.jrobin.core.ConsolFuns ConsolFuns} interface. ! * @return Aggregated value ! * @throws RrdException Thrown if unsupported consolidation function is supplied ! */ ! public double getAggregate(String consolFun) throws RrdException { ! if(consolFun.equals(CF_AVERAGE) || consolFun.equalsIgnoreCase( "AVG" ) ) { ! return average; ! } ! else if(consolFun.equals(CF_FIRST)) { ! return first; ! } ! else if(consolFun.equals(CF_LAST)) { ! return last; ! } ! else if(consolFun.equals(CF_MAX) || consolFun.equalsIgnoreCase( "MAXIMUM" ) ) { ! return max; ! } ! else if(consolFun.equals(CF_MIN) || consolFun.equalsIgnoreCase( "MINIMUM" ) ) { ! return min; ! } ! else if(consolFun.equals(CF_TOTAL)) { ! return total; ! } ! else { ! throw new RrdException("Unknown consolidation function: " + consolFun); ! } ! } ! ! /** ! * Returns String representing all aggregated values. Just for debugging purposes. ! * @return String containing all aggregated values ! */ ! public String dump() { ! return "MIN=" + Util.formatDouble(min) + ", MAX=" + Util.formatDouble(max) + "\n" + ! "FIRST=" + Util.formatDouble(first) + ", LAST=" + Util.formatDouble(last) + "\n" + ! "AVERAGE=" + Util.formatDouble(average) + ", TOTAL=" + Util.formatDouble(total); ! } ! } --- 1,144 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.ConsolFuns; ! import org.jrobin.core.RrdException; ! import org.jrobin.core.Util; ! ! /** ! * Simple class which holds aggregated values (MIN, MAX, FIRST, LAST, AVERAGE and TOTAL). You ! * don't need to create objects of this class directly. Objects of this class are returned from ! * <code>getAggregates()</code> method in ! * {@link org.jrobin.core.FetchData#getAggregates(String) FetchData} and ! * {@link DataProcessor#getAggregates(String)} DataProcessor} classes. ! */ ! public class Aggregates implements ConsolFuns { ! double min = Double.NaN, max = Double.NaN; ! double first = Double.NaN, last = Double.NaN; ! double average = Double.NaN, total = Double.NaN; ! ! Aggregates() { ! // NOP; ! } ! ! /** ! * Returns the minimal value ! * ! * @return Minimal value ! */ ! public double getMin() { ! return min; ! } ! ! /** ! * Returns the maximum value ! * ! * @return Maximum value ! */ ! public double getMax() { ! return max; ! } ! ! /** ! * Returns the first falue ! * ! * @return First value ! */ ! public double getFirst() { ! return first; ! } ! ! /** ! * Returns the last value ! * ! * @return Last value ! */ ! public double getLast() { ! return last; ! } ! ! /** ! * Returns average ! * ! * @return Average value ! */ ! public double getAverage() { ! return average; ! } ! ! /** ! * Returns total value ! * ! * @return Total value ! */ ! public double getTotal() { ! return total; ! } ! ! /** ! * Returns single aggregated value for the give consolidation function ! * ! * @param consolFun Consolidation function: MIN, MAX, FIRST, LAST, AVERAGE, TOTAL. These constanst ! * are conveniently defined in the {@link org.jrobin.core.ConsolFuns ConsolFuns} interface. ! * @return Aggregated value ! * @throws RrdException Thrown if unsupported consolidation function is supplied ! */ ! public double getAggregate(String consolFun) throws RrdException { ! if (consolFun.equals(CF_AVERAGE)) { ! return average; ! } ! else if (consolFun.equals(CF_FIRST)) { ! return first; ! } ! else if (consolFun.equals(CF_LAST)) { ! return last; ! } ! else if (consolFun.equals(CF_MAX)) { ! return max; ! } ! else if (consolFun.equals(CF_MIN)) { ! return min; ! } ! else if (consolFun.equals(CF_TOTAL)) { ! return total; ! } ! else { ! throw new RrdException("Unknown consolidation function: " + consolFun); ! } ! } ! ! /** ! * Returns String representing all aggregated values. Just for debugging purposes. ! * ! * @return String containing all aggregated values ! */ ! public String dump() { ! return "MIN=" + Util.formatDouble(min) + ", MAX=" + Util.formatDouble(max) + "\n" + ! "FIRST=" + Util.formatDouble(first) + ", LAST=" + Util.formatDouble(last) + "\n" + ! "AVERAGE=" + Util.formatDouble(average) + ", TOTAL=" + Util.formatDouble(total); ! } ! } Index: Plottable.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Plottable.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Plottable.java 6 Sep 2005 20:40:54 -0000 1.1.1.1 --- Plottable.java 21 Dec 2006 18:02:43 -0000 1.2 *************** *** 30,42 **** * that represents that datasource, and then pass this class on to the RrdGraphDef.</p> */ ! public abstract class Plottable ! { /** * Retrieves datapoint value based on a given timestamp. * Use this method if you only have one series of data in this class. * @param timestamp Timestamp in seconds for the datapoint. * @return Double value of the datapoint. */ ! public double getValue( long timestamp ) { return Double.NaN; } --- 30,42 ---- * that represents that datasource, and then pass this class on to the RrdGraphDef.</p> */ ! public abstract class Plottable { /** * Retrieves datapoint value based on a given timestamp. * Use this method if you only have one series of data in this class. + * * @param timestamp Timestamp in seconds for the datapoint. * @return Double value of the datapoint. */ ! public double getValue(long timestamp) { return Double.NaN; } Index: Source.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Source.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Source.java 29 Dec 2004 11:36:50 -0000 1.4 --- Source.java 21 Dec 2006 18:02:43 -0000 1.5 *************** *** 1,69 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.ConsolFuns; ! import org.jrobin.core.RrdException; ! ! abstract class Source implements ConsolFuns { ! final private String name; ! protected double[] values; ! protected long[] timestamps; ! ! Source(String name) { ! this.name = name; ! } ! ! String getName() { ! return name; ! } ! ! void setValues(double[] values) { ! this.values = values; ! } ! ! void setTimestamps(long[] timestamps) { ! this.timestamps = timestamps; ! } ! ! double[] getValues() { ! return values; ! } ! ! long[] getTimestamps() { ! return timestamps; ! } ! ! Aggregates getAggregates(long tStart, long tEnd) throws RrdException { ! Aggregator agg = new Aggregator(timestamps, values); ! return agg.getAggregates(tStart, tEnd); ! } ! ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { ! Aggregator agg = new Aggregator(timestamps, values); ! return agg.getPercentile(tStart, tEnd, percentile); ! } ! } --- 1,69 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.ConsolFuns; ! import org.jrobin.core.RrdException; ! ! abstract class Source implements ConsolFuns { ! final private String name; ! protected double[] values; ! protected long[] timestamps; ! ! Source(String name) { ! this.name = name; ! } ! ! String getName() { ! return name; ! } ! ! void setValues(double[] values) { ! this.values = values; ! } ! ! void setTimestamps(long[] timestamps) { ! this.timestamps = timestamps; ! } ! ! double[] getValues() { ! return values; ! } ! ! long[] getTimestamps() { ! return timestamps; ! } ! ! Aggregates getAggregates(long tStart, long tEnd) throws RrdException { ! Aggregator agg = new Aggregator(timestamps, values); ! return agg.getAggregates(tStart, tEnd); ! } ! ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { ! Aggregator agg = new Aggregator(timestamps, values); ! return agg.getPercentile(tStart, tEnd, percentile); ! } ! } Index: Aggregator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Aggregator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Aggregator.java 29 Dec 2004 11:36:50 -0000 1.3 --- Aggregator.java 21 Dec 2006 18:02:42 -0000 1.4 *************** *** 1,113 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.ConsolFuns; ! import org.jrobin.core.Util; ! ! import java.util.List; ! import java.util.ArrayList; ! 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"; ! this.timestamps = timestamps; ! this.values = values; ! this.step = timestamps[1] - timestamps[0]; ! } ! ! Aggregates getAggregates(long tStart, long tEnd) { ! Aggregates agg = new Aggregates(); ! long totalSeconds = 0; ! boolean firstFound = false; ! for (int i = 0; i < timestamps.length; i++) { ! long left = Math.max(timestamps[i] - step, tStart); ! long right = Math.min(timestamps[i], tEnd); ! long delta = right - left; ! if (delta > 0) { ! double value = values[i]; ! agg.min = Util.min(agg.min, value); ! agg.max = Util.max(agg.max, value); ! if (!firstFound) { ! agg.first = value; ! firstFound = true; ! } ! agg.last = value; ! if (!Double.isNaN(value)) { ! agg.total = Util.sum(agg.total, delta * value); ! totalSeconds += delta; ! } ! } ! } ! agg.average = totalSeconds > 0 ? (agg.total / totalSeconds) : Double.NaN; ! return agg; ! } ! ! double getPercentile(long tStart, long tEnd, double percentile) { ! List valueList = new ArrayList(); ! // create a list of included datasource values (different from NaN) ! for (int i = 0; i < timestamps.length; i++) { ! long left = Math.max(timestamps[i] - step, tStart); ! long right = Math.min(timestamps[i], tEnd); ! if (right > left && !Double.isNaN(values[i])) { ! valueList.add(new Double(values[i])); ! } ! } ! // create an array to work with ! int count = valueList.size(); ! if (count > 1) { ! double[] valuesCopy = new double[count]; ! for (int i = 0; i < count; i++) { ! valuesCopy[i] = ((Double) valueList.get(i)).doubleValue(); ! } ! // 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) { ! return valuesCopy[count - 1]; ! } ! } ! // not enough data available ! return Double.NaN; ! } ! ! /* ! public static void main(String[] args) { ! long[] t = {10, 20, 30, 40}; ! double[] v = {2, Double.NaN, 3, 1}; ! Aggregator agg = new Aggregator(t, v); ! System.out.println(agg.getAggregates(0, 40).dump()); ! } ! */ ! } --- 1,104 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.ConsolFuns; ! import org.jrobin.core.Util; ! ! import java.util.ArrayList; ! import java.util.Arrays; ! import java.util.List; ! ! 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"; ! this.timestamps = timestamps; ! this.values = values; ! this.step = timestamps[1] - timestamps[0]; ! } ! ! Aggregates getAggregates(long tStart, long tEnd) { ! Aggregates agg = new Aggregates(); ! long totalSeconds = 0; ! boolean firstFound = false; ! for (int i = 0; i < timestamps.length; i++) { ! long left = Math.max(timestamps[i] - step, tStart); ! long right = Math.min(timestamps[i], tEnd); ! long delta = right - left; ! if (delta > 0) { ! double value = values[i]; ! agg.min = Util.min(agg.min, value); ! agg.max = Util.max(agg.max, value); ! if (!firstFound) { ! agg.first = value; ! firstFound = true; ! } ! agg.last = value; ! if (!Double.isNaN(value)) { ! agg.total = Util.sum(agg.total, delta * value); ! totalSeconds += delta; ! } ! } ! } ! agg.average = totalSeconds > 0 ? (agg.total / totalSeconds) : Double.NaN; ! return agg; ! } ! ! double getPercentile(long tStart, long tEnd, double percentile) { ! List<Double> valueList = new ArrayList<Double>(); ! // create a list of included datasource values (different from NaN) ! for (int i = 0; i < timestamps.length; i++) { ! long left = Math.max(timestamps[i] - step, tStart); ! long right = Math.min(timestamps[i], tEnd); ! if (right > left && !Double.isNaN(values[i])) { ! valueList.add(values[i]); ! } ! } ! // create an array to work with ! int count = valueList.size(); ! if (count > 1) { ! double[] valuesCopy = new double[count]; ! for (int i = 0; i < count; i++) { ! valuesCopy[i] = valueList.get(i); ! } ! // 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) { ! return valuesCopy[count - 1]; ! } ! } ! // not enough data available ! return Double.NaN; ! } ! } Index: Normalizer.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Normalizer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Normalizer.java 15 Dec 2004 14:55:41 -0000 1.1 --- Normalizer.java 21 Dec 2006 18:02:43 -0000 1.2 *************** *** 1,104 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.Util; ! import java.util.Arrays; ! ! class Normalizer { ! private long[] timestamps; ! int count; ! long step; ! ! Normalizer(long[] timestamps) { ! this.timestamps = timestamps; ! this.step = timestamps[1] - timestamps[0]; ! this.count = timestamps.length; ! } ! ! double[] normalize(long[] rawTimestamps, double[] rawValues) { ! int rawCount = rawTimestamps.length; ! long rawStep = rawTimestamps[1] - rawTimestamps[0]; ! // check if we have a simple match ! if(rawCount == count && rawStep == step && rawTimestamps[0] == timestamps[0]) { ! return getCopyOf(rawValues); ! } ! // reset all normalized values to NaN ! double[] values = new double[count]; ! Arrays.fill(values, Double.NaN); ! for (int rawSeg = 0, seg = 0; rawSeg < rawCount && seg < count; rawSeg++) { ! double rawValue = rawValues[rawSeg]; ! if (!Double.isNaN(rawValue)) { ! long rawLeft = rawTimestamps[rawSeg] - rawStep; ! while (seg < count && rawLeft >= timestamps[seg]) { ! seg++; ! } ! boolean overlap = true; ! for (int fillSeg = seg; overlap && fillSeg < count; fillSeg++) { ! long left = timestamps[fillSeg] - step; ! long t1 = Math.max(rawLeft, left); ! long t2 = Math.min(rawTimestamps[rawSeg], timestamps[fillSeg]); ! if (t1 < t2) { ! values[fillSeg] = Util.sum(values[fillSeg], (t2 - t1) * rawValues[rawSeg]); ! } ! else { ! overlap = false; ! } ! } ! } ! } ! for (int seg = 0; seg < count; seg++) { ! values[seg] /= step; ! } ! return values; ! } ! ! private static double[] getCopyOf(double[] rawValues) { ! int n = rawValues.length; ! double[] values = new double[n]; ! for(int i = 0; i < n; i++) { ! values[i] = rawValues[i]; ! } ! return values; ! } ! ! private static void dump(long[] t, double[] v) { ! for(int i = 0; i < v.length; i++) { ! System.out.print("[" + t[i] + "," + v[i] + "] "); ! } ! System.out.println(""); ! } ! ! public static void main(String[] args) { ! long rawTime[] = {100, 120, 140, 160, 180, 200}; ! double rawValues[] = {10, 30, 20, Double.NaN, 50, 40}; ! long time[] = {60, 100, 140, 180, 220, 260, 300}; ! Normalizer n = new Normalizer(time); ! double[] values = n.normalize(rawTime, rawValues); ! dump(rawTime, rawValues); ! dump(time, values); ! } ! } --- 1,87 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.Util; ! ! import java.util.Arrays; ! ! class Normalizer { ! final private long[] timestamps; ! final int count; ! final long step; ! ! Normalizer(long[] timestamps) { ! this.timestamps = timestamps; ! this.step = timestamps[1] - timestamps[0]; ! this.count = timestamps.length; ! } ! ! double[] normalize(long[] rawTimestamps, double[] rawValues) { ! int rawCount = rawTimestamps.length; ! long rawStep = rawTimestamps[1] - rawTimestamps[0]; ! // check if we have a simple match ! if (rawCount == count && rawStep == step && rawTimestamps[0] == timestamps[0]) { ! return getCopyOf(rawValues); ! } ! // reset all normalized values to NaN ! double[] values = new double[count]; ! Arrays.fill(values, Double.NaN); ! for (int rawSeg = 0, seg = 0; rawSeg < rawCount && seg < count; rawSeg++) { ! double rawValue = rawValues[rawSeg]; ! if (!Double.isNaN(rawValue)) { ! long rawLeft = rawTimestamps[rawSeg] - rawStep; ! while (seg < count && rawLeft >= timestamps[seg]) { ! seg++; ! } ! boolean overlap = true; ! for (int fillSeg = seg; overlap && fillSeg < count; fillSeg++) { ! long left = timestamps[fillSeg] - step; ! long t1 = Math.max(rawLeft, left); ! long t2 = Math.min(rawTimestamps[rawSeg], timestamps[fillSeg]); ! if (t1 < t2) { ! values[fillSeg] = Util.sum(values[fillSeg], (t2 - t1) * rawValues[rawSeg]); ! } ! else { ! overlap = false; ! } ! } ! } ! } ! for (int seg = 0; seg < count; seg++) { ! values[seg] /= step; ! } ! return values; ! } ! ! private static double[] getCopyOf(double[] rawValues) { ! int n = rawValues.length; ! double[] values = new double[n]; ! System.arraycopy(rawValues, 0, values, 0, n); ! return values; ! } ! } ! Index: SDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/SDef.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SDef.java 29 Dec 2004 11:36:50 -0000 1.3 --- SDef.java 21 Dec 2006 18:02:43 -0000 1.4 *************** *** 1,69 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.RrdException; ! ! class SDef extends Source { ! private String defName; ! private String consolFun; ! private double value; ! ! SDef(String name, String defName, String consolFun) { ! super(name); ! this.defName = defName; ! this.consolFun = consolFun; ! } ! ! String getDefName() { ! return defName; ! } ! ! String getConsolFun() { ! return consolFun; ! } ! ! void setValue(double value) { ! this.value = value; ! int count = getTimestamps().length; ! double[] values = new double[count]; ! for(int i = 0; i < count; i++) { ! values[i] = value; ! } ! setValues(values); ! } ! ! Aggregates getAggregates(long tStart, long tEnd) throws RrdException { ! Aggregates agg = new Aggregates(); ! agg.first = agg.last = agg.min = agg.max = agg.average = value; ! agg.total = value * (tEnd - tStart); ! return agg; ! } ! ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { ! return value; ! } ! } --- 1,69 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.RrdException; ! ! class SDef extends Source { ! private String defName; ! private String consolFun; ! private double value; ! ! SDef(String name, String defName, String consolFun) { ! super(name); ! this.defName = defName; ! this.consolFun = consolFun; ! } ! ! String getDefName() { ! return defName; ! } ! ! String getConsolFun() { ! return consolFun; ! } ! ! void setValue(double value) { ! this.value = value; ! int count = getTimestamps().length; ! double[] values = new double[count]; ! for (int i = 0; i < count; i++) { ! values[i] = value; ! } ! setValues(values); ! } ! ! Aggregates getAggregates(long tStart, long tEnd) throws RrdException { ! Aggregates agg = new Aggregates(); ! agg.first = agg.last = agg.min = agg.max = agg.average = value; ! agg.total = value * (tEnd - tStart); ! return agg; ! } ! ! double getPercentile(long tStart, long tEnd, double percentile) throws RrdException { ! return value; ! } ! } Index: RpnCalculator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/RpnCalculator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RpnCalculator.java 15 Dec 2004 14:55:41 -0000 1.3 --- RpnCalculator.java 21 Dec 2006 18:02:43 -0000 1.4 *************** *** 1,562 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) [...1092 lines suppressed...] ! } ! return stack[pos - 1]; ! } ! ! void reset() { ! pos = 0; ! } ! ! boolean isEmpty() { ! return pos <= 0; ! } ! } ! ! private class Token { ! byte id = -1; ! double number = Double.NaN; ! String variable = null; ! double[] values = null; ! } ! } Index: Def.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/Def.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Def.java 29 Dec 2004 11:36:50 -0000 1.5 --- Def.java 21 Dec 2006 18:02:43 -0000 1.6 *************** *** 1,119 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.Util; ! import org.jrobin.core.FetchData; ! import org.jrobin.core.RrdException; ! ! import java.io.IOException; ! ! class Def extends Source { ! 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) { ! this(name, path, dsName, consolFunc, null); ! } ! ! Def(String name, String path, String dsName, String consolFunc, String backend) { ! super(name); ! this.path = path; ! this.dsName = dsName; ! this.consolFun = consolFunc; ! this.backend = backend; ! } ! ! String getPath() { ! return path; ! } ! ! String getCanonicalPath() throws IOException { ! return Util.getCanonicalPath(path); ! } ! ! String getDsName() { ! return dsName; ! } ! ! String getConsolFun() { ! return consolFun; ! } ! ! String getBackend() { ! return backend; ! } ! ! boolean isCompatibleWith(Def def) throws IOException { ! return getCanonicalPath().equals(def.getCanonicalPath()) && ! getConsolFun().equals(def.consolFun) && ! ((backend == null && def.backend == null) || ! (backend != null && def.backend != null && backend.equals(def.backend))); ! } ! ! void setFetchData(FetchData fetchData) { ! this.fetchData = fetchData; ! } ! ! long[] getRrdTimestamps() { ! return fetchData.getTimestamps(); ! } ! ! double[] getRrdValues() throws RrdException { ! return fetchData.getValues(dsName); ! } ! ! long getArchiveEndTime() { ! return fetchData.getArcEndTime(); ! } ! ! long getFetchStep() { ! return fetchData.getStep(); ! } ! ! Aggregates getAggregates(long tStart, long tEnd) throws RrdException { ! long[] t = getRrdTimestamps(); ! double[] v = getRrdValues(); ! Aggregator agg = new Aggregator(t, v); ! return agg.getAggregates(tStart, tEnd); ! } ! ! 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); ! } ! ! boolean isLoaded() { ! return fetchData != null; ! } ! } --- 1,119 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.core.FetchData; ! import org.jrobin.core.RrdException; ! import org.jrobin.core.Util; ! ! import java.io.IOException; ! ! class Def extends Source { ! 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) { ! this(name, path, dsName, consolFunc, null); ! } ! ! Def(String name, String path, String dsName, String consolFunc, String backend) { ! super(name); ! this.path = path; ! this.dsName = dsName; ! this.consolFun = consolFunc; ! this.backend = backend; ! } ! ! String getPath() { ! return path; ! } ! ! String getCanonicalPath() throws IOException { ! return Util.getCanonicalPath(path); ! } ! ! String getDsName() { ! return dsName; ! } ! ! String getConsolFun() { ! return consolFun; ! } ! ! String getBackend() { ! return backend; ! } ! ! boolean isCompatibleWith(Def def) throws IOException { ! return getCanonicalPath().equals(def.getCanonicalPath()) && ! getConsolFun().equals(def.consolFun) && ! ((backend == null && def.backend == null) || ! (backend != null && def.backend != null && backend.equals(def.backend))); ! } ! ! void setFetchData(FetchData fetchData) { ! this.fetchData = fetchData; ! } ! ! long[] getRrdTimestamps() { ! return fetchData.getTimestamps(); ! } ! ! double[] getRrdValues() throws RrdException { ! return fetchData.getValues(dsName); ! } ! ! long getArchiveEndTime() { ! return fetchData.getArcEndTime(); ! } ! ! long getFetchStep() { ! return fetchData.getStep(); ! } ! ! Aggregates getAggregates(long tStart, long tEnd) throws RrdException { ! long[] t = getRrdTimestamps(); ! double[] v = getRrdValues(); ! Aggregator agg = new Aggregator(t, v); ! return agg.getAggregates(tStart, tEnd); ! } ! ! 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); ! } ! ! boolean isLoaded() { ! return fetchData != null; ! } ! } Index: PDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/PDef.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PDef.java 15 Dec 2004 14:55:41 -0000 1.2 --- PDef.java 21 Dec 2006 18:02:43 -0000 1.3 *************** *** 1,64 **** ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * Arne Vandamme (cob...@jr...) ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! import org.jrobin.graph.Plottable; ! ! class PDef extends Source { ! private final Plottable plottable; ! ! PDef(String name, Plottable plottable) { ! super(name); ! this.plottable = plottable; ! } ! ! PDef(String name, final Plottable plottable, final int index) { ! super(name); ! this.plottable = new Plottable() { ! public double getValue(long timestamp) { ! return plottable.getValue(timestamp, index); ! } ! }; ! } ! ! PDef(String name, final Plottable plottable, final String sourceName) { ! super(name); ! this.plottable = new Plottable() { ! public double getValue(long timestamp) { ! return plottable.getValue(timestamp, sourceName); ! } ! }; ! } ! ! void calculateValues() { ! long[] times = getTimestamps(); ! double[] vals = new double[times.length]; ! for(int i = 0; i < times.length; i++) { ! vals[i] = plottable.getValue(times[i]); ! } ! setValues(vals); ! } ! } --- 1,44 ---- ! /* ============================================================ ! * JRobin : Pure java implementation of RRDTool's functionality ! * ============================================================ ! * ! * Project Info: http://www.jrobin.org ! * Project Lead: Sasa Markovic (sa...@jr...); ! * ! * (C) Copyright 2003-2005, by Sasa Markovic. ! * ! * Developers: Sasa Markovic (sa...@jr...) ! * ! * ! * This library is free software; you can redistribute it and/or modify it under the terms ! * of the GNU Lesser General Public License as published by the Free Software Foundation; ! * either version 2.1 of the License, or (at your option) any later version. ! * ! * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; ! * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ! * See the GNU Lesser General Public License for more details. ! * ! * You should have received a copy of the GNU Lesser General Public License along with this ! * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, ! * Boston, MA 02111-1307, USA. ! */ ! ! package org.jrobin.data; ! ! class PDef extends Source { ! private final Plottable plottable; ! ! PDef(String name, Plottable plottable) { ! super(name); ! this.plottable = plottable; ! } ! ! void calculateValues() { ! long[] times = getTimestamps(); ! double[] vals = new double[times.length]; ! for (int i = 0; i < times.length; i++) { ! vals[i] = plottable.getValue(times[i]); ! } ! setValues(vals); ! } ! } Index: LinearInterpolator.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/data/LinearInterpolator.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LinearInterpolator.java 6 Sep 2005 20:40:54 -0000 1.1.1.1 --- LinearInterpolator.java 21 Dec 2006 18:02:43 -0000 1.2 *************** *** 34,38 **** * Class used to interpolate datasource values from the collection of (timestamp, values) * points. This class is suitable for linear interpolation only. <p> ! * * Interpolation algorithm returns different values based on the value passed to * {@link #setInterpolationMethod(int) setInterpolationMethod()}. If not set, interpolation --- 34,38 ---- * Class used to interpolate datasource values from the collection of (timestamp, values) * points. This class is suitable for linear interpolation only. <p> ! * <p/> * Interpolation algorithm returns different values based on the value passed to * {@link #setInterpolationMethod(int) setInterpolationMethod()}. If not set, interpolation *************** *** 40,57 **** * Interpolation method handles NaN datasource * values gracefully.<p> - * */ public class LinearInterpolator extends Plottable { ! /** constant used to specify LEFT interpolation. ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_LEFT = 0; ! /** constant used to specify RIGHT interpolation. ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_RIGHT = 1; ! /** constant used to specify LINEAR interpolation (default interpolation method). ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_LINEAR = 2; ! /** constant used to specify LINEAR REGRESSION as interpolation method. ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. */ public static final int INTERPOLATE_REGRESSION = 3; --- 40,64 ---- * Interpolation method handles NaN datasource * values gracefully.<p> */ public class LinearInterpolator extends Plottable { ! /** ! * constant used to specify LEFT interpolation. ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. ! */ public static final int INTERPOLATE_LEFT = 0; ! /** ! * constant used to specify RIGHT interpolation. ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. ! */ public static final int INTERPOLATE_RIGHT = 1; ! /** ! * constant used to specify LINEAR interpolation (default interpolation method). ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. ! */ public static final int INTERPOLATE_LINEAR = 2; ! /** ! * constant used to specify LINEAR REGRESSION as interpolation method. ! * See {@link #setInterpolationMethod(int) setInterpolationMethod()} for explanation. ! */ public static final int INTERPOLATE_REGRESSION = 3; *************** *** 67,74 **** /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. * @param timestamps timestamps in seconds ! * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if ! * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(long[] timestamps, double[] values) throws RrdException { --- 74,82 ---- /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. + * * @param timestamps timestamps in seconds ! * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if ! * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(long[] timestamps, double[] values) throws RrdException { *************** *** 80,92 **** /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. ! * @param dates Array of Date objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if ! * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(Date[] dates, double[] values) throws RrdException { this.values = values; timestamps = new long[dates.length]; ! for(int i = 0; i < dates.length; i++) { timestamps[i] = Util.getTimestamp(dates[i]); } --- 88,101 ---- /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. ! * ! * @param dates Array of Date objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if ! * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(Date[] dates, double[] values) throws RrdException { this.values = values; timestamps = new long[dates.length]; ! for (int i = 0; i < dates.length; i++) { timestamps[i] = Util.getTimestamp(dates[i]); } *************** *** 96,108 **** /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. ! * @param dates array of GregorianCalendar objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if ! * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(Calendar[] dates, double[] values) throws RrdException { this.values = values; timestamps = new long[dates.length]; ! for(int i = 0; i < dates.length; i++) { timestamps[i] = Util.getTimestamp(dates[i]); } --- 105,118 ---- /** * Creates LinearInterpolator from arrays of timestamps and corresponding datasource values. ! * ! * @param dates array of GregorianCalendar objects * @param values corresponding datasource values * @throws RrdException Thrown if supplied arrays do not contain at least two values, or if ! * timestamps are not ordered, or array lengths are not equal. */ public LinearInterpolator(Calendar[] dates, double[] values) throws RrdException { this.values = values; timestamps = new long[dates.length]; ! for (int i = 0; i < dates.length; i++) { timestamps[i] = Util.getTimestamp(dates[i]); } *************** *** 112,124 **** private void validate() throws RrdException { boolean ok = true; ! if(timestamps.length != values.length || timestamps.length < 2) { ok = false; } ! for(int i = 0; i < timestamps.length - 1 && ok; i++) { ! if(timestamps[i] >= timestamps[i + 1]) { ok = false; } } ! if(!ok) { throw new RrdException("Invalid plottable data supplied"); } --- 122,134 ---- private void validate() throws RrdException { boolean ok = true; ! if (timestamps.length != values.length || timestamps.length < 2) { ok = false; } ! for (int i = 0; i < timestamps.length - 1 && ok; i++) { ! if (timestamps[i] >= timestamps[i + 1]) { ok = false; } } ! if (!ok) { throw new RrdException("Invalid plottable data supplied"); } *************** *** 135,154 **** * </ul> * If not set, interpolation method defaults to <code>INTERPOLATE_LINEAR</code>.<p> ! * * The fourth available interpolation method is INTERPOLATE_REGRESSION. This method uses * simple linear re... [truncated message content] |