hakkoso/utils.py

18 lines
427 B
Python
Raw Normal View History

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}W\n'.format(key, dic[key])
out += 'Total:\t{0:.2f}W'.format(sum(dic.values()))
return out
def stohms(s):
return str(timedelta(seconds = s))