Skip to content

Instantly share code, notes, and snippets.

@citostyle
Last active March 1, 2016 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save citostyle/23113eb38618ff0a7317 to your computer and use it in GitHub Desktop.
Save citostyle/23113eb38618ff0a7317 to your computer and use it in GitHub Desktop.
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