Browse Source

Date transition in rate of change calculation bandage.

Neal Wilson 11 years ago
parent
commit
e603c4f513
1 changed files with 25 additions and 0 deletions
  1. 25
    0
      src/rate.w

+ 25
- 0
src/rate.w View File

60
 two cached values, but we can force the most volatile calculation by setting
60
 two cached values, but we can force the most volatile calculation by setting
61
 the cache time to 0 seconds.
61
 the cache time to 0 seconds.
62
 
62
 
63
+Measurement handling is a little bit different on a date transition.
64
+
63
 @<Remove stale measurements from rate cache@>=
65
 @<Remove stale measurements from rate cache@>=
64
 if(cache.size() > 2)
66
 if(cache.size() > 2)
65
 {
67
 {
70
 		{
72
 		{
71
 			cache.removeFirst();
73
 			cache.removeFirst();
72
 		}
74
 		}
75
+		else if(cache.back().time() < cache.front().time())
76
+		{
77
+			cache.removeFirst();
78
+			done = true;
79
+		}
73
 		else
80
 		else
74
 		{
81
 		{
75
 			done = true;
82
 			done = true;
105
 }
112
 }
106
 double pavg = acc /= rates.size();
113
 double pavg = acc /= rates.size();
107
 double v2 = pavg * st;
114
 double v2 = pavg * st;
115
+double refm = cache.back().temperature() - cache.front().temperature();
116
+double reft = (double)(cache.front().time().msecsTo(cache.back().time())) / 1000.0;
117
+double ref = refm/reft;
108
 Measurement value(v2, cache.back().time(), cache.back().scale());
118
 Measurement value(v2, cache.back().time(), cache.back().scale());
109
 value.insert("relative", true);
119
 value.insert("relative", true);
110
 emit newData(value);
120
 emit newData(value);
121
+double calcdiff = ref - pavg;
122
+if(calcdiff < 0)
123
+{
124
+	calcdiff = -calcdiff;
125
+}
126
+if(pavg < 0)
127
+{
128
+	pavg = -pavg;
129
+}
130
+if(calcdiff > (pavg * 0.2))
131
+{
132
+	Measurement save = cache.back();
133
+	cache.clear();
134
+	cache.append(save);
135
+}
111
 
136
 
112
 @ The rest of the class implementation is trivial.
137
 @ The rest of the class implementation is trivial.
113
 
138
 

Loading…
Cancel
Save