bugtracker icon indicating copy to clipboard operation
bugtracker copied to clipboard

Provide proper interface for upower battery data

Open MerlijnWajer opened this issue 5 years ago • 7 comments

Upower logs lots of valueable battery data. We should make that insightful to everyone.

GNOME Power Manager can do it, but it's slow, and doesn't generate particularly nice graphs: https://wizzup.org/leste-droid4-gnome-power-manager.png

But it should at least help with reading the upower database format.

MerlijnWajer avatar Jun 23 '20 10:06 MerlijnWajer

The values are newline separated, and then tab separated per value on a line:

$ cat plot.py
import sys
import datetime

import matplotlib
import matplotlib.pyplot as plt


if __name__ == '__main__':
    f=open(sys.argv[1])
    ptype=sys.argv[2]

    datapts=f.read().split('\n')

    times = []
    values = []

    for datapt in datapts:
        vals = datapt.split('\t')
        if len(vals) != 3:
            continue
        time, val, state = vals
        time = int(time)
        dt = datetime.datetime.fromtimestamp(time)
        val = float(val)

        # Can decide to only plot state == 'charging' or state == 'discharging'
        times.append(dt) #times.append(time)
        values.append(val)

        #print(dt, val, state)

    plt.xlabel('time')
    if ptype == 'capacity':
        plt.ylabel('capacity')
    if ptype == 'rate':
        plt.ylabel('discharging rate')
    if ptype == 'time-to':
        plt.ylabel('time to full/empty')
    plt.plot(times, values)
    plt.show()

MerlijnWajer avatar Jun 23 '20 11:06 MerlijnWajer

image

Files are in /var/lib/upower

MerlijnWajer avatar Jun 23 '20 11:06 MerlijnWajer

Maybe we can use this frontend (not the collecting backend, of course) http://maemo.org/downloads/product/Maemo5/battery-eye/

MerlijnWajer avatar Jun 23 '20 11:06 MerlijnWajer

We might also want to change the max data age of upower, in src/up-history.c:

#define UP_HISTORY_FILE_HEADER      "PackageKit Profile"
#define UP_HISTORY_SAVE_INTERVAL    (10*60)     /* seconds */
#define UP_HISTORY_DEFAULT_MAX_DATA_AGE (7*24*60*60)    /* seconds */

MerlijnWajer avatar Jun 23 '20 11:06 MerlijnWajer

/me wonders why upower doesn't provide a way to adjust those (max data age, etc.) in a config file instead.

sicelo avatar Jun 23 '20 19:06 sicelo

For the record this is how to actually invoke the script for discharge rates:

python plot.py /var/lib/upower/history-rate-7.dat rate

MerlijnWajer avatar Dec 11 '21 10:12 MerlijnWajer

If you limit by this for datapt in datapts[-200:]: then you have a much recent lecture and clear plot without deal with delta times etc, otherwise just skip those by comparing dt = datetime.datetime.fromtimestamp(time) to desired value. Line val = float(val) no longer works (at least for me), so just replace the , by val = float(val.replace(",", ".")).

erm3nda avatar Mar 22 '23 11:03 erm3nda