hakkoso/utils.py

13 lines
340 B
Python

def consumption_diff(before, after):
out = {}
for key in after:
out[key] = before.get(key, 0) - after.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