예제 #1
0
    def test_equivalence(self):
        partitioner = EquivalencePartitioner.make_propertystate_equivalence()

        p1 = PropertyState(pm_property_id=100)
        p2 = PropertyState(pm_property_id=100)
        p3 = PropertyState(pm_property_id=200)
        p4 = PropertyState(custom_id_1=100)
        p5 = PropertyState(ubid='abc+123')
        p6 = PropertyState(ubid='100')
        p7 = PropertyState(ubid='abc+123')

        equivalence_classes = partitioner.calculate_equivalence_classes(
            [p1, p2])
        self.assertEqual(len(equivalence_classes), 1)

        equivalence_classes = partitioner.calculate_equivalence_classes(
            [p1, p3])
        self.assertEqual(len(equivalence_classes), 2)

        equivalence_classes = partitioner.calculate_equivalence_classes(
            [p1, p4])
        self.assertEqual(len(equivalence_classes), 1)

        equivalence_classes = partitioner.calculate_equivalence_classes(
            [p4, p6])
        self.assertEqual(len(equivalence_classes), 2)

        equivalence_classes = partitioner.calculate_equivalence_classes(
            [p5, p6])
        self.assertEqual(len(equivalence_classes), 2)

        equivalence_classes = partitioner.calculate_equivalence_classes(
            [p5, p7])
        self.assertEqual(len(equivalence_classes), 1)
예제 #2
0
    def test_match_and_merge_unmatched_objects_with_dates(self):
        # Make sure that the dates sort correctly! (only testing release_date, but also sorts
        # on generation_date, then pk

        partitioner = EquivalencePartitioner.make_default_state_equivalence(
            PropertyState)

        self.property_state_factory.get_property_state(
            no_default_data=True,
            address_line_1='123 same address',
            release_date=datetime.datetime(2010,
                                           1,
                                           1,
                                           1,
                                           1,
                                           tzinfo=tz.get_current_timezone()),
            site_eui=25,
            import_file_id=self.import_file.id,
            data_state=DATA_STATE_MAPPING,
        )

        self.property_state_factory.get_property_state(
            no_default_data=True,
            address_line_1='123 same address',
            release_date=datetime.datetime(2015,
                                           1,
                                           1,
                                           1,
                                           1,
                                           tzinfo=tz.get_current_timezone()),
            site_eui=150,
            import_file_id=self.import_file.id,
            data_state=DATA_STATE_MAPPING,
        )

        self.property_state_factory.get_property_state(
            no_default_data=True,
            address_line_1='123 same address',
            release_date=datetime.datetime(2005,
                                           1,
                                           1,
                                           1,
                                           1,
                                           tzinfo=tz.get_current_timezone()),
            site_eui=300,
            import_file_id=self.import_file.id,
            data_state=DATA_STATE_MAPPING,
        )

        props = self.import_file.find_unmatched_property_states()
        uniq_states, dup_states = filter_duplicated_states(props)
        merged, keys = match_and_merge_unmatched_objects(
            uniq_states, partitioner)

        found = False
        for ps in merged:
            found = True
            self.assertEqual(ps.site_eui.magnitude,
                             150)  # from the second record
        self.assertEqual(found, True)
    def test_equivalence(self):
        all_unmatched_properties = self.import_file.find_unmatched_property_states(
        )
        unmatched_properties, duplicate_property_states = tasks.filter_duplicated_states(
            all_unmatched_properties)
        partitioner = EquivalencePartitioner.make_propertystate_equivalence()

        equiv_classes = partitioner.calculate_equivalence_classes(
            unmatched_properties)
        self.assertEqual(len(equiv_classes), 512)
예제 #4
0
    def test_equivalence(self):
        all_unmatched_properties = self.import_file.find_unmatched_property_states(
        )
        unmatched_property_ids, duplicate_property_count = match.filter_duplicate_states(
            all_unmatched_properties)
        partitioner = EquivalencePartitioner.make_propertystate_equivalence()

        unmatched_properties = list(
            PropertyState.objects.filter(pk__in=unmatched_property_ids))
        equiv_classes = partitioner.calculate_equivalence_classes(
            unmatched_properties)
        self.assertEqual(len(equiv_classes), 512)
예제 #5
0
    def test_match_and_merge_unmatched_objects_all_unique(self):
        # create some objects to match and merge
        partitioner = EquivalencePartitioner.make_default_state_equivalence(
            PropertyState)

        for i in range(10):
            self.property_state_factory.get_property_state(
                import_file_id=self.import_file.id,
                data_state=DATA_STATE_MAPPING,
            )

        props = self.import_file.find_unmatched_property_states()
        uniq_states, dup_states = filter_duplicated_states(props)
        merged, keys = match_and_merge_unmatched_objects(
            uniq_states, partitioner)

        self.assertEqual(len(merged), 10)
예제 #6
0
    def test_match_and_merge_unmatched_objects_with_duplicates(self):
        # create some objects to match and merge
        partitioner = EquivalencePartitioner.make_default_state_equivalence(
            PropertyState)

        for i in range(8):
            self.property_state_factory.get_property_state(
                import_file_id=self.import_file.id,
                data_state=DATA_STATE_MAPPING,
            )

        self.property_state_factory.get_property_state(
            no_default_data=True,
            extra_data={'moniker': '12345'},
            address_line_1='123 same address',
            site_eui=25,
            import_file_id=self.import_file.id,
            data_state=DATA_STATE_MAPPING,
        )

        self.property_state_factory.get_property_state(
            no_default_data=True,
            extra_data={'moniker': '12345'},
            address_line_1='123 same address',
            site_eui=150,
            import_file_id=self.import_file.id,
            data_state=DATA_STATE_MAPPING,
        )

        props = self.import_file.find_unmatched_property_states()
        uniq_states, dup_states = filter_duplicated_states(props)
        merged, keys = match_and_merge_unmatched_objects(
            uniq_states, partitioner)

        self.assertEqual(len(merged), 9)
        self.assertEqual(len(keys), 9)

        # find the ps_cp_1 in the list of merged
        found = False
        for ps in merged:
            if ps.extra_data.get('moniker', None) == '12345':
                found = True
                self.assertEqual(ps.site_eui.magnitude,
                                 150)  # from the second record
        self.assertEqual(found, True)