2023-02-21 16:34:40 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2023-02-21 14:00:07 +01:00
|
|
|
def consumption_diff(before, after):
|
|
|
|
out = {}
|
|
|
|
for key in after:
|
2023-02-21 16:34:40 +01:00
|
|
|
out[key] = after.get(key, 0) - before.get(key, 0)
|
2023-02-21 14:00:07 +01:00
|
|
|
return out
|
|
|
|
|
|
|
|
def consumption_to_string(dic):
|
|
|
|
out = ''
|
|
|
|
for key in dic:
|
2023-02-21 19:23:12 +01:00
|
|
|
out += '{0:s}:\t{1:.2f}Wh\n'.format(key, dic[key])
|
|
|
|
out += 'Total:\t{0:.2f}Wh'.format(sum(dic.values()))
|
2023-02-21 14:00:07 +01:00
|
|
|
return out
|
2023-02-21 16:34:40 +01:00
|
|
|
|
|
|
|
def stohms(s):
|
|
|
|
return str(timedelta(seconds = s))
|