comparison graph.py @ 14:aa18210c2703

Improve start/end/days handling - Allow the user to specify nothing to graph todays data. - Fix bug when only specifying days. - When specifying days finish at the end of today.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 11 Jan 2018 08:43:40 +1030
parents 3f22fa1f32d5
children c04c75360a3b
comparison
equal deleted inserted replaced
13:3f22fa1f32d5 14:aa18210c2703
64 args = parser.parse_args() 64 args = parser.parse_args()
65 65
66 if args.days is not None and args.days < 0: 66 if args.days is not None and args.days < 0:
67 parser.error('days must be non-negative') 67 parser.error('days must be non-negative')
68 68
69 # Can specify..
70 # Start and end
71 # Start and days or Start
72 # End and days or End
73 # Nothing
74 # Want to end up with a start & end
75 selector = [args.start is not None, args.end is not None, args.days is not None] 69 selector = [args.start is not None, args.end is not None, args.days is not None]
76 if selector == [True, True, False]: 70 if selector == [True, True, False]: # Start and end
77 pass 71 pass
78 elif selector == [True, False, True] or selector == [True, False, False]: 72 elif selector == [True, False, True] or selector == [True, False, False]: # Start and days or start
79 if args.days == None: 73 if args.days == None:
80 args.days = 1 74 args.days = 1
81 args.end = args.start + datetime.timedelta(days = args.days) 75 args.end = args.start + datetime.timedelta(days = args.days)
82 elif selector == [False, True, True] or selector == [False, True, False]: 76 elif selector == [False, True, True] or selector == [False, True, False]: # End and days or end
83 if args.days == None: 77 if args.days == None:
84 args.days = 1 78 args.days = 1
85 args.start = args.end - datetime.timedelta(days = args.days) 79 args.start = args.end - datetime.timedelta(days = args.days)
86 elif selector == [False, False, True]: 80 elif selector == [False, False, True]: # Days
87 end = datetime.date.today() 81 args.end = datetime.date.today() + datetime.timedelta(days = 1)
88 end = datetime.datetime(start.year, start.month, start.day) 82 args.end = datetime.datetime(args.end.year, args.end.month, args.end.day)
89 args.start = args.end - datetime.timedelta(days = args.days) 83 args.start = args.end - datetime.timedelta(days = args.days)
84 elif selector == [False, False, False]: # Nothing
85 args.start = datetime.date.today()
86 args.start = datetime.datetime(args.start.year, args.start.month, args.start.day)
87 args.end = args.start + datetime.timedelta(days = 1)
90 else: 88 else:
91 parser.error('can\'t specify days, start and end simultaneously') 89 parser.error('can\'t specify days, start and end simultaneously')
92 90
93 if args.start >= args.end: 91 if args.start >= args.end:
94 parser.error('Start must be before end') 92 parser.error('Start must be before end')