Adjust fake command handler to prevent date cross over.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-22 21:35:36 -04:00
parent c13914d6e2
commit c4147af34d
1 changed files with 12 additions and 12 deletions

View File

@ -81,15 +81,15 @@ class Command(BaseCommand):
color=color color=color
).save() ).save()
start = date last_end = date
while start < date + timedelta(days=1): while last_end < date + timedelta(days=1):
method = choice(Feeding._meta.get_field('method').choices)[0] method = choice(Feeding._meta.get_field('method').choices)[0]
if method is 'bottle': if method is 'bottle':
amount = Decimal('%d.%d' % (randint(0, 6), randint(0, 9))) amount = Decimal('%d.%d' % (randint(0, 6), randint(0, 9)))
else: else:
amount = None amount = None
start += timedelta(minutes=randint(0, 60 * 2)) start = last_end + timedelta(minutes=randint(0, 60 * 2))
end = start + timedelta(minutes=randint(5, 20)) end = start + timedelta(minutes=randint(5, 20))
if end > now: if end > now:
break break
@ -102,26 +102,26 @@ class Command(BaseCommand):
method=method, method=method,
amount=amount amount=amount
).save() ).save()
start = end last_end = end
start = date last_end = date
while start < date + timedelta(days=1): while last_end < date + timedelta(days=1):
start += timedelta(minutes=randint(0, 60 * 2)) start = last_end + timedelta(minutes=randint(0, 60 * 2))
end = start + timedelta(minutes=randint(10, 60 * 3)) end = start + timedelta(minutes=randint(10, 60 * 3))
if end > now: if end > now:
break break
Sleep.objects.create(child=child, start=start, end=end).save() Sleep.objects.create(child=child, start=start, end=end).save()
start = end last_end = end
start = date last_end = date
while start < date + timedelta(days=1): while last_end < date + timedelta(days=1):
if choice([True, False]): if choice([True, False]):
milestone = self.faker.sentence() milestone = self.faker.sentence()
else: else:
milestone = '' milestone = ''
start += timedelta(minutes=randint(0, 60 * 2)) start = last_end + timedelta(minutes=randint(0, 60 * 2))
end = start + timedelta(minutes=randint(1, 10)) end = start + timedelta(minutes=randint(1, 10))
if end > now: if end > now:
break break
@ -132,4 +132,4 @@ class Command(BaseCommand):
end=end, end=end,
milestone=milestone milestone=milestone
).save() ).save()
start = end last_end = end