# Changeset 2b223aba8b2de203fe480dd111bd6bd48b4792cc for src/java/com

- Timestamp:
- 11/06/09 20:12:35 (8 years ago)
- git-parent:
- Files:

### Legend:

- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved

## src/java/com/omniti/reconnoiter/esper/CounterView.java

rc75a210 r2b223ab 9 9 **************************************************************************************/ 10 10 package com.omniti.reconnoiter.esper; 11 12 ~~import java.math.BigDecimal;~~13 11 14 12 import com.omniti.reconnoiter.esper.DeriveView; … … 30 28 return new CounterView(statementContext, this.expressionX, this.expressionY); 31 29 } 32 protected ~~BigDecimal[] subtract(BigDecimal[] a, BigDecimal[]~~b)30 protected NoitDerivePoint subtract(NoitDerivePoint a, NoitDerivePoint b) 33 31 { 34 BigDecimal[] v = new BigDecimal[2]; 35 v[0] = a[0].subtract(b[0]); 36 v[1] = a[1].subtract(b[1]); 37 if(v[1].signum() < 0) v[0] = BigDecimal.ZERO; 32 NoitDerivePoint v = super.subtract(a,b); 33 if(v.Ylong < 0 || v.Ydouble < 0.0) v.X = 0; 38 34 return v; 39 35 } ## src/java/com/omniti/reconnoiter/esper/DeriveView.java

rc75a210 r2b223ab 22 22 import java.util.Iterator; 23 23 import java.util.Arrays; 24 ~~import java.math.BigDecimal;~~25 ~~import java.math.MathContext;~~26 24 27 25 /** … … 33 31 protected ExprNode expressionX; 34 32 protected ExprNode expressionY; 35 private boolean 33 private boolean isDouble; 36 34 private WeightedValueBean lastWVBean; 37 private ~~BigDecimal[]~~lastpoint;35 private NoitDerivePoint lastpoint; 38 36 39 37 /** … … 86 84 for ( EventBean pointb : newData ) { 87 85 EventBean eventsPerStream[] = { pointb }; 88 ~~BigDecimal X = new BigDecimal(((Number) expressionX.evaluate(eventsPerStream, true, statementContext)).toString()~~);89 ~~BigDecimal Y~~;86 NoitDerivePoint point = new NoitDerivePoint(); 87 point.X = ((Number) expressionX.evaluate(eventsPerStream, true, statementContext)).longValue(); 90 88 if(isDouble) 91 ~~Y = new BigDecimal(((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).doubleValue()~~);89 point.Ydouble = ((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).doubleValue(); 92 90 else 93 ~~Y = new BigDecimal(((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).toString()~~);91 point.Ylong = ((Number) expressionY.evaluate(eventsPerStream, true, statementContext)).longValue(); 94 92 95 ~~BigDecimal[] point = new BigDecimal[] {X,Y};~~96 93 if (lastpoint != null) { 97 94 try { 98 ~~BigDecimal[]~~sub = subtract(point,lastpoint);99 lastWVBean = new WeightedValueBean(sub ~~[0], sub[1].divide(sub[0],MathContext.DECIMAL128~~));95 NoitDerivePoint sub = subtract(point,lastpoint); 96 lastWVBean = new WeightedValueBean(sub.X, sub.ror(isDouble)); 100 97 EventBean eb = statementContext.getEventAdapterService().adapterForBean(lastWVBean); 101 98 derivedNew[i++] = eb; … … 116 113 } 117 114 118 protected ~~BigDecimal[] subtract(BigDecimal[] a, BigDecimal[]~~b)115 protected NoitDerivePoint subtract(NoitDerivePoint a, NoitDerivePoint b) 119 116 { 120 BigDecimal[] v = new BigDecimal[2]; 121 v[0] = a[0].subtract(b[0]); 122 v[1] = a[1].subtract(b[1]); 117 NoitDerivePoint v = new NoitDerivePoint(); 118 v.X = a.X - b.X; 119 v.Ylong = a.Ylong - b.Ylong; 120 v.Ydouble = a.Ydouble - b.Ydouble; 123 121 return v; 124 122 } … … 131 129 public final String toString() 132 130 { 133 return this.getClass().getName() + " lastpoint=" + lastpoint[0] + "," + lastpoint[1]; 131 return this.getClass().getName() + " lastpoint=" + lastpoint.X + "," + (isDouble ? lastpoint.Ydouble : lastpoint.Ylong); 132 } 133 134 protected class NoitDerivePoint { 135 public long X; 136 public long Ylong; 137 public double Ydouble; 138 public double ror(boolean isDouble) { 139 if(X == 0) return Double.NaN; 140 if(isDouble) return (Ydouble / (double)X); 141 else return ((double)Ylong / (double)X); 142 } 134 143 } 135 144 } ## src/java/com/omniti/reconnoiter/esper/WeightedValueBean.java

rc75a210 r2b223ab 2 2 3 3 import java.io.Serializable; 4 ~~import java.math.BigDecimal;~~5 4 6 5 /** … … 11 10 public class WeightedValueBean implements Cloneable, Serializable 12 11 { 13 private ~~double~~weight;12 private long weight; 14 13 private double value; 15 14 private static final long serialVersionUID = 7995123761256377184L; 16 15 17 public WeightedValueBean( ~~BigDecimal w, BigDecimal~~v) {18 weight = ~~(w == null) ? Double.NaN : w.doubleValue()~~;19 value = ~~(v == null) ? Double.NaN: v.doubleValue()~~;16 public WeightedValueBean(long w, double v) { 17 weight = w; 18 value = v; 20 19 } 21 20 22 public ~~double~~getWeight() { return weight; }21 public long getWeight() { return weight; } 23 22 public double getValue() { return value; } 24 public void setWeight( ~~double~~w) { weight = w; }23 public void setWeight(long w) { weight = w; } 25 24 public void setValue(double v) { value = v; } 26 25 }