From c5ed1420f53f0b1782fb8846f9814cd1aa634d3b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 9 Nov 2020 19:07:32 +0100 Subject: [PATCH] draw graphs by_temp buckets daily --- gnuplot/by_temp.gnuplot | 77 +++++++++++++++++++++++++++++++++++++++++ gnuplot/by_temp.sql | 13 +++++++ www/cgi-bin/by_temp.cgi | 43 +++++++++++++++++++++++ www/rijeka-by_temp.html | 38 ++++++++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 gnuplot/by_temp.gnuplot create mode 100644 gnuplot/by_temp.sql create mode 100755 www/cgi-bin/by_temp.cgi create mode 100644 www/rijeka-by_temp.html diff --git a/gnuplot/by_temp.gnuplot b/gnuplot/by_temp.gnuplot new file mode 100644 index 0000000..020c0b7 --- /dev/null +++ b/gnuplot/by_temp.gnuplot @@ -0,0 +1,77 @@ +set terminal pngcairo color size 800,600 +#set output 'axes.png' +set output + +set xdata time +set timefmt "%Y-%m-%d" + +set datafile separator "," + +#unset border +#set key outside +#set key top left horizontal + +set grid +set key outside tmargin center + +#set ylabel "°" +#set ylabel "deg." +#set ylabel "degrees" + +#set format x "%H:%M" + +set format x "" +#set format y "%.2f" +set yrange [ -0.1 : 0.1 ] + +#set arrow 1 from first,3 to last,3 nohead linestyle rgb "#ff0000" + +#set multiplot +set multiplot layout 3,1 + +set lmargin at screen 0.125 + +#set linetype 1 lc 'green' +set linetype 99 lc 'red' + +#plot "axes.txt" using 1:2 with lines title "X angle", "" using 1:(3) with dots notitle, "" using 1:(-3) with dots notitle + +set ylabel "X degrees" +plot "/dev/shm/by_temp.pn.18.txt" using 1:2 with lines title 18, \ +"/dev/shm/by_temp.pn.20.txt" using 1:2 with lines title 20, \ +"/dev/shm/by_temp.pn.22.txt" using 1:2 with lines title 22, \ +"/dev/shm/by_temp.pn.24.txt" using 1:2 with lines title 24, \ +"/dev/shm/by_temp.pn.26.txt" using 1:2 with lines title 26, \ +"/dev/shm/by_temp.pn.28.txt" using 1:2 with lines title 28 +# http://gnuplot-surprising.blogspot.com/2011/09/gnuplot-background-image.html +#'/home/dpavlin/zc/www/logo-color.png' binary filetype=png origin=(0,0) dx=0.5 dy=0.5 with rgbimage notitle + + +#plot "axes.txt" using 1:3 with lines title "Y angle", "" using 1:(3) with dots notitle, "" using 1:(-3) with dots notitle + +set tmargin 0 + +set ylabel "Y degrees" +plot "/dev/shm/by_temp.pn.18.txt" using 1:3 with lines title 18, \ +"/dev/shm/by_temp.pn.20.txt" using 1:3 with lines title 20, \ +"/dev/shm/by_temp.pn.22.txt" using 1:3 with lines title 22, \ +"/dev/shm/by_temp.pn.24.txt" using 1:3 with lines title 24, \ +"/dev/shm/by_temp.pn.26.txt" using 1:3 with lines title 26, \ +"/dev/shm/by_temp.pn.28.txt" using 1:3 with lines title 28 +#, "" using 1:(3) with dots notitle, "" using 1:(-3) with dots notitle + +set tmargin 0 + +set xlabel "time" +set format x "%d.%m." + +set ylabel "celsius" +set yrange [ * : * ] + +plot "/dev/shm/by_temp.pn.18.txt" using 1:4 with lines title 18, \ +"/dev/shm/by_temp.pn.20.txt" using 1:4 with lines title 20, \ +"/dev/shm/by_temp.pn.22.txt" using 1:4 with lines title 22, \ +"/dev/shm/by_temp.pn.24.txt" using 1:4 with lines title 24, \ +"/dev/shm/by_temp.pn.26.txt" using 1:4 with lines title 26, \ +"/dev/shm/by_temp.pn.28.txt" using 1:4 with lines title 28 + diff --git a/gnuplot/by_temp.sql b/gnuplot/by_temp.sql new file mode 100644 index 0000000..cd936e6 --- /dev/null +++ b/gnuplot/by_temp.sql @@ -0,0 +1,13 @@ +select + to_char(min(time), 'YYYY-MM-DD') as time, + avg(x_axis_angle) , + avg(y_axis_angle) , + avg(sensor_temperature) , + round((sensor_temperature / 2)) * 2 +from zc +where pn = 2008050087 -- and time > now() - interval '24 hours' +group by + to_char(time, 'YYYY-MM-DD'), + round((sensor_temperature / 2)) * 2 +order by time asc + diff --git a/www/cgi-bin/by_temp.cgi b/www/cgi-bin/by_temp.cgi new file mode 100755 index 0000000..5af4d17 --- /dev/null +++ b/www/cgi-bin/by_temp.cgi @@ -0,0 +1,43 @@ +#!/bin/sh + +dir=/home/dpavlin/zc/gnuplot/ + +set > /dev/shm/cgi.env + +echo "Content-type: image/svg+xml" +echo + +#pn=$( basename $0 | sed 's/.cgi//' ) +test -z "$QUERY_STRING" && QUERY_STRING='.' +numbers=$( grep "$QUERY_STRING" $dir/../subvision-numbers.txt | head -1 ) +pn=$( echo $numbers | cut -d' ' -f2 ) +temp_corr=$( echo $numbers | cut -d' ' -f5 ) +test -z "$temp_corr" && temp_corr=0.00001 + +offset=$( grep "^$pn" $dir/offset.txt ) +offset_x=$( echo $offset | cut -d' ' -f2 ) +test -z "$offset_x" && offset_x=0 +offset_y=$( echo $offset | cut -d' ' -f3 ) +test -z "$offset_y" && offset_y=0 + + +set > /dev/shm/by_temp.$pn.env + +cat $dir/by_temp.sql | sed \ + -e "s/2008050087/$pn/" \ + -e "s/x_axis_angle/x_axis_angle + $offset_x/" -e "s/y_axis_angle/y_axis_angle + $offset_y/" \ + -e "s/0.0001/$temp_corr/" \ +| tee /dev/shm/by_temp.$pn.sql \ +| psql --username=dpavlin -A -F "," -t zc \ +| tee /dev/shm/by_temp.$pn.txt \ +| awk -v pn=$pn -F, '{ print $1","$2","$3","$4 > "/dev/shm/by_temp."pn"."$5".txt" }' + +cat $dir/by_temp.gnuplot | sed \ + -e "s,\.pn\.,.$pn.," \ + -e "s,^set terminal.*$,set terminal svg," \ + -e "s,^set output.*$,set output," \ +> /dev/shm/by_temp.$pn.gnuplot + +gnuplot /dev/shm/by_temp.$pn.gnuplot + +#rm /dev/shm/axes.txt.$$ /dev/shm/axes.gnuplot.$$ diff --git a/www/rijeka-by_temp.html b/www/rijeka-by_temp.html new file mode 100644 index 0000000..2dec8dd --- /dev/null +++ b/www/rijeka-by_temp.html @@ -0,0 +1,38 @@ + + + + Rijeka - senzori nagiba (+/- 2 stupnja C) + + + +

+ + +

2OI-000115

+ + +

2OI-000116

+ + +

2OI-000117

+ + +

2OI-000118

+ + +

2OI-000119

+ + + +

2OI-000124

+ + + + + +

+ + -- 2.20.1