-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.py
142 lines (120 loc) · 4.21 KB
/
report.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from datetime import datetime as dtime
import os, time, random
# normal charge lasts about 1h 100%
# So it would be fair to report every 10mins = every 10%
# but it heats up quickly and we need data before it heats
# therefore report every 3mins
# time passed shown in report is total time it took
# to charge to 100%
# timer is reset if charger was disconnected
# as it will be inacurrate data
# current date/time
d = dtime.now()
day = d.strftime("%d%m")
tim = d.strftime("%I:%M:%S %p %d/%m/%Y")
# ask for current code_name
c_n = input("What is code_name you are testing? : ")
if not c_n:
c_n = f"beta_{day}_{random.randint(0, 100)}"
print("\n[WARN] You didn't give code_name one of the existing logs may be overwritten")
# run shell commands
def cat(cmd, remove_new_lines=True):
return os.popen(cmd).read().replace('\n','') if remove_new_lines else os.popen(cmd).read()
# New File
filename = f"vant_{c_n}.txt"
f = open(f"/sdcard/{filename}", "a")
print(f"\n[INFO] Created {filename}")
flavor = cat("getprop ro.build.flavor")
host = cat("getprop ro.build.host")
id = cat("getprop ro.build.id")
code = cat("getprop ro.build.product")
start = f"""
########### BESS VANT ############
##### {tim} #####
######### Charging Report ########
Device Code : {code}
Rom ID : {id}
Rom Host : {host}
Rom Flavor : {flavor}
Test Name : {c_n} """
print(start, file=f)
f.flush()
def log(t, n):
timen = timeinletters(int(t))
temp = int(cat("cat /sys/devices/virtual/thermal/thermal_zone79/temp"))/1000
level = cat("cat /sys/class/power_supply/battery/capacity")
dmesg = cat("su -c 'dmesg | tail -25'", remove_new_lines=False) # last 25 line of dmesg
# calc watt by Average of volts*amp three times
data = []
for i in range(3):
v = round(int(os.popen("cat /sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-00/c440000.qcom,spmi:qcom,pm6150@0:qcom,qpnp-smb5/power_supply/battery/voltage_now").read().replace("\n",''))/1000000, 2)
a = round(int(os.popen("cat /sys/devices/platform/soc/c440000.qcom,spmi/spmi-0/spmi0-00/c440000.qcom,spmi:qcom,pm6150@0:qcom,qpnp-smb5/power_supply/battery/current_now").read().replace("\n",'').replace("-",''))/1000, 2)
data.append(round((v*a)/1000,2))
# calc avg
watts = round(sum(data)/len(data),2)
report = f"""\n\n
####################################################################
########################## Report {n} ################################
Time Passed : {timen}
Charge level: {level}%
Temp : {temp}°C
Watts : {watts}w
########################### DMESG ################################
{dmesg}
####################################################################
####################################################################
"""
printf(report)
if int(level) >= 100:
printf(f"\n#### CHARGING COMPLETE IN {timen} ####")
exit()
# check if charging
def is_connected():
a = int(cat("cat /sys/class/power_supply/usb/online"))
return bool(a)
# duplicate logging to terminal/text file
def printf(s):
print(s)
print(s, file=f)
f.flush()
# homan readable format
def timeinletters(unixt):
h = 86400
m = 3540
s = 59
t = int(time.time())
diff = abs(t - unixt)
if diff < s: return str(diff) + "s"
elif diff < m: return str(round(diff/60)) + "m"
elif diff < h: return str(int(diff/3600)) + "h"
else: return str(int(diff/86400)) + "days"
# constants
m = 60*3 # 3mins
c = 0 # time passed
n = 0
t = time.time()
# Real Code
while 1:
# if 10mins passed
if int(time.time()) >= c + m:
if not is_connected():
while 1:
if not is_connected():
printf("\n### Please Connect Charger to start logging ###")
time.sleep(5)
continue
else:
printf("\n### Usb Connected Charging Timer reset ###")
t = time.time() # reset timer
break
c = int(time.time())
log(t, n)
n+=1
continue
else:
sleep = (c+m) - int(time.time())
print(f"\n[INFO] sleeping for {sleep}s")
time.sleep(sleep)
continue
# this is part of ln8000_beta_reporting project on github.com/justxd22
# credits goes to the boss bantom for porting ln8000