-
Notifications
You must be signed in to change notification settings - Fork 4
/
process-apm.py
49 lines (33 loc) · 955 Bytes
/
process-apm.py
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
#! /usr/bin/python
import sys
import string
def main():
if not sys.argv[0]:
path = '/tmp/n30.log'
else:
path = sys.argv[1]
f = open(path, 'r')
t0 = 0
last_charge = -1
while 1:
l = f.readline()
if not l:
break
parts = l.split()
if len(parts) != 15 or parts[12][-1:] != '%':
continue
h, m, s = parts[3].split(':')
t = (string.atoi(h) * 60 + string.atoi(m)) * 60 + string.atoi(s)
if not t0:
t0 = t
if t < t0:
sys.stderr.write("%d %d %d\n" % (t, t0, hours * 3600))
t0 = t - hours * 3600
hours = (t - t0) / 3600.0
charge = string.atoi(parts[12][:-1])
if charge == -1 or last_charge == charge:
continue
last_charge = charge
print "%.2f %2d" % (hours, charge)
print "%.2f %2d" % (hours, charge)
main()