-
Notifications
You must be signed in to change notification settings - Fork 3
/
battery-status-graph
executable file
·40 lines (36 loc) · 1.02 KB
/
battery-status-graph
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
#!/bin/sh
# License: GNU Public License v2 or later at your choice.
input=/var/log/hjemmenett-battery-status.log
filename="${1}"
# manufacturer,model_name,technology
type=$(head -2 "$input" | tail -1 | cut -d, -f2-4 | tr , " ")
(
cat <<EOF
set xdata time
set timefmt "%s"
set format x "%Y"
set datafile separator ","
set title 'Battery statistics $type'
set ylabel 'Percent'
set xlabel 'Year'
set grid
EOF
if [ "$filename" ]; then
cat <<EOF
set term png
set output "$filename"
EOF
fi
cat <<EOF
plot "$input" using 1:(100 * \$8 / \$7) \
smooth unique axis x1y1 title "Battery level %" \
with lines linewidth 0.1 linecolor rgb '#080808',"$input" using 1:(100 * \$6 / \$7) \
smooth unique axis x1y1 title "Battery full capacity %" \
with lines linewidth 1 linecolor rgb 'red',"$input" using 1:(100 * \$7 / \$7) \
smooth unique axis x1y1 title "Battery design capacity %" \
with lines linewidth 1 linecolor rgb 'black'
EOF
) | gnuplot -p
if [ "$filename" ] ; then
echo "PNG graph $filename created."
fi