~charles/dotfiles

ref: 9bd530e81b6474e5da246ec3e5a3f89d1707ede1 dotfiles/overlay/bin/batstat -rwxr-xr-x 2.4 KiB
9bd530e8 — Charles Daniels Merge branch 'master' of git.sr.ht:~charles/dotfiles 3 years ago
                                                                                
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
#!/usr/bin/env python3

import datetime
import matplotlib.pyplot as plt
import numpy as np
import dateutil
import dateutil.parser

timestamps       = []
last_full_data   = []
remaining_data   = []
discharging_data = []
speed_data       = []
rate_data        = []
coretemp_data    = []
load_data        = []
degrade_data     = []

with open("/home/cad/Log/batrecord.log") as f:
    for line in f:
        line = line.strip().split(',')
        timestamp = line[0]
        rate = line[1]
        last_full = line[2]
        remaining = line[3]
        discharging = line[4]
        speed = line[5]
        coretemp = 0
        numcpu = 1
        loadavg = 0

        if len(line) > 6:
            coretemp = line[6]

        if len(line) > 7:
            loadavg = float(line[7])
            numcpu = float(line[8])

        timestamps.append(dateutil.parser.parse(timestamp))
        rate_data.append(float(rate))
        last_full_data.append(float(last_full))
        remaining_data.append(float(remaining))
        discharging_data.append(float(discharging))
        speed_data.append(float(speed) * 0.025)
        coretemp_data.append(float(coretemp))
        load_data.append((loadavg / numcpu) * 100)

        if len(timestamps) < 5:
            degrade_data.append(0)
            continue

        lost_capacity = last_full_data[-1] - last_full_data[0]
        elapsed = timestamps[-1] - timestamps[0]
        rate = (lost_capacity * 60 * 60) / (elapsed.total_seconds())
        rate_why = rate * 8765.8128
        print("lost capacity since {}: {:0.2f} Wh over {} at {:0.4f} w = {:0.2f} wh / yr"
                .format(timestamps[0], lost_capacity, elapsed, rate, rate_why))
        degrade_data.append(-1*rate_why)



plt.plot(timestamps, remaining_data, label="remaining (Wh)", marker='o', linestyle=':')
plt.plot(timestamps, rate_data, label="discharge rate (W)", marker='x', linestyle='-.')
plt.plot(timestamps, last_full_data, label="last full (Wh)", marker='o', linestyle='--')
plt.plot(timestamps, coretemp_data, label="core temperature (C)", marker='x', linestyle='--')
plt.plot(timestamps, speed_data, label="clock speed (MHz * 0.025)", marker='o')
plt.plot(timestamps, load_data, label="load average (of 100)", marker='x', linestyle=':')
plt.plot(timestamps, degrade_data, label="degrade rate (Wh / y)", marker='x', linestyle='--')

plt.legend(loc = "upper left")

plt.xticks(rotation=20)

plt.show()