def construct_compound_reservation(request_group, semester_start): '''Convert a RequestGroup into a CompoundReservation, translating datetimes to kernel epoch times. The Request windows were already translated into visible windows during the filter_on_visibility step. ''' reservations = [] for index, request in enumerate(request_group.requests): visibility_intervals_for_resources = req_windows_to_kernel_intervals(request.windows.windows_for_resource) kernel_intervals_for_resources = translate_request_windows_to_kernel_windows(visibility_intervals_for_resources, semester_start) # Construct the kernel Reservation res = Reservation(request_group.get_effective_priority(index), request.duration, kernel_intervals_for_resources, previous_solution_reservation=request.scheduled_reservation) # Store the original requests for recovery after scheduling # TODO: Do this with a field provided for this purpose, not this hack res.request_group = request_group res.request = request reservations.append(res) # Combine Reservations into CompoundReservations # Each CompoundReservation represents an actual request to do something compound_res = CompoundReservation(reservations, request_group.operator) return compound_res
def test_build_rr_observation(self): reservation = Reservation(priority=None, duration=10, possible_windows_dict={}) reservation.scheduled_start = 0 reservation.scheduled_resource = '1m0a.doma.bpl' proposal = Proposal({ 'id': 'testPro', 'tag': 'tagPro', 'tac_priority': 39, 'pi': 'me' }) target = ICRSTarget({'name': 'test', 'ra': 23.3, 'dec': 22.2}) request_group = RequestGroup(operator='single', requests=None, proposal=proposal, expires=None, rg_id=333333, is_staff=False, name=None, ipp_value=1.0, observation_type="RAPID_RESPONSE", submitter='') configuration = Mock() configuration.guiding_config = {'mode': 'ON', 'optional': True} configuration.type = 'EXPOSE' configuration.instrument_type = '1M0-FAKE-SCICAM' configuration.constraints = {} configuration.id = 13 configuration.target = target request = Request( configurations=[configuration], windows=None, request_id=22223, ) reservation.request = request reservation.request_group = request_group configdb_interface = Mock() configdb_interface.get_specific_instrument.return_value = 'xx03' configdb_interface.get_autoguider_for_instrument.return_value = 'xx04' received = build_observation(reservation, self.start, configdb_interface) assert_equal(received['request'], 22223) assert_equal(received['site'], 'bpl') assert_equal(received['enclosure'], 'doma') assert_equal(received['telescope'], '1m0a') assert_equal(received['configuration_statuses'][0]['configuration'], 13) assert_equal(received['configuration_statuses'][0]['instrument_name'], 'xx03') assert_equal( received['configuration_statuses'][0]['guide_camera_name'], 'xx04')
def construct_many_compound_reservation(request_group, request_index, semester_start): request = request_group.requests[request_index] visibility_intervals_for_resources = req_windows_to_kernel_intervals(request.windows.windows_for_resource) kernel_intervals_for_resources = translate_request_windows_to_kernel_windows(visibility_intervals_for_resources, semester_start) # Construct the kernel Reservation res = Reservation(request_group.get_effective_priority(request_index), request.duration, kernel_intervals_for_resources, previous_solution_reservation=request.scheduled_reservation) # Store the original requests for recovery after scheduling # TODO: Do this with a field provided for this purpose, not this hack res.request_group = request_group res.request = request # Create a CR of type 'single' for kernel scheduling compound_res = CompoundReservation([res], 'single') return compound_res