def testDeconflictReservation(self): processedTime = datetimeAsIso8601(dt.now()) reservationRequest = reservationRequestWithConflicts() availabilityList = antennaAvailability() for antenna in reservationRequest['contactPlan']['antennas']: antennaId = antenna['id'] for contact in antenna['contacts']: for antenna in availabilityList['antennas']: if antenna['antennaId'] == antennaId: denied = False for window in antenna['outOfServiceWindows']: overlap = doWindowsOverlap(contact['startTime'], contact['stopTime'], window['startTime'], window['stopTime']) denied = denied or overlap contact['status'] = ('DENIED_OUT_OF_SERVICE' if denied else 'RESERVED') contact['processedTime'] = processedTime expectedStatusList = { 'SkySat-A-rev1006-Fairbanks-1': 'DENIED_OUT_OF_SERVICE', 'SkySat-B-rev2209-Fairbanks-1': 'RESERVED', 'SkySat-A-rev1006-Fairbanks-2': 'RESERVED', 'SkySat-B-rev2209-Fairbanks-2': 'DENIED_OUT_OF_SERVICE', } for antenna in reservationRequest['contactPlan']['antennas']: for contact in antenna['contacts']: # print "'%s\' : '%s'" % (contact['id'], contact['status']) self.assertEqual(contact['status'], expectedStatusList[contact['id']]) pass
def testDeconflictReservation(self): processedTime = datetimeAsIso8601(dt.now()) reservationRequest = reservationRequestWithConflicts() availabilityList = antennaAvailability() for antenna in reservationRequest['contactPlan']['antennas']: antennaId = antenna['id'] for contact in antenna['contacts']: for antenna in availabilityList['antennas']: if antenna['antennaId'] == antennaId : denied = False for window in antenna['outOfServiceWindows']: overlap = doWindowsOverlap(contact['startTime'], contact['stopTime'], window['startTime'], window['stopTime']) denied = denied or overlap contact['status'] = ('DENIED_OUT_OF_SERVICE' if denied else 'RESERVED') contact['processedTime'] = processedTime expectedStatusList = { 'SkySat-A-rev1006-Fairbanks-1' : 'DENIED_OUT_OF_SERVICE', 'SkySat-B-rev2209-Fairbanks-1' : 'RESERVED', 'SkySat-A-rev1006-Fairbanks-2' : 'RESERVED', 'SkySat-B-rev2209-Fairbanks-2' : 'DENIED_OUT_OF_SERVICE', } for antenna in reservationRequest['contactPlan']['antennas']: for contact in antenna['contacts']: # print "'%s\' : '%s'" % (contact['id'], contact['status']) self.assertEqual(contact['status'], expectedStatusList[contact['id']]) pass
def processReservation(requestJson, antennaAvailabilityList): processedTime = datetimeAsIso8601(dt.now()) reservationRequest = deepcopy(requestJson) deniedCount = 0 for antenna in reservationRequest['contactPlan']['antennas']: antennaId = antenna['id'] for contact in antenna['contacts']: for antenna in antennaAvailabilityList['antennas']: if antenna['antennaId'] == antennaId: denied = False for window in antenna['outOfServiceWindows']: overlap = doWindowsOverlap(contact['startTime'], contact['stopTime'], window['startTime'], window['stopTime']) denied = denied or overlap contact['status'] = ('DENIED_OUT_OF_SERVICE' if denied else 'RESERVED') contact['processedTime'] = processedTime if denied: deniedCount += 1 return (deniedCount, reservationRequest)
def testWindowsOverlap(self): outageStart = dt(2015, 10, 13, 13, 10, 00) outageEnd = dt(2015, 10, 13, 13, 20, 00) before = dt(2015, 10, 13, 13, 9, 00) withinEarly = dt(2015, 10, 13, 13, 11, 00) withinLate = dt(2015, 10, 13, 13, 19, 00) after = dt(2015, 10, 13, 13, 30, 00) # Contact Start before, End within self.assertTrue( doWindowsOverlap(before, withinLate, outageStart, outageEnd)) # Contact Start/End within self.assertTrue( doWindowsOverlap(withinEarly, withinLate, outageStart, outageEnd)) # Contact Start within. End after self.assertTrue( doWindowsOverlap(withinEarly, after, outageStart, outageEnd)) # Contact Start before, Contact End after self.assertTrue(doWindowsOverlap(before, after, outageStart, outageEnd)) # Contact Start = Window End self.assertTrue( doWindowsOverlap(outageEnd, after, outageStart, outageEnd)) # Contact End = Window Start self.assertTrue( doWindowsOverlap(before, outageStart, outageStart, outageEnd))
def processReservation(requestJson, antennaAvailabilityList): processedTime = datetimeAsIso8601(dt.now()) reservationRequest = deepcopy(requestJson) deniedCount = 0 for antenna in reservationRequest['contactPlan']['antennas']: antennaId = antenna['id'] for contact in antenna['contacts']: for antenna in antennaAvailabilityList['antennas']: if antenna['antennaId'] == antennaId : denied = False for window in antenna['outOfServiceWindows']: overlap = doWindowsOverlap(contact['startTime'], contact['stopTime'], window['startTime'], window['stopTime']) denied = denied or overlap contact['status'] = ('DENIED_OUT_OF_SERVICE' if denied else 'RESERVED') contact['processedTime'] = processedTime if denied: deniedCount +=1 return (deniedCount, reservationRequest)
def testWindowsOverlap(self): outageStart = dt(2015, 10, 13, 13, 10, 00) outageEnd = dt(2015, 10, 13, 13, 20, 00) before = dt(2015, 10, 13, 13, 9, 00) withinEarly = dt(2015, 10, 13, 13, 11, 00) withinLate = dt(2015, 10, 13, 13, 19, 00) after = dt(2015, 10, 13, 13, 30, 00) # Contact Start before, End within self.assertTrue(doWindowsOverlap(before, withinLate, outageStart, outageEnd )) # Contact Start/End within self.assertTrue(doWindowsOverlap(withinEarly, withinLate, outageStart, outageEnd )) # Contact Start within. End after self.assertTrue(doWindowsOverlap(withinEarly, after, outageStart, outageEnd )) # Contact Start before, Contact End after self.assertTrue(doWindowsOverlap(before, after, outageStart, outageEnd )) # Contact Start = Window End self.assertTrue(doWindowsOverlap(outageEnd, after, outageStart, outageEnd )) # Contact End = Window Start self.assertTrue(doWindowsOverlap(before, outageStart, outageStart, outageEnd ))