Ejemplo n.º 1
0
    def test_position_case_C(self):
        """UNIT test: services.common.slots.position (CASE C)
        CASE C: slot[0] > interval[0], slot[1] < interval[1]
        """

        i0 = misc.get_next_midnight() + py_delta(days=300, hours=12)
        interval = (i0, i0 + py_delta(days=2))

        slot = (
            misc.get_next_midnight() + py_delta(hours=13),
            misc.get_next_midnight() + py_delta(hours=14)
        )
        result = slots.position(interval, slot)
        expected = (
            slot[0] + py_delta(days=300), slot[1] + py_delta(days=300)
        )

        self.assertEquals(result, expected)

        slot = (
            misc.get_next_midnight() + py_delta(hours=13),
            misc.get_next_midnight() + py_delta(days=1, hours=10)
        )
        result = slots.position(interval, slot)
        expected = (
            slot[0] + py_delta(days=300), slot[1] + py_delta(days=300)
        )

        self.assertEquals(result, expected)
Ejemplo n.º 2
0
    def generate_available_slots_daily(rule_values, interval=None):
        """
        This method generates the available slots for a daily rule that
        starts and ends in the given dates, during the specified interval.
        TODO :: improve the generation algorithm in order to avoid generating
                slots since the start of the rule until the validity of the
                current interval (can be long)
        :param interval: Interval of applicability
        :param rule_values: The values for the ONCE availability rule
        """
        if interval is None:
            interval = simulation.OrbitalSimulator.get_simulation_window()

        try:
            r = AvailabilityRuleDaily.objects.get(
                availabilityrule_ptr_id=rule_values['id'])
        except dj_exceptions.ObjectDoesNotExist as ex:
            logger.warning(
                '>>> Child rule does not exist, returning no slots, ex = ' +
                str(ex))
            return []

        result = []
        slot_i = slots.position(interval, (r.starting_time, r.ending_time))

        while slot_i[0] < interval[1]:

            slot = slots.cutoff(interval, slot_i)
            result.append((slot[0], slot[1]))

            slot_i = (slot_i[0] + py_timedelta(days=1),
                      slot_i[1] + py_timedelta(days=1))

        return result
Ejemplo n.º 3
0
    def test_position_case_C(self):
        """UNIT test: services.common.slots.position (CASE C)
        CASE C: slot[0] > interval[0], slot[1] < interval[1]
        """

        i0 = misc.get_next_midnight() + py_delta(days=300, hours=12)
        interval = (i0, i0 + py_delta(days=2))

        slot = (misc.get_next_midnight() + py_delta(hours=13),
                misc.get_next_midnight() + py_delta(hours=14))
        result = slots.position(interval, slot)
        expected = (slot[0] + py_delta(days=300), slot[1] + py_delta(days=300))

        self.assertEquals(result, expected)

        slot = (misc.get_next_midnight() + py_delta(hours=13),
                misc.get_next_midnight() + py_delta(days=1, hours=10))
        result = slots.position(interval, slot)
        expected = (slot[0] + py_delta(days=300), slot[1] + py_delta(days=300))

        self.assertEquals(result, expected)
Ejemplo n.º 4
0
    def generate_available_slots_daily(rule_values, interval=None):
        """
        This method generates the available slots for a daily rule that
        starts and ends in the given dates, during the specified interval.
        TODO :: improve the generation algorithm in order to avoid generating
                slots since the start of the rule until the validity of the
                current interval (can be long)
        :param interval: Interval of applicability
        :param rule_values: The values for the ONCE availability rule
        """
        if interval is None:
            interval = simulation.OrbitalSimulator.get_simulation_window()

        try:
            r = AvailabilityRuleDaily.objects.get(
                availabilityrule_ptr_id=rule_values['id']
            )
        except dj_exceptions.ObjectDoesNotExist as ex:
            logger.warning(
                '>>> Child rule does not exist, returning no slots, ex = ' +
                str(ex)
            )
            return []

        result = []
        slot_i = slots.position(interval, (r.starting_time, r.ending_time))

        while slot_i[0] < interval[1]:

            slot = slots.cutoff(interval, slot_i)
            result.append((slot[0], slot[1]))

            slot_i = (
                slot_i[0] + py_timedelta(days=1),
                slot_i[1] + py_timedelta(days=1)
            )

        return result