hakkoso/utils.py

18 lines
429 B
Python

from datetime import timedelta
def consumption_diff(before, after):
out = {}
for key in after:
out[key] = after.get(key, 0) - before.get(key, 0)
return out
def consumption_to_string(dic):
out = ''
for key in dic:
out += '{0:s}:\t{1:.2f}Wh\n'.format(key, dic[key])
out += 'Total:\t{0:.2f}Wh'.format(sum(dic.values()))
return out
def stohms(s):
return str(timedelta(seconds = s))