Exemplo n.º 1
0
    def get(self, request):
        try:
            start, end = get_start_end_paramters(request, default_days_back=0)
        except ValueError as e:
            return HttpResponseBadRequest(str(e))
        sites = request.query_params.getlist('site')
        telescopes = request.query_params.getlist('telescope')
        telescope_states = TelescopeStates(start, end, sites=sites, telescopes=telescopes).get()
        str_telescope_states = {str(k): v for k, v in telescope_states.items()}

        return Response(str_telescope_states)
Exemplo n.º 2
0
    def test_states_no_duplicate_consecutive_states(self):
        telescope_states = TelescopeStates(self.start, self.end).get()

        for tk, events in telescope_states.items():
            previous_event = None
            for event in events:
                if previous_event:
                    self.assertTrue(previous_event['event_type'] != event['event_type'] or
                                    previous_event['event_reason'] != event['event_reason'])

                previous_event = event
Exemplo n.º 3
0
def get_telescope_states_for_request(request):
    instrument_type = request.molecules.first().instrument_name
    site_intervals = {}
    # Build up the list of telescopes and their rise set intervals for the target on this request
    site_data = configdb.get_sites_with_instrument_type_and_location(
        instrument_type=instrument_type,
        site_code=request.location.site,
        observatory_code=request.location.observatory,
        telescope_code=request.location.telescope)
    for site, details in site_data.items():
        if site not in site_intervals:
            site_intervals[site] = get_rise_set_intervals(
                request.as_dict, site)
    # If you have no sites, return the empty dict here
    if not site_intervals:
        return {}

    # Retrieve the telescope states for that set of sites
    telescope_states = TelescopeStates(start=request.min_window_time,
                                       end=request.max_window_time,
                                       sites=list(site_intervals.keys()),
                                       instrument_types=[instrument_type
                                                         ]).get()
    # Remove the empty intervals from the dictionary
    site_intervals = {
        site: intervals
        for site, intervals in site_intervals.items() if intervals
    }

    # Filter the telescope states list with the site intervals
    filtered_telescope_states = filter_telescope_states_by_intervals(
        telescope_states, site_intervals, request.min_window_time,
        request.max_window_time)

    return filtered_telescope_states
Exemplo n.º 4
0
    def test_aggregate_states_1(self):
        start = datetime(2016, 10, 1)
        end = datetime(2016, 10, 2)
        telescope_states = TelescopeStates(start, end).get()

        self.assertIn(self.tk1, telescope_states)
        self.assertIn(self.tk2, telescope_states)

        doma_expected_available_state = {'telescope': 'tst.doma.1m0a',
                                         'event_type': 'AVAILABLE',
                                         'event_reason': 'Available for scheduling',
                                         'start': datetime(2016, 10, 1, 18, 24, 58, tzinfo=timezone.utc),
                                         'end': datetime(2016, 10, 1, 20, 44, 58, tzinfo=timezone.utc)
                                         }

        self.assertIn(doma_expected_available_state, telescope_states[self.tk1])

        domb_expected_available_state1 = {'telescope': 'tst.domb.1m0a',
                                          'event_type': 'AVAILABLE',
                                          'event_reason': 'Available for scheduling',
                                          'start': datetime(2016, 10, 1, 18, 30, 0, tzinfo=timezone.utc),
                                          'end': datetime(2016, 10, 1, 19, 24, 59, tzinfo=timezone.utc)
                                          }

        self.assertIn(domb_expected_available_state1, telescope_states[self.tk2])

        domb_expected_available_state2 = {'telescope': 'tst.domb.1m0a',
                                          'event_type': 'AVAILABLE',
                                          'event_reason': 'Available for scheduling',
                                          'start': datetime(2016, 10, 1, 20, 24, 59, tzinfo=timezone.utc),
                                          'end': datetime(2016, 10, 1, 20, 44, 58, tzinfo=timezone.utc)
                                          }
        self.assertIn(domb_expected_available_state2, telescope_states[self.tk2])
Exemplo n.º 5
0
    def test_states_end_time_after_start(self):
        telescope_states = TelescopeStates(self.start, self.end).get()

        for tk, events in telescope_states.items():
            for event in events:
                self.assertTrue(event['start'] <= event['end'])
Exemplo n.º 6
0
    def test_states_no_enclosure_interlock(self):
        telescope_states = TelescopeStates(self.start, self.end).get()

        self.assertNotIn("ENCLOSURE_INTERLOCK", telescope_states)
Exemplo n.º 7
0
 def test_one_telescope_correctness(self):
     telescope_states = TelescopeStates(self.start, self.end).get()
     tak = TelescopeKey(site='lsc', observatory='domb', telescope='1m0a')
     expected_events = [{'end': datetime(2016, 10, 3, 10, 25, 5, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 1, 0, 0, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 3, 10, 31, 20, tzinfo=timezone.utc),
                         'event_reason': 'Sequencer: Sequencer unavailable for scheduling',
                         'event_type': 'SEQUENCER_DISABLED',
                         'start': datetime(2016, 10, 3, 10, 25, 5, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 3, 16, 47, 42, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 3, 10, 31, 20, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 3, 17, 7, 49, tzinfo=timezone.utc),
                         'event_reason': 'Site Agent: No update since 2016-10-03T16:37:35',
                         'event_type': 'SITE_AGENT_UNRESPONSIVE',
                         'start': datetime(2016, 10, 3, 16, 47, 42, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 3, 23, 35, 58, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 3, 17, 7, 49, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 4, 1, 3, tzinfo=timezone.utc),
                         'event_reason': 'Weather: Sky transparency too low',
                         'event_type': 'NOT_OK_TO_OPEN',
                         'start': datetime(2016, 10, 3, 23, 35, 58, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 4, 1, 20, 46, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 4, 1, 3, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 4, 10, 30, 55, tzinfo=timezone.utc),
                         'event_reason': 'Weather: Sky transparency too low',
                         'event_type': 'NOT_OK_TO_OPEN',
                         'start': datetime(2016, 10, 4, 1, 20, 46, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 4, 21, 47, 6, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 4, 10, 30, 55, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 5, 0, 58, 26, tzinfo=timezone.utc),
                         'event_reason': 'Sequencer: Sequencer in MANUAL state',
                         'event_type': 'SEQUENCER_DISABLED',
                         'start': datetime(2016, 10, 4, 21, 47, 6, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 6, 16, 48, 6, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 5, 0, 58, 26, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 6, 16, 57, 19, tzinfo=timezone.utc),
                         'event_reason': 'Site Agent: No update since 2016-10-06T16:12:10',
                         'event_type': 'SITE_AGENT_UNRESPONSIVE',
                         'start': datetime(2016, 10, 6, 16, 48, 6, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 7, 10, 20, 44, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 6, 16, 57, 19, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 7, 10, 28, 58, tzinfo=timezone.utc),
                         'event_reason': 'Sequencer: Sequencer unavailable for scheduling',
                         'event_type': 'SEQUENCER_DISABLED',
                         'start': datetime(2016, 10, 7, 10, 20, 44, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 8, 10, 20, 25, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 7, 10, 28, 58, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 8, 10, 28, 36, tzinfo=timezone.utc),
                         'event_reason': 'Sequencer: Sequencer unavailable for scheduling',
                         'event_type': 'SEQUENCER_DISABLED',
                         'start': datetime(2016, 10, 8, 10, 20, 25, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'},
                        {'end': datetime(2016, 10, 10, 0, 0, tzinfo=timezone.utc),
                         'event_reason': 'Available for scheduling',
                         'event_type': 'AVAILABLE',
                         'start': datetime(2016, 10, 8, 10, 28, 36, tzinfo=timezone.utc),
                         'telescope': 'lsc.domb.1m0a'}]
     # looked in depth at lsc.domb.1m0a in the date range to verify correctness of this
     # data is available on the telescope_events index of elasticsearch
     self.assertEqual(telescope_states[tak], expected_events)