def test_filter_on_duration_emits_user_feedback(self):

        # Trickery to gain access to the inner closure
        arg_list = []

        def recording_filter_executor(rg_list, filter_test):
            arg_list.append(rg_list)
            arg_list.append(filter_test)

            return rg_list

        rg_list = []
        filter_on_duration(rg_list, recording_filter_executor)

        w = Mock()
        w.start = datetime(2013, 10, 1)
        w.end = datetime(2013, 10, 3)
        w.get_resource_name.return_value = 'elp'

        ur = Mock()

        r = Mock()
        r.id = 1
        r.duration = 5 * 24 * 3600

        arg_list[1](w, ur, r)
        expected_msg = "Request %d Window (at elp) 2013-10-01 00:00:00 -> 2013-10-03 00:00:00 too small for duration '5 days, 0:00:00'" % r.id
        expected_tag = 'WindowTooSmall'
        ur.emit_rg_feedback.assert_called_with(expected_msg, expected_tag)
    def test_filter_on_duration_no_user_feedback_if_ok(self):

        # Trickery to gain access to the inner closure
        arg_list = []

        def recording_filter_executor(rg_list, filter_test):
            arg_list.append(rg_list)
            arg_list.append(filter_test)

            return rg_list

        rg_list = []
        filter_on_duration(rg_list, recording_filter_executor)

        w = Mock()
        w.start = datetime(2013, 10, 1)
        w.end = datetime(2013, 10, 3)

        rg = Mock()

        r = Mock()
        r.duration = 1 * 24 * 3600

        arg_list[1](w, rg, r)
        assert_equal(rg.emit_rg_feedback.called, False)
    def test_filter_on_duration_window_smaller_tdelta(self):

        # Window is smaller than one hour
        window_dict1 = {
            'start': "2013-09-01T00:00:00Z",
            'end': "2013-09-01T00:30:00Z",
        }
        windows = [(window_dict1,)]
        rg1, window_list = self.create_request_group(windows)

        with patch.object(Request, 'duration') as mock_duration:
            mock_duration.__get__ = Mock(return_value=3600.0)
            received_rg_list = filter_on_duration([rg1])

        received_rg_list = filter_on_duration([rg1])

        request = received_rg_list[0].requests[0]
        received_windows = get_windows_from_request(request, self.resource_name)

        assert_equal(received_windows, [])
Example #4
0
def filter_for_kernel(request_groups, visibility_for_resource, downtime_intervals, semester_start, semester_end,
                      scheduling_horizon):
    '''After throwing out and marking RGs as UNSCHEDULABLE, reduce windows by
       considering dark time and target visibility. Remove any RGs that are now too
       small to hold their duration after this consideration, so they are not passed
       to the kernel.
       NOTE: We do this as an explicit additional filtering step, because we do not
       want to set the UNSCHEDULABLE flag for these Requests. This is because the
       step is network-dependent; if the network subsequently changes (e.g. a
       telescope becomes available), then the Request may then be schedulable.'''
    # trim windows to scheduling horizon, expiry, or end of semester and filter
    rgs = filter_on_scheduling_horizon(request_groups, scheduling_horizon)

    # Filter on rise_set/airmass/downtime intervals
    rgs = filter_on_visibility(rgs, visibility_for_resource, downtime_intervals, semester_start, semester_end)

    # Clean up now impossible Requests
    rgs = filter_on_duration(rgs)
    # TODO: Do we need to drop empty requests here before carrying on?
    rgs = filter_on_type(rgs, [])

    return rgs