Parcourir la source

Date transition in rate of change calculation bandage.

Neal Wilson il y a 11 ans
Parent
révision
e603c4f513
1 fichiers modifiés avec 25 ajouts et 0 suppressions
  1. 25
    0
      src/rate.w

+ 25
- 0
src/rate.w Voir le fichier

@@ -60,6 +60,8 @@ to determine how the calculated value is presented. We never allow fewer than
60 60
 two cached values, but we can force the most volatile calculation by setting
61 61
 the cache time to 0 seconds.
62 62
 
63
+Measurement handling is a little bit different on a date transition.
64
+
63 65
 @<Remove stale measurements from rate cache@>=
64 66
 if(cache.size() > 2)
65 67
 {
@@ -70,6 +72,11 @@ if(cache.size() > 2)
70 72
 		{
71 73
 			cache.removeFirst();
72 74
 		}
75
+		else if(cache.back().time() < cache.front().time())
76
+		{
77
+			cache.removeFirst();
78
+			done = true;
79
+		}
73 80
 		else
74 81
 		{
75 82
 			done = true;
@@ -105,9 +112,27 @@ for(int i = 0; i < rates.size(); i++)
105 112
 }
106 113
 double pavg = acc /= rates.size();
107 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 118
 Measurement value(v2, cache.back().time(), cache.back().scale());
109 119
 value.insert("relative", true);
110 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 137
 @ The rest of the class implementation is trivial.
113 138
 

Chargement…
Annuler
Enregistrer