def process_request_visibility(request_group_id, request, target_intervals, downtime_intervals): request = compute_request_availability(request, target_intervals, downtime_intervals) if request.has_windows(): tag = 'RequestIsVisible' msg = 'Request {} (RG {}) is visible ({} windows remaining)'.format(request.id, request_group_id, request.n_windows()) else: tag = 'RequestIsNotVisible' msg = 'Request {} (RG {}) is not up and dark at any available telescope'.format(request.id, request_group_id) RequestGroup.emit_request_group_feedback(request_group_id, msg, tag)
def test_filter_on_pending(self): request_id = 5 r1 = Request( configurations=None, windows=Windows(), request_id=request_id, state='PENDING' ) r2 = Request( configurations=None, windows=Windows(), request_id=9, state='UNSCHEDULABLE' ) rg1 = RequestGroup( operator='single', requests=[r1, r2], proposal=None, expires=None, rg_id=1, is_staff=False, name=None, ipp_value=1.0, observation_type='NORMAL', submitter='', ) filter_on_pending([rg1]) assert_equal(rg1.requests, [r1])
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 test_emit_user_feedback(self, mock_func): request_group_id = 5 operator = 'single' rg = RequestGroup(operator=operator, requests=[], proposal=None, expires=None, rg_id=request_group_id, is_staff=False, name=None, ipp_value=1.0, observation_type='NORMAL', submitter='') msg = 'Yo dude' tag = 'MeTag' timestamp = datetime(2013, 10, 15, 1, 1, 1) rg.emit_rg_feedback(msg, tag, timestamp) assert_equal(mock_func.called, True)
def create_request_group(window_dicts, operator='and', resource_name='Martin', configurations=None, proposal=create_mock_proposal(), expires=None, duration=60, first_request_id=5, request_group_id=5): t1 = {'name': resource_name} req_list = [] window_list = [] next_request_id = int(first_request_id) for req_windows in window_dicts: windows = Windows() for window_dict in req_windows: w = Window(window_dict=window_dict, resource=t1['name']) windows.append(w) window_list.append(w) r = Request(configurations=configurations, windows=windows, request_id=next_request_id) r.get_duration = Mock(return_value=duration) req_list.append(r) next_request_id += 1 if len(req_list) == 1: operator = 'single' if expires: RequestGroup.expires = PropertyMock(return_value=expires) else: RequestGroup.expires = PropertyMock(return_value=datetime.utcnow() + timedelta(days=365)) rg = RequestGroup( operator=operator, requests=req_list, proposal=proposal, expires=None, rg_id=request_group_id, is_staff=False, name=None, ipp_value=1.0, observation_type='NORMAL', submitter='', ) return rg, window_list
def test_drop_empty_children(self): r_mock1 = mock.MagicMock() r_mock1.has_windows.return_value = True r_mock2 = mock.MagicMock() r_mock2.has_windows.return_value = False rg = RequestGroup(operator='many', requests=[r_mock1, r_mock2], name='Group 1', proposal=Proposal(), rg_id=1, is_staff=False, observation_type='NORMAL', ipp_value=1.0, expires=datetime(2999, 1, 1), submitter='') rg.drop_empty_children() assert_equal(len(rg.requests), 1) assert_equal(rg.requests[0], r_mock1)
def create_request_group(self, expiry_dt): rg = RequestGroup( operator='single', requests=None, proposal=None, expires=expiry_dt, rg_id='0000000005', is_staff=False, name=None, ipp_value=1.0, observation_type='NORMAL', submitter='' ) return rg
def test_large_and_requests(self): days_out = 0 # build up a request a day for 100 days out new_time = datetime(2016, 10, 3, 5, 0) request_list = [] while days_out < 80: resource = '1m0a.doma.ogg' window = Window( { 'start': new_time + timedelta(days=days_out), 'end': new_time + timedelta(days=days_out, hours=0, minutes=30) }, resource) windows = Windows() windows.append(window) request = Request(configurations=[self.configuration], windows=windows, request_id=int("11{}".format(days_out).rjust( 10, '0')), duration=1750) request_list.append(request) days_out += 1 request_group = RequestGroup(operator='and', requests=request_list, proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=100, is_staff=False, ipp_value=1.0, name='large ur', submitter='', observation_type='NORMAL') normal_request_list = [ request_group, ] result = self._schedule_requests([], normal_request_list, new_time - timedelta(hours=10)) scheduled_rgs = result.get_scheduled_requests_by_request_group_id() # assert that none of the and is scheduled (since it has an unschedulable request in it) # assert that both of the manys are scheduled assert 100 in scheduled_rgs for req in request_list: # assert each child request is in the schedule (scheduler schedules past horizon for ands) assert req.id in scheduled_rgs[100]
def test_valid_request_type_does_not_raise_exception(self): valid_res_type = 'and' request = Request( configurations=[self.configuration], windows=self.windows, request_id=self.id, ) RequestGroup(operator=valid_res_type, requests=[request], name='Group 1', proposal=Proposal(), rg_id=1, is_staff=False, observation_type='NORMAL', ipp_value=1.0, expires=datetime(2999, 1, 1), submitter='')
def make_request_group(self, requests, operator='single'): proposal = Proposal({ 'id': 'TestProposal', 'tag': 'Test Proposal', 'pi': '', 'tac_priority': 10 }) rg = RequestGroup(operator=operator, requests=requests, proposal=proposal, submitter='', expires=datetime(2999, 1, 1), rg_id=1, is_staff=False, name='test group id', ipp_value=1.0, observation_type='NORMAL') return rg
def test_drop_empty_requests(self): request_id = 5 r = Request( configurations=None, windows=Windows(), request_id=request_id ) rg1 = RequestGroup( operator='single', requests=[r], proposal=None, expires=None, rg_id=1, is_staff=False, name=None, ipp_value=1.0, observation_type='NORMAL', submitter='', ) received = drop_empty_requests([rg1]) assert_equal(received, [5])
def _build_request_group(self, base_priority=1.0, ipp_value=1.0): operator = 'single' proposal = Proposal(id='LCOSchedulerTest', pi='Eric Saunders', tag='admin', tac_priority=base_priority) instrument_config = dict(exposure_count=1, bin_x=2, bin_y=2, exposure_time=20, extra_params={}, optical_elements={'filter': 'BSSL-UX-020'}) guiding_config = dict(mode='ON', optional=True, optical_elements={}, extra_params={}, exposure_time=10) acquisition_config = dict(mode='OFF', extra_params={}) constraints = {'max_airmass': None, 'min_lunar_distance': 0.0} configuration1 = Configuration( dict(id=5, target=None, type='expose', instrument_type='1M0-SCICAM-SBIG', priority=1, instrument_configs=[instrument_config], acquisition_config=acquisition_config, guiding_config=guiding_config, extra_params={}, constraints=constraints)) telescope = dict( name='maui', latitude=20.7069444444, longitude=-156.258055556, ) window_dict = { 'start': "2013-03-01T00:00:00Z", 'end': "2013-03-01T00:30:00Z", } w = Window(window_dict=window_dict, resource=telescope['name']) windows = Windows() windows.append(w) r = Request(configurations=[configuration1], windows=windows, request_id='0000000003', duration=10) rg = RequestGroup(operator=operator, requests=[r], proposal=proposal, expires=None, rg_id=4, is_staff=False, ipp_value=ipp_value, observation_type='NORMAL', name=None, submitter='Eric Saunders') return rg
def setup(self): self.target = ICRSTarget( name='deneb', ra=310.35795833333333, dec=45.280338888888885, epoch=2000, ) self.telescope = dict(name='1m0a.doma.ogg', latitude=20.7069444444, longitude=-156.258055556, tel_class='1m0', horizon=15, status='online', ha_limit_neg=-4.6, ha_limit_pos=4.6, zenith_blind_spot=0.0) self.telescopes = {'1m0a.doma.ogg': self.telescope} self.proposal = Proposal(id='LCOSchedulerTest', pi='Eric Saunders', tag='admin', tac_priority=1) self.instrument_config = dict(exposure_count=1, bin_x=2, bin_y=2, exposure_time=60 * 25, optical_elements={'filter': 'b'}) self.guiding_config = dict(mode='ON', optional=True, optical_elements={}, exposure_time=10) self.acquisition_config = dict(mode='OFF') self.constraints = {'max_airmass': None, 'min_lunar_distance': 0} self.configuration = Configuration( **dict(id=5, target=self.target, type='expose', instrument_type='1M0-SCICAM-SBIG', priority=1, instrument_configs=[self.instrument_config], acquisition_config=self.acquisition_config, guiding_config=self.guiding_config, constraints=self.constraints)) self.base_time = datetime(2016, 9, 14, 6, 0) resource_1 = '1m0a.doma.ogg' self.window_1 = Window( { 'start': self.base_time, 'end': self.base_time + timedelta(hours=0, minutes=30) }, resource_1) self.windows_1 = Windows() self.windows_1.append(self.window_1) resource_2 = '1m0a.doma.ogg' self.window_2 = Window( { 'start': self.base_time + timedelta(hours=0, minutes=30), 'end': self.base_time + timedelta(hours=1, minutes=0) }, resource_2) self.windows_2 = Windows() self.windows_2.append(self.window_2) self.resource_3 = '1m0a.doma.ogg' self.window_3 = Window( { 'start': self.base_time + timedelta(hours=1, minutes=0), 'end': self.base_time + timedelta(hours=1, minutes=30) }, self.resource_3) self.windows_3 = Windows() self.windows_3.append(self.window_3) self.request_1 = Request(configurations=[self.configuration], windows=self.windows_1, request_id=1, duration=1750) self.request_2 = Request(configurations=[self.configuration], windows=self.windows_2, request_id=2, duration=1750) self.request_3 = Request(configurations=[self.configuration], windows=self.windows_2, request_id=3, duration=1750) self.request_4 = Request(configurations=[self.configuration], windows=self.windows_3, request_id=4, duration=1750) self.request_5 = Request(configurations=[self.configuration], windows=self.windows_3, request_id=5, duration=1750) self.and_request_group_1 = RequestGroup( operator='and', requests=[self.request_1, self.request_2], proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=1, is_staff=False, observation_type='NORMAL', ipp_value=1.0, name='ur 1', submitter='') self.and_request_group_2 = RequestGroup( operator='and', requests=[self.request_3, self.request_4], proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=2, is_staff=False, observation_type='NORMAL', ipp_value=1.0, name='ur 2', submitter='') self.many_request_group_1 = RequestGroup( operator='many', requests=[self.request_1, self.request_2], proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=3, is_staff=False, observation_type='NORMAL', ipp_value=1.5, name='ur 3', submitter='') self.many_request_group_2 = RequestGroup( operator='many', requests=[self.request_3, self.request_4], proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=4, is_staff=False, observation_type='NORMAL', ipp_value=1.5, name='ur 4', submitter='') self.rr_request_group_1 = RequestGroup( operator='many', requests=[self.request_5], proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=5, is_staff=False, observation_type='RAPID_RESPONSE', ipp_value=1.5, name='ur 5', submitter='') self.rr_request_group_2 = RequestGroup( operator='many', requests=[self.request_1, self.request_3], proposal=self.proposal, expires=datetime(2050, 1, 1), rg_id=6, is_staff=False, observation_type='RAPID_RESPONSE', ipp_value=1.5, name='ur 6', submitter='')