Changed output format for bookedslots
This commit is contained in:
parent
ceee052a90
commit
cb1f9dfb88
@ -37,6 +37,19 @@ def checkDayNumber(days):
|
|||||||
days = int(days)
|
days = int(days)
|
||||||
return days
|
return days
|
||||||
|
|
||||||
|
def getMigCount(day, slot):
|
||||||
|
return Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(day), booked_time=slot).count()
|
||||||
|
|
||||||
|
def buildDictFromTimeslot(slot):
|
||||||
|
slotDict = {}
|
||||||
|
slotDict["timeslot"] = slot
|
||||||
|
slotDict["yesterday"] = getMigCount(-1, slot)
|
||||||
|
slotDict["today"] = getMigCount(0, slot)
|
||||||
|
slotDict["tomorrow"] = getMigCount(1, slot)
|
||||||
|
slotDict["2days"] = getMigCount(2, slot)
|
||||||
|
slotDict["3days"] = getMigCount(3, slot)
|
||||||
|
return slotDict
|
||||||
|
|
||||||
def getAllMigrations(limit):
|
def getAllMigrations(limit):
|
||||||
return Migration.objects.all()[:limit]
|
return Migration.objects.all()[:limit]
|
||||||
|
|
||||||
@ -171,31 +184,18 @@ class MigrationListAll(APIView):
|
|||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
class MigrationTimeslotDetails(APIView):
|
class MigrationTimeslotDetails(APIView):
|
||||||
|
'''
|
||||||
|
Returns the number of items booked in a slot
|
||||||
|
|
||||||
|
Takes a noOfDays argument to specify how many days worth of data to grab
|
||||||
|
'''
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
#TODO: FIX THIS GARBAGE I HATE IT
|
|
||||||
# 5 days starting day before - Return Array of arrays
|
|
||||||
day = checkDayNumber(request.GET.get('day', ''))
|
day = checkDayNumber(request.GET.get('day', ''))
|
||||||
days = checkDayNumber(request.GET.get('noOfDays', ''))
|
|
||||||
# timeslots = ['00:00-03:00', '03:00-06:00', '06:00-09:00', '08:00-12:00', '12:00-18:00', '18:00-00:00']
|
|
||||||
timeslots = settings.MIG_TIMESLOTS
|
timeslots = settings.MIG_TIMESLOTS
|
||||||
if checkValue(request.GET.get('values', '')):
|
daySlotArray = []
|
||||||
slotArray = []
|
for slot in timeslots:
|
||||||
if days:
|
daySlotArray.append(buildDictFromTimeslot(slot))
|
||||||
daySlotArray = []
|
return Response(daySlotArray)
|
||||||
for daynum in range(days):
|
|
||||||
for slot in timeslots:
|
|
||||||
slotArray.append(Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(daynum -1), booked_time=slot).count())
|
|
||||||
daySlotArray.append(slotArray)
|
|
||||||
slotArray = []
|
|
||||||
return Response(daySlotArray)
|
|
||||||
for slot in timeslots:
|
|
||||||
slotArray.append(Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(day), booked_time=slot).count())
|
|
||||||
return Response(slotArray)
|
|
||||||
else:
|
|
||||||
slotDict = {}
|
|
||||||
for slot in timeslots:
|
|
||||||
slotDict[slot] = Migration.objects.filter(migration_status="Booked", booked_date=datetime.datetime.now().date() + datetime.timedelta(day), booked_time=slot).count()
|
|
||||||
return Response(slotDict)
|
|
||||||
|
|
||||||
|
|
||||||
class getTimeslots(APIView):
|
class getTimeslots(APIView):
|
||||||
|
|||||||
Reference in New Issue
Block a user