Last active
March 1, 2016 22:01
-
-
Save citostyle/23113eb38618ff0a7317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
def main(argv): | |
script, filename = argv | |
data = get_voltage_current(filename) | |
sum = 0 | |
for item in data: | |
if item['current'] > 0: | |
sum = sum + (item['voltage'] * item['current']) | |
average_power_dissipation = sum / len(data) | |
print format(average_power_dissipation, 'f') | |
def get_voltage_current(filename): | |
f = open(filename, 'r') | |
data = [] | |
voltage = "" | |
current = "" | |
while True: | |
item = f.readline() | |
if not item: break | |
#POWER_SUPPLY_VOLTAGE_NOW=3846129 | |
keyValue = item.split('=') | |
if len(keyValue) == 1: continue #next record | |
key, value = keyValue | |
if key == "POWER_SUPPLY_VOLTAGE_NOW": | |
voltage = float(value) | |
if key == "POWER_SUPPLY_CURRENT_NOW": | |
current = float(value) | |
if voltage != "" and current != "": | |
data.append({'voltage' : voltage, 'current' : current}) | |
voltage = "" | |
current = "" | |
f.close | |
return data | |
if __name__ =='__main__': | |
main(argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment