extract mean and spread and use it to reject invalid data
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 Jul 2017 06:34:34 +0000 (08:34 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 26 Jul 2017 06:34:34 +0000 (08:34 +0200)
temp2.gnuplot
temp2.sh

index cbee3b7..028c94e 100644 (file)
@@ -14,10 +14,28 @@ set size 1, 0.5
 
 set origin 0.0, 0.5
 
-plot "/dev/shm/DS18B20-temperature" using ($1+7200):($2 > 3 && $2 < 45 ? $2 : '') with dots title "DS18B20 deg. C","/dev/shm/DHT22-temperature" using ($1+7200):($2 > 3 && $2 < 45 ? $2 : '') with dots title "DHT22 deg. C"
+if ( ! exists("t_mean")) {
+
+t_mean=26
+t_spread=5
+
+h_mean = 50
+h_spread = 30
+
+print "using default mean and spread"
+}
+
+min_t = t_mean - t_spread
+max_t = t_mean + t_spread
+
+plot "/dev/shm/DS18B20-temperature" using ($1+7200):($2 > min_t && $2 < max_t ? $2 : '') with dots title "DS18B20 deg. C","/dev/shm/DHT22-temperature" using ($1+7200):($2 > min_t && $2 < max_t ? $2 : '') with dots title "DHT22 deg. C"
 
 set origin 0.0, 0.0
 
-plot "/dev/shm/DHT22-humidity" using ($1+7200):($2 > 3 ? $2 : '') with dots title "DHT22 % hum"
+
+min_h = h_mean - h_spread
+max_h = h_mean + h_spread
+
+plot "/dev/shm/DHT22-humidity" using ($1+7200):($2 > min_h && $2 < max_h ? $2 : '') with dots title "DHT22 % hum"
 
 unset multiplot
index bb2bedb..5d6fd76 100755 (executable)
--- a/temp2.sh
+++ b/temp2.sh
@@ -9,8 +9,12 @@ curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-url
 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - 48h AND \"topic\"='stat/boiler/DHT22/temperature'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DHT22-temperature
 curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT \"value\" FROM \"mqtt_consumer\" WHERE time > now() - 48h AND \"topic\"='stat/boiler/DHT22/humidity'" | sed -e 's/^.*"values":\[\[//' -e 's/\],\[/\n/g' -e 's/,/ /g' -e 's/]].*$//' > /dev/shm/DHT22-humidity
 
+curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT mean(\"value\"),spread(\"value\") FROM \"mqtt_consumer\" WHERE time > now() - 48h AND \"topic\"='stat/boiler/DS18B20/temperature'"  | jq '.results[0].series[0].values[0][1,2]' > /dev/shm/temperature.mean.spread
+curl -G 'http://10.60.0.89:8086/query' --data-urlencode "db=telegraf" --data-urlencode "epoch=s" --data-urlencode "q=SELECT mean(\"value\"),spread(\"value\") FROM \"mqtt_consumer\" WHERE time > now() - 48h AND \"topic\"='stat/boiler/DHT22/humidity'"  | jq '.results[0].series[0].values[0][1,2]' > /dev/shm/humidity.mean.spread
+
+
 cd /home/pi/vaillant-thermostat/
-gnuplot temp2.gnuplot
+gnuplot -e "t_mean=`head -1 /dev/shm/temperature.mean.spread`;t_spread=`tail -1 /dev/shm/temperature.mean.spread`;h_mean=`head -1 /dev/shm/humidity.mean.spread` ; h_spread=`tail -1 /dev/shm/humidity.mean.spread`" temp2.gnuplot
 convert /dev/shm/temp2.png -gravity center -extent 600x800 -colorspace Gray /dev/shm/temp2-gray.png
 # ln -s /dev/shm/temp2-gray.png /var/www/html/temp2.png