draw graphs by_temp buckets daily
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 9 Nov 2020 18:07:32 +0000 (19:07 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 9 Nov 2020 18:08:43 +0000 (19:08 +0100)
gnuplot/by_temp.gnuplot [new file with mode: 0644]
gnuplot/by_temp.sql [new file with mode: 0644]
www/cgi-bin/by_temp.cgi [new file with mode: 0755]
www/rijeka-by_temp.html [new file with mode: 0644]

diff --git a/gnuplot/by_temp.gnuplot b/gnuplot/by_temp.gnuplot
new file mode 100644 (file)
index 0000000..020c0b7
--- /dev/null
@@ -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 (file)
index 0000000..cd936e6
--- /dev/null
@@ -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 (executable)
index 0000000..5af4d17
--- /dev/null
@@ -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 (file)
index 0000000..2dec8dd
--- /dev/null
@@ -0,0 +1,38 @@
+<html>
+<head>
+       <meta charset="utf-8" />
+       <title>Rijeka - senzori nagiba (+/- 2 stupnja C)</title>
+</head>
+<body>
+
+       <p>
+       <img src="logo-color.png">
+
+       <h1>2OI-000115</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050082" width="100%">
+
+       <h1>2OI-000116</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050080" width="100%">
+
+       <h1>2OI-000117</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050078" width="100%">
+
+       <h1>2OI-000118</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050083" width="100%">
+
+       <h1>2OI-000119</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050084" width="100%">
+
+       <!--
+       <h1>2OI-000120</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050079" width="100%">
+       -->
+       <h1>2OI-000124</h1>
+       <img src="cgi-bin/by_temp.cgi?2008050081" width="100%">
+
+
+
+
+       </p>
+
+</body>