Example #1
0
 def test_merge_none(self):
     """UNIT test: services.common.slots.merge_slots (robustness)
     Nones and empties test.
     """
     self.assertCountEqual([], slots.merge_slots(None, None),
                           '[] is the expected response to (None, None)')
     self.assertCountEqual([], slots.merge_slots([], []),
                           '[] is the expected response to ([], [])')
Example #2
0
    def test_merge_case_complex_2(self):
        """UNIT test: services.common.slots.merge_slots (complex case #2)
        """
        if self.__verbose_testing:
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
            print('TESTING MERGE, COMPLEX CASE #2')
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')

        p = (misc.get_today_utc() + timedelta(hours=0),
             misc.get_today_utc() + timedelta(hours=1))
        q = (misc.get_today_utc() + timedelta(hours=2),
             misc.get_today_utc() + timedelta(hours=3))
        r = (misc.get_today_utc() + timedelta(hours=2),
             misc.get_today_utc() + timedelta(hours=4))
        s = (misc.get_today_utc() + timedelta(hours=3),
             misc.get_today_utc() + timedelta(hours=5))

        m = (misc.get_today_utc() + timedelta(hours=0),
             misc.get_today_utc() + timedelta(hours=3))

        expected_s = [(m[1], r[1]), s]
        actual_s = slots.merge_slots([p, q, r, s], [m])

        if self.__verbose_testing:
            misc.print_list([p, q, r, s], name='(+) slots')
            misc.print_list([m], name='(-) slots')
            misc.print_list(actual_s, name='(A) slots')
            misc.print_list(expected_s, name='(EXPECTED) slots')

        self.assertCountEqual(expected_s, actual_s,
                              'COMPLEX CASE #2: Wrong result!')
Example #3
0
    def test_merge_case_multiple_end(self):
        """UNIT test: services.common.slots.merge_slots (multiple + slots)
        Case merging multiple ending (+) slots)
        """
        if self.__verbose_testing:
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
            print('TESTING MERGE, CASE MULITPLE (+)')
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')

        p = (misc.get_today_utc() + timedelta(hours=2),
             misc.get_today_utc() + timedelta(hours=3))
        q = (misc.get_today_utc() + timedelta(hours=4),
             misc.get_today_utc() + timedelta(hours=5))
        r = (misc.get_today_utc() + timedelta(hours=6),
             misc.get_today_utc() + timedelta(hours=7))
        s = (misc.get_today_utc() + timedelta(hours=8),
             misc.get_today_utc() + timedelta(hours=9))

        m = (misc.get_today_utc() + timedelta(hours=0),
             misc.get_today_utc() + timedelta(hours=1))
        expected_s = [p, q, r, s]
        actual_s = slots.merge_slots([p, q, r, s], [m])

        if self.__verbose_testing:
            misc.print_list(p, name='(+) slots')
            misc.print_list(m, name='(-) slots')
            misc.print_list(actual_s, name='(A) slots')
            misc.print_list(expected_s, name='(EXPECTED) slots')

        self.assertCountEqual(expected_s, actual_s,
                              'CASE MULTIPLE: Wrong result!')
Example #4
0
    def test_merge_case_no_m_slots(self):
        """UNIT test: services.common.slots.merge_slots (p slots)
        Case merging p slots without m slots.
        """
        if self.__verbose_testing:
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
            print('TESTING MERGE, CASE NONE M SLOTS')
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')

        p = (misc.get_today_utc() + timedelta(hours=2),
             misc.get_today_utc() + timedelta(hours=3))
        q = (misc.get_today_utc() + timedelta(hours=4),
             misc.get_today_utc() + timedelta(hours=5))
        r = (misc.get_today_utc() + timedelta(hours=6),
             misc.get_today_utc() + timedelta(hours=7))
        s = (misc.get_today_utc() + timedelta(hours=8),
             misc.get_today_utc() + timedelta(hours=9))

        expected_s = [p, q, r, s]
        actual_s = slots.merge_slots([p, q, r, s], [])

        if self.__verbose_testing:
            misc.print_list(p, name='(+) slots')
            misc.print_list([], name='(-) slots')
            misc.print_list(actual_s, name='(A) slots')
            misc.print_list(expected_s, name='(EXPECTED) slots')

        self.assertCountEqual(expected_s, actual_s,
                              'CASE NONE M: Wrong result!')
Example #5
0
    def get_availability_slots(groundstation, interval=None):
        """
        This method generates the availability slots for this set of rules.
        :param groundstation; Reference to the ground station
        :param interval: Time interval for slot generation
        """
        if interval is None:
            if satnet_settings.TESTING:
                interval = AvailabilityRuleManager.create_test_window()
            else:
                interval = simulation.OrbitalSimulator.get_simulation_window()

        add_rules, remove_rules = AvailabilityRuleManager\
            .get_applicable_rule_values(groundstation, interval=interval)

        logger.info(
            misc.list_2_string(
                AvailabilityRule.objects.all().values(),
                name='@get_availabilit_slots.rules'
            )
        )
        logger.info(
            '>>> @get_availabilit_slots.interval = ' + slots.string(interval)
        )

        # 0) We obtain the applicable slots from the database
        add_slots = []
        for r in add_rules:
            add_slots += AvailabilityRuleManager.generate_available_slots(
                r, interval=interval
            )

        remove_slots = []
        for r in remove_rules:
            remove_slots += AvailabilityRuleManager.generate_available_slots(
                r, interval=interval
            )

        # 1) First, raw slots must be sorted and normalized.
        add_slots = slots.normalize_slots(
            sorted(add_slots, key=lambda s: s[1])
        )
        remove_slots = slots.normalize_slots(
            sorted(remove_slots, key=lambda s: s[0])
        )

        # 2) Sorted and normalized slots can be merged to generated the final
        # availability slots.
        return slots.merge_slots(add_slots, remove_slots)
Example #6
0
    def test_merge_case_complex_3(self):
        """UNIT test: services.common.slots.merge_slots (complex case #3)
        """
        if self.__verbose_testing:
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
            print('TESTING MERGE, COMPLEX CASE #3')
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')

        p = (misc.get_today_utc() + timedelta(hours=0),
             misc.get_today_utc() + timedelta(hours=1))
        q = (misc.get_today_utc() + timedelta(hours=2),
             misc.get_today_utc() + timedelta(hours=3))
        r = (misc.get_today_utc() + timedelta(hours=2),
             misc.get_today_utc() + timedelta(hours=4))
        s = (misc.get_today_utc() + timedelta(hours=3),
             misc.get_today_utc() + timedelta(hours=5))

        t = (misc.get_today_utc() + timedelta(hours=6),
             misc.get_today_utc() + timedelta(hours=7))
        u = (misc.get_today_utc() + timedelta(hours=8),
             misc.get_today_utc() + timedelta(hours=9))
        v = (misc.get_today_utc() + timedelta(hours=10),
             misc.get_today_utc() + timedelta(hours=11))

        m = (misc.get_today_utc() + timedelta(hours=0),
             misc.get_today_utc() + timedelta(hours=3))

        n = (misc.get_today_utc() + timedelta(hours=3, minutes=30),
             misc.get_today_utc() + timedelta(hours=4))

        expected_s = [(m[1], n[0]), (s[0], n[0]), (n[1], s[1]), t, u, v]
        actual_s = slots.merge_slots([p, q, r, s, t, u, v], [m, n])

        if self.__verbose_testing:
            misc.print_list([p, q, r, s], name='(+) slots')
            misc.print_list([m, n], name='(-) slots')
            misc.print_list(actual_s, name='(A) slots')
            misc.print_list(expected_s, name='(EXPECTED) slots')

        self.assertCountEqual(expected_s, actual_s,
                              'COMPLEX CASE #1: Wrong result!')
Example #7
0
    def get_availability_slots(groundstation, interval=None):
        """
        This method generates the availability slots for this set of rules.
        :param groundstation; Reference to the ground station
        :param interval: Time interval for slot generation
        """
        if interval is None:
            if satnet_settings.TESTING:
                interval = AvailabilityRuleManager.create_test_window()
            else:
                interval = simulation.OrbitalSimulator.get_simulation_window()

        add_rules, remove_rules = AvailabilityRuleManager\
            .get_applicable_rule_values(groundstation, interval=interval)

        logger.info(
            misc.list_2_string(AvailabilityRule.objects.all().values(),
                               name='@get_availabilit_slots.rules'))
        logger.info('>>> @get_availabilit_slots.interval = ' +
                    slots.string(interval))

        # 0) We obtain the applicable slots from the database
        add_slots = []
        for r in add_rules:
            add_slots += AvailabilityRuleManager.generate_available_slots(
                r, interval=interval)

        remove_slots = []
        for r in remove_rules:
            remove_slots += AvailabilityRuleManager.generate_available_slots(
                r, interval=interval)

        # 1) First, raw slots must be sorted and normalized.
        add_slots = slots.normalize_slots(sorted(add_slots,
                                                 key=lambda s: s[1]))
        remove_slots = slots.normalize_slots(
            sorted(remove_slots, key=lambda s: s[0]))

        # 2) Sorted and normalized slots can be merged to generated the final
        # availability slots.
        return slots.merge_slots(add_slots, remove_slots)
Example #8
0
    def test_merge_case_c(self):
        """UNIT test: services.common.slots.merge_slots (case C)
        Case C for merging slots.
        """
        if self.__verbose_testing:
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')
            print('TESTING MERGE, CASE C')
            print('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$')

        p = (misc.get_today_utc(), misc.get_today_utc() + timedelta(hours=5))
        m = (misc.get_today_utc() + timedelta(hours=1),
             misc.get_today_utc() + timedelta(hours=4))

        expected_s = [(p[0], m[0]), (m[1], p[1])]
        actual_s = slots.merge_slots([p], [m])

        if self.__verbose_testing:
            misc.print_list(p, name='(+) slots')
            misc.print_list(m, name='(-) slots')
            misc.print_list(actual_s, name='(A) slots')
            misc.print_list(expected_s, name='(EXPECTED) slots')

        self.assertCountEqual(expected_s, actual_s, 'CASE C: Wrong result!')