Debian Codegraph @

src/battery-stats-graph-gnuplot

raw
1 #!/bin/sh
2 # License: GNU Public License v2 or later at your choice.
3
4 input=/var/log/battery-status.csv
5 filename="${1}"
6
7 # manufacturer,model_name,technology
8 type=$(head -2 "$input" | tail -1 | cut -d, -f2-4 | tr , " ")
9
10 (
11 cat <<EOF
12 set xdata time
13 set timefmt "%s"
14 set format x "%Y"
15 set datafile separator ","
16 set title 'Battery statistics $type'
17 set ylabel 'Percent'
18 set xlabel 'Year'
19 set grid
20 EOF
21 if [ "$filename" ]; then
22 cat <<EOF
23 set term png
24 set output "$filename"
25 EOF
26 fi
27 cat <<EOF
28 plot "$input" using 1:(100 * \$8 / \$7) \
29 smooth unique axis x1y1 title "Battery level %" \
30 with lines linewidth 0.1 linecolor rgb '#080808',"$input" using 1:(100 * \$6 / \$7) \
31 smooth unique axis x1y1 title "Battery full capacity %" \
32 with lines linewidth 1 linecolor rgb 'red',"$input" using 1:(100 * \$7 / \$7) \
33 smooth unique axis x1y1 title "Battery design capacity %" \
34 with lines linewidth 1 linecolor rgb 'black'
35 EOF
36 ) | gnuplot -p
37
38 if [ "$filename" ] ; then
39 echo "PNG graph $filename created."
40 fi