|
From: <sa...@us...> - 2003-09-23 13:39:25
|
Update of /cvsroot/jrobin/src/jrobin/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv13583/jrobin/graph
Modified Files:
Def.java Source.java ValueExtractor.java
Log Message:
BUGFIX: removed problem with the last point int the graph - was NaN in most cases
Index: Def.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/Def.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Def.java 4 Sep 2003 13:27:14 -0000 1.1
--- Def.java 23 Sep 2003 13:39:21 -0000 1.2
***************
*** 49,53 ****
void setInterval(long start, long end) throws RrdException, IOException {
RrdDb rrd = new RrdDb(rrdPath);
! FetchRequest request = rrd.createFetchRequest(consolFun, start, end);
FetchPoint[] fetchPoints = request.fetch();
int numPoints = fetchPoints.length;
--- 49,54 ----
void setInterval(long start, long end) throws RrdException, IOException {
RrdDb rrd = new RrdDb(rrdPath);
! long rrdStep = rrd.getRrdDef().getStep();
! FetchRequest request = rrd.createFetchRequest(consolFun, start, end + rrdStep);
FetchPoint[] fetchPoints = request.fetch();
int numPoints = fetchPoints.length;
Index: Source.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/Source.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Source.java 4 Sep 2003 13:27:14 -0000 1.1
--- Source.java 23 Sep 2003 13:39:21 -0000 1.2
***************
*** 33,41 ****
abstract class Source {
protected String name = "";
! private double min;
! private double max;
! private double last;
! private double sum;
! private int count;
private RrdTimeSeries series;
--- 33,41 ----
abstract class Source {
protected String name = "";
!
! private long lastTime, totalTime;
! private double aggMin, aggMax, aggLast;
! private double lastValue, totalValue;
!
private RrdTimeSeries series;
***************
*** 59,63 ****
double value = getValue(timestamp, values);
series.add(timestamp, value);
! aggregate(value);
values.add(name, value);
return value;
--- 59,63 ----
double value = getValue(timestamp, values);
series.add(timestamp, value);
! aggregate(timestamp, value);
values.add(name, value);
return value;
***************
*** 69,88 ****
}
! private void aggregate(double value) {
! min = Util.min(min, value);
! max = Util.max(max, value);
! last = value;
! if(!Double.isNaN(value)) {
! sum += value;
! count++;
}
}
private void reset() {
! min = Double.NaN;
! max = Double.NaN;
! last = Double.NaN;
! sum = 0.0;
! count = 0;
series = new RrdTimeSeries(name);
}
--- 69,90 ----
}
! private void aggregate(long time, double value) {
! aggMin = Util.min(aggMin, value);
! aggMax = Util.max(aggMax, value);
! aggLast = value;
! if(!Double.isNaN(lastValue) && !Double.isNaN(value)) {
! long dt = time - lastTime;
! totalValue += dt * (value + lastValue) / 2.0;
! totalTime += dt;
}
+ lastTime = time;
+ lastValue = value;
}
private void reset() {
! lastTime = totalTime = 0;
! aggMin = aggMax = aggLast = lastValue = Double.NaN;
! totalValue = 0.0;
!
series = new RrdTimeSeries(name);
}
***************
*** 90,104 ****
double getAggregate(String consolFun) throws RrdException {
if(consolFun.equals("MAX")) {
! return max;
}
else if(consolFun.equals("MIN")) {
! return min;
}
else if(consolFun.equals("LAST")) {
! return last;
}
else if(consolFun.equals("AVERAGE")) {
! if(count > 0) {
! return sum / count;
}
else {
--- 92,106 ----
double getAggregate(String consolFun) throws RrdException {
if(consolFun.equals("MAX")) {
! return aggMax;
}
else if(consolFun.equals("MIN")) {
! return aggMin;
}
else if(consolFun.equals("LAST")) {
! return aggLast;
}
else if(consolFun.equals("AVERAGE")) {
! if(totalTime > 0) {
! return totalValue / totalTime;
}
else {
Index: ValueExtractor.java
===================================================================
RCS file: /cvsroot/jrobin/src/jrobin/graph/ValueExtractor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ValueExtractor.java 4 Sep 2003 13:27:14 -0000 1.1
--- ValueExtractor.java 23 Sep 2003 13:39:21 -0000 1.2
***************
*** 27,35 ****
class ValueExtractor {
private DataPoint[] points;
private int pos = 0;
ValueExtractor(DataPoint[] points) throws RrdException {
this.points = points;
! if(points.length < 2) {
throw new RrdException("At least two datapoints are required");
}
--- 27,37 ----
class ValueExtractor {
private DataPoint[] points;
+ private int numPoints;
private int pos = 0;
ValueExtractor(DataPoint[] points) throws RrdException {
this.points = points;
! this.numPoints = points.length;
! if(numPoints < 2) {
throw new RrdException("At least two datapoints are required");
}
***************
*** 40,44 ****
throw new RrdException("Backward reading not allowed");
}
! while(pos < points.length - 1) {
if(points[pos].getTime() <= timestamp && timestamp < points[pos + 1].getTime()) {
return points[pos + 1].getValue();
--- 42,46 ----
throw new RrdException("Backward reading not allowed");
}
! while(pos < numPoints - 1) {
if(points[pos].getTime() <= timestamp && timestamp < points[pos + 1].getTime()) {
return points[pos + 1].getValue();
|