formating

This commit is contained in:
Valentin Boettcher 2018-02-18 22:37:29 +01:00
parent 40f2d67b1e
commit f837728261

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3
import sys
import datetime
import time
import argparse
import logParser
import dateparser
@ -13,10 +13,12 @@ argparser.add_argument('--list', '-l', help='List all Heaters in the Database.',
argparser.add_argument('--heatAmmount', help='Sum of the actuator value times a time slice.', nargs=1, metavar='HEATER')
argparser.add_argument('--allHeatAmmount', help='Get the heat ammount from all known heaters.', action='store_true')
argparser.add_argument('--timeSpan', help='The time span for the heatAmmount calculation. Either t1/t2 or both may be supplied.', nargs=1, metavar='t1..t2 | t1 | ..t2')
argparser.add_argument('--verbose', '-v', help='Output more information about the query.', action='store_true')
# Parse args. Set name to default.
args = argparser.parse_args()
mintime, maxtime = 0, inf
mintime, maxtime = 0, time.time()
if args.timeSpan:
times = args.timeSpan[0].split('..')
@ -25,16 +27,14 @@ if args.timeSpan:
print('Invalid Timespan!')
exit(1)
elif len(times) == 2:
try:
times[0] = dateparser.parse(times[0]).timestamp()
times[1] = dateparser.parse(times[1]).timestamp()
except:
pass
if times[0] == '':
maxtime = int(times[1])
else:
mintime, maxtime = times
else:
mintime = int(times[0])
@ -44,6 +44,16 @@ if not args.parse is None:
elif not args.list is False:
print('\n'.join(logParser.getHeaterList()))
elif not args.heatAmmount is None:
print(logParser.getHeaterSum(args.heatAmmount[0], mintime, maxtime))
heat = args.heatAmmount[0], logParser.getHeaterSum(args.heatAmmount[0], mintime, maxtime)
if args.verbose:
print(', '.join([heat[0], str(heat[1]), str(int(mintime)), str(int(maxtime))]))
else:
print(heat[1])
elif not args.allHeatAmmount is None:
print(logParser.getAllHeaterSums(mintime, maxtime))
allheaters = logParser.getAllHeaterSums(mintime, maxtime)
for heater in allheaters:
if args.verbose:
print(', '.join([heater, str(allheaters[heater]), str(int(mintime)), str(int(maxtime))]))
else:
print(', '.join([heater, str(allheaters[heater])]))