-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_daily_details.sh
executable file
·97 lines (84 loc) · 2.34 KB
/
plot_daily_details.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
#
# PVM PhotoVoltaic Monitor
#
# Plot daily details graph.
#
# Copyright (C) 2012 Pietro Pizzo <pietro.pizzo@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
cd `dirname $0`
# Read configuration file
eval $(cat config |grep output_dir)
eval $(cat config |grep daily_details_plot_file)
data_file=$daily_details_plot_file
# Parameters check
if [ $# -eq 1 ]; then
date_ref=$1
elif [ $# -eq 0 ]; then
date_ref=$(date +"%Y-%m-%d")
else
echo "Usage: `basename $0` [yyyy-mm-dd]" >&2
exit 1
fi
# Other checks
if [ ! -d $output_dir ]; then
echo "Output directory not found. Exiting." >&2
exit 2
fi
# Create dirs
dest_dir=$(echo $date_ref |cut -c 1-7 |tr '-' '/')
mkdir -p ${output_dir}/$dest_dir
# Create plot data file
rm -f $data_file
python3 <<EOF
import plot
plot.plot_daily_details("${date_ref}")
EOF
cd $output_dir
# Check if the datafile has been created
if [ ! -r $data_file ]; then
echo "Datafile not found. Exiting." >&2
exit 3
fi
if [ ! -s $data_file ]; then
echo "Empty datafile. Exiting."
rm -f $data_file
exit 3
fi
# Plot data
gnuplot <<EOF
set title "${date_ref}"
set autoscale
set xdata time
set timefmt "%H:%M:%S"
set yrange [0:5000]
set y2range [0:90]
set xrange ["05:00:00":"22:00:00"]
set xtics 3600 nomirror rotate by -45
set ytics 500 nomirror
set y2tics 5
set grid xtics ytics
set bmargin 3
set rmargin 5
set pointsize 0.1
set terminal png size 1400, 600
set output "${dest_dir}/pvm-${date_ref}-daily_details.png"
plot "${data_file}" using 2:9 title "Generator power (W)" with lines axis x1y1 lt rgb "red", \
"${data_file}" using 2:10 title "Inverter temperature (°C)" with lines axis x1y2 lt rgb "green"
EOF
# Clean up
rm -f $data_file