3
I have this battery usage data from my phone that I captured using Tasker:
97 - 1467514184514
tela desligada - 1467514366535
tela ligada - 1467514369196
96 - 1467514414616
95 - 1467514674523
94 - 1467514924621
93 - 1467515154585
92 - 1467515364555
91 - 1467515644567
90 - 1467515904577
89 - 1467516164576
88 - 1467516444576
87 - 1467516724599
86 - 1467516974598
85 - 1467517234639
84 - 1467517524627
83 - 1467517774639
tela desligada - 1467517831625
tela ligada - 1467517844633
82 - 1467518044654
81 - 1467518304726
80 - 1467518564731
79 - 1467518854649
tela desligada - 1467519062759
tela ligada - 1467519065287
78 - 1467519114701
tela desligada - 1467519222448
tela ligada - 1467519224361
tela desligada - 1467519268223
tela ligada - 1467519270241
tela desligada - 1467519313549
tela ligada - 1467519315661
77 - 1467519394673
tela ligada - 1467519525076
77 - 1467519534643
76 - 1467519625736
75 - 1467519874688
74 - 1467520114710
tela desligada - 1467520268384
tela ligada - 1467520277494
73 - 1467520364777
tela desligada - 1467520374973
tela ligada - 1467520375570
tela desligada - 1467520510265
tela ligada - 1467520512333
tela desligada - 1467520535432
tela ligada - 1467520536223
tela desligada - 1467520626069
tela ligada - 1467520628278
72 - 1467520644742
tela ligada - 1467520726202
tela desligada - 1467520728528
72 - 1467520742118
tela ligada - 1467520742157
carregando bateria - 1467520742203
tela desligada - 1467520743675
73 - 1467520841112
tela ligada - 1467520848617
tela desligada - 1467520864967
74 - 1467520931093
75 - 1467521011773
76 - 1467521091225
77 - 1467521171491
78 - 1467521241273
79 - 1467521311313
80 - 1467521381433
81 - 1467521451291
82 - 1467521521127
83 - 1467521591250
84 - 1467521661254
85 - 1467521731324
86 - 1467521801328
87 - 1467521871262
88 - 1467521941243
89 - 1467522021200
90 - 1467522101530
91 - 1467522191145
92 - 1467522291331
93 - 1467522401305
94 - 1467522521292
95 - 1467522661469
96 - 1467522821464
97 - 1467523021208
98 - 1467523261325
99 - 1467523561392
100 - 1467524071444
tela ligada - 1467543507927
tela desligada - 1467543522847
tela ligada - 1467543553598
tela desligada - 1467543555464
desarregando bateria - 1467543570366
tela ligada - 1467543570466
tela desligada - 1467543572805
tela ligada - 1467543573367
tela ligada - 1467543762197
100 - 1467543769538
tela desligada - 1467543799334
tela ligada - 1467543801542
tela desligada - 1467543824793
tela ligada - 1467543834876
99 - 1467543933770
tela ligada - 1467543996645
99 - 1467544003623
tela ligada - 1467544153861
98 - 1467544163912
97 - 1467544323634
tela desligada - 1467544325142
tela ligada - 1467544329638
tela desligada - 1467544386685
tela ligada - 1467544483093
tela desligada - 1467544571038
96 - 1467544609004
tela ligada - 1467544609039
tela ligada - 1467544745366
96 - 1467544748377
95 - 1467544798445
94 - 1467545068409
93 - 1467545308429
92 - 1467545558429
tela ligada - 1467545595320
tela desligada - 1467545597590
92 - 1467545598382
tela ligada - 1467545696894
tela desligada - 1467545757555
tela ligada - 1467545933920
91 - 1467546013522
tela desligada - 1467546113335
tela ligada - 1467546140287
90 - 1467546318244
tela ligada - 1467546377997
90 - 1467546378382
tela desligada - 1467546409534
tela ligada - 1467546451043
89 - 1467546630530
tela desligada - 1467546663460
tela ligada - 1467546814986
tela desligada - 1467546825432
88 - 1467547523083
tela ligada - 1467550033900
tela desligada - 1467550061241
tela ligada - 1467550063275
tela ligada - 1467550132143
88 - 1467550133363
87 - 1467550233622
86 - 1467550503471
85 - 1467550843458
tela desligada - 1467550908878
tela ligada - 1467550927895
84 - 1467551207421
83 - 1467551557383
tela desligada - 1467551790452
tela ligada - 1467552405020
tela desligada - 1467552425594
tela ligada - 1467552865867
82 - 1467552875404
tela desligada - 1467552885894
tela desligada - 1467552888918
82 - 1467553007104
tela ligada - 1467554234966
81 - 1467554244423
tela ligada - 1467554326023
81 - 1467554344363
tela desligada - 1467554355202
80 - 1467554451089
tela ligada - 1467554463059
tela desligada - 1467554507173
tela desligada - 1467554510531
80 - 1467554512114
tela ligada - 1467554535934
79 - 1467554635456
tela ligada - 1467554689882
79 - 1467554695461
tela desligada - 1467554766183
tela ligada - 1467554768110
tela desligada - 1467554778616
tela ligada - 1467554803911
78 - 1467554853440
77 - 1467555083503
76 - 1467555383387
75 - 1467555623525
74 - 1467555873422
73 - 1467556113534
tela ligada - 1467556152852
73 - 1467556153400
tela ligada - 1467556184928
73 - 1467556193424
72 - 1467556323438
71 - 1467556583452
70 - 1467556823513
69 - 1467557103509
tela desligada - 1467557191455
tela ligada - 1467557490051
tela desligada - 1467557494232
tela ligada - 1467557858175
tela ligada - 1467557879460
tela desligada - 1467557879482
tela ligada - 1467557908318
68 - 1467557914380
tela desligada - 1467557925409
tela ligada - 1467558492101
tela desligada - 1467558510096
tela ligada - 1467558887050
tela desligada - 1467558921283
tela ligada - 1467559261338
67 - 1467559270523
66 - 1467559440485
My goal is to find out how long it takes to change the battery status with the screen on, off, and also whether or not you’re charging your phone. In python I made this script to get the data from the file lol.txt:
import glob, time, pprint
a = glob.glob('*.txt')[:1]
def postar_bonito(kk):
l = []
x = kk.splitlines()
for k in x:
m, o = k.split(' - ')
o = time.strftime('%d/%m/%Y - %H:%M:%S', time.localtime(int(o)/1000))
if m[0].isdigit(): m += '%'
l.append('%s - %s' % (o, m))
return '\n'.join(l)
def estava_ligado(x):
m = f.index('tela desligada')
mm = f.index('tela ligada')
return mm > m
def remover_repetidos(s):
last = 'lolcopter'
k = []
for i, e in enumerate(s):
lolcopter = e.split(' - ')[0]
if lolcopter != last:
k.append(lolcopter)
last = lolcopter
return k
def estava_carregando(j):
lol = remover_repetidos([m for m in j.splitlines() if m[0].isdigit()])
return int(lol[0]) < int(lol[1])
def prettytime(x):
return time.strftime('%d/%m/%Y - %H:%M:%S', time.localtime(int(x) / 1000))
def prettytime2(x):
o, k = divmod(x, 60)
return '%02d:%02d' % (o, k)
def process(x, y, z):
return [z, prettytime(x), prettytime(y), prettytime2((int(y) - int(x)) / 1000)]
for i in a:
f = file(i, 'r').read()
carregando_tela_ligada = []
carregando_tela_desligada = []
descarregando_tela_ligada = []
descarregando_tela_desligada = []
carregando = estava_carregando(f)
tela = estava_ligado(f)
last = None
last_percent = None
for h in f.splitlines():
g, r = h.split(' - ')
if g[0].isdigit():
if g != last_percent:
if last == None:
last = r
if carregando:
if tela:
carregando_tela_ligada.append(process(last, r, last_percent))
else:
carregando_tela_desligada.append(process(last, r, last_percent))
else:
if tela:
descarregando_tela_ligada.append(process(last, r, last_percent))
else:
descarregando_tela_desligada.append(process(last, r, last_percent))
last = r
last_percent = g
if g == "tela desligada":
tela = False
if g == "tela ligada":
tela = True
if g == "descarregando bateria":
carregando = False
if g == "carregando bateria":
carregando = True
print "carregando_tela_ligada ="
pprint.pprint(carregando_tela_ligada)
print "carregando_tela_desligada ="
pprint.pprint(carregando_tela_desligada)
print "descarregando_tela_ligada ="
pprint.pprint(descarregando_tela_ligada)
print "descarregando_tela_desligada ="
pprint.pprint(descarregando_tela_desligada)
The output is this:
carregando_tela_ligada =
[['100', '03/07/2016 - 02:34:31', '03/07/2016 - 08:05:33', '331:02'],
['99', '03/07/2016 - 08:05:33', '03/07/2016 - 08:09:23', '03:50'],
['98', '03/07/2016 - 08:09:23', '03/07/2016 - 08:12:03', '02:39'],
['96', '03/07/2016 - 08:16:49', '03/07/2016 - 08:19:58', '03:09'],
['95', '03/07/2016 - 08:19:58', '03/07/2016 - 08:24:28', '04:29'],
['94', '03/07/2016 - 08:24:28', '03/07/2016 - 08:28:28', '04:00'],
['93', '03/07/2016 - 08:28:28', '03/07/2016 - 08:32:38', '04:10'],
['92', '03/07/2016 - 08:32:38', '03/07/2016 - 08:40:13', '07:35'],
['91', '03/07/2016 - 08:40:13', '03/07/2016 - 08:45:18', '05:04'],
['90', '03/07/2016 - 08:45:18', '03/07/2016 - 08:50:30', '05:12'],
['88', '03/07/2016 - 09:05:23', '03/07/2016 - 09:50:33', '45:10'],
['87', '03/07/2016 - 09:50:33', '03/07/2016 - 09:55:03', '04:29'],
['86', '03/07/2016 - 09:55:03', '03/07/2016 - 10:00:43', '05:39'],
['85', '03/07/2016 - 10:00:43', '03/07/2016 - 10:06:47', '06:03'],
['84', '03/07/2016 - 10:06:47', '03/07/2016 - 10:12:37', '05:49'],
['83', '03/07/2016 - 10:12:37', '03/07/2016 - 10:34:35', '21:58'],
['82', '03/07/2016 - 10:34:35', '03/07/2016 - 10:57:24', '22:49'],
['80', '03/07/2016 - 11:00:51', '03/07/2016 - 11:03:55', '03:04'],
['79', '03/07/2016 - 11:03:55', '03/07/2016 - 11:07:33', '03:37'],
['78', '03/07/2016 - 11:07:33', '03/07/2016 - 11:11:23', '03:50'],
['77', '03/07/2016 - 11:11:23', '03/07/2016 - 11:16:23', '04:59'],
['76', '03/07/2016 - 11:16:23', '03/07/2016 - 11:20:23', '04:00'],
['75', '03/07/2016 - 11:20:23', '03/07/2016 - 11:24:33', '04:09'],
['74', '03/07/2016 - 11:24:33', '03/07/2016 - 11:28:33', '04:00'],
['73', '03/07/2016 - 11:28:33', '03/07/2016 - 11:32:03', '03:29'],
['72', '03/07/2016 - 11:32:03', '03/07/2016 - 11:36:23', '04:20'],
['71', '03/07/2016 - 11:36:23', '03/07/2016 - 11:40:23', '04:00'],
['70', '03/07/2016 - 11:40:23', '03/07/2016 - 11:45:03', '04:39'],
['69', '03/07/2016 - 11:45:03', '03/07/2016 - 11:58:34', '13:30'],
['68', '03/07/2016 - 11:58:34', '03/07/2016 - 12:21:10', '22:36'],
['67', '03/07/2016 - 12:21:10', '03/07/2016 - 12:24:00', '02:49']]
carregando_tela_desligada =
[['72', '03/07/2016 - 01:37:24', '03/07/2016 - 01:40:41', '03:16'],
['73', '03/07/2016 - 01:40:41', '03/07/2016 - 01:42:11', '01:29'],
['74', '03/07/2016 - 01:42:11', '03/07/2016 - 01:43:31', '01:20'],
['75', '03/07/2016 - 01:43:31', '03/07/2016 - 01:44:51', '01:19'],
['76', '03/07/2016 - 01:44:51', '03/07/2016 - 01:46:11', '01:20'],
['77', '03/07/2016 - 01:46:11', '03/07/2016 - 01:47:21', '01:09'],
['78', '03/07/2016 - 01:47:21', '03/07/2016 - 01:48:31', '01:10'],
['79', '03/07/2016 - 01:48:31', '03/07/2016 - 01:49:41', '01:10'],
['80', '03/07/2016 - 01:49:41', '03/07/2016 - 01:50:51', '01:09'],
['81', '03/07/2016 - 01:50:51', '03/07/2016 - 01:52:01', '01:09'],
['82', '03/07/2016 - 01:52:01', '03/07/2016 - 01:53:11', '01:10'],
['83', '03/07/2016 - 01:53:11', '03/07/2016 - 01:54:21', '01:10'],
['84', '03/07/2016 - 01:54:21', '03/07/2016 - 01:55:31', '01:10'],
['85', '03/07/2016 - 01:55:31', '03/07/2016 - 01:56:41', '01:10'],
['86', '03/07/2016 - 01:56:41', '03/07/2016 - 01:57:51', '01:09'],
['87', '03/07/2016 - 01:57:51', '03/07/2016 - 01:59:01', '01:09'],
['88', '03/07/2016 - 01:59:01', '03/07/2016 - 02:00:21', '01:19'],
['89', '03/07/2016 - 02:00:21', '03/07/2016 - 02:01:41', '01:20'],
['90', '03/07/2016 - 02:01:41', '03/07/2016 - 02:03:11', '01:29'],
['91', '03/07/2016 - 02:03:11', '03/07/2016 - 02:04:51', '01:40'],
['92', '03/07/2016 - 02:04:51', '03/07/2016 - 02:06:41', '01:49'],
['93', '03/07/2016 - 02:06:41', '03/07/2016 - 02:08:41', '01:59'],
['94', '03/07/2016 - 02:08:41', '03/07/2016 - 02:11:01', '02:20'],
['95', '03/07/2016 - 02:11:01', '03/07/2016 - 02:13:41', '02:39'],
['96', '03/07/2016 - 02:13:41', '03/07/2016 - 02:17:01', '03:19'],
['97', '03/07/2016 - 02:17:01', '03/07/2016 - 02:21:01', '04:00'],
['98', '03/07/2016 - 02:21:01', '03/07/2016 - 02:26:01', '05:00'],
['99', '03/07/2016 - 02:26:01', '03/07/2016 - 02:34:31', '08:30'],
['97', '03/07/2016 - 08:12:03', '03/07/2016 - 08:16:49', '04:45'],
['89', '03/07/2016 - 08:50:30', '03/07/2016 - 09:05:23', '14:52'],
['81', '03/07/2016 - 10:57:24', '03/07/2016 - 11:00:51', '03:26']]
descarregando_tela_ligada =
[[None, '02/07/2016 - 23:49:44', '02/07/2016 - 23:49:44', '00:00'],
['97', '02/07/2016 - 23:49:44', '02/07/2016 - 23:53:34', '03:50'],
['96', '02/07/2016 - 23:53:34', '02/07/2016 - 23:57:54', '04:19'],
['95', '02/07/2016 - 23:57:54', '03/07/2016 - 00:02:04', '04:10'],
['94', '03/07/2016 - 00:02:04', '03/07/2016 - 00:05:54', '03:49'],
['93', '03/07/2016 - 00:05:54', '03/07/2016 - 00:09:24', '03:29'],
['92', '03/07/2016 - 00:09:24', '03/07/2016 - 00:14:04', '04:40'],
['91', '03/07/2016 - 00:14:04', '03/07/2016 - 00:18:24', '04:20'],
['90', '03/07/2016 - 00:18:24', '03/07/2016 - 00:22:44', '04:19'],
['89', '03/07/2016 - 00:22:44', '03/07/2016 - 00:27:24', '04:40'],
['88', '03/07/2016 - 00:27:24', '03/07/2016 - 00:32:04', '04:40'],
['87', '03/07/2016 - 00:32:04', '03/07/2016 - 00:36:14', '04:09'],
['86', '03/07/2016 - 00:36:14', '03/07/2016 - 00:40:34', '04:20'],
['85', '03/07/2016 - 00:40:34', '03/07/2016 - 00:45:24', '04:49'],
['84', '03/07/2016 - 00:45:24', '03/07/2016 - 00:49:34', '04:10'],
['83', '03/07/2016 - 00:49:34', '03/07/2016 - 00:54:04', '04:30'],
['82', '03/07/2016 - 00:54:04', '03/07/2016 - 00:58:24', '04:20'],
['81', '03/07/2016 - 00:58:24', '03/07/2016 - 01:02:44', '04:20'],
['80', '03/07/2016 - 01:02:44', '03/07/2016 - 01:07:34', '04:49'],
['79', '03/07/2016 - 01:07:34', '03/07/2016 - 01:11:54', '04:20'],
['78', '03/07/2016 - 01:11:54', '03/07/2016 - 01:16:34', '04:39'],
['77', '03/07/2016 - 01:16:34', '03/07/2016 - 01:20:25', '03:51'],
['76', '03/07/2016 - 01:20:25', '03/07/2016 - 01:24:34', '04:08'],
['75', '03/07/2016 - 01:24:34', '03/07/2016 - 01:28:34', '04:00'],
['74', '03/07/2016 - 01:28:34', '03/07/2016 - 01:32:44', '04:10'],
['73', '03/07/2016 - 01:32:44', '03/07/2016 - 01:37:24', '04:39']]
descarregando_tela_desligada =
[]
But the data is incorrect. On charging with the screen on the power is decreasing and on charging with the screen off is ok but then comes an 89 and an 81 from the beyond!
Where’s the logic error in my script? Someone suggests a better way to do what I want?