Ejemplo n.º 1
0
    def test_calculate_empty_distances(self):
        empty_case = Case("Empty case")

        assert calculate_case_time_distances(empty_case) == [0]

        single_event_case = Case("Single event case")
        single_event_case.add_event({
            "concept:name":
            "",
            "time:timestamp":
            datetime(2015, 5, 10, 8, 30, 30)
        })

        assert calculate_case_time_distances(single_event_case) == [0]
Ejemplo n.º 2
0
    def test_initialize_cdesf(self, process, cases_list):
        assert process.nyquist == 0
        assert process.check_point_cases == 0

        assert len(process.process_model_graph.edges) == 0
        assert len(process.process_model_graph.nodes) == 0

        assert process.cases == []
        with pytest.raises(Exception):
            assert initialize_graph([])

        case4 = Case("4")
        case4.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case4.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })
        case4.add_event({
            "concept:name": "activityC",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
        })

        process.cases = cases_list
        process.cases.insert(0, case4)
        process.process_model_graph = initialize_graph(process.cases)
        pmg = initialize_graph(cases_list)
        for case in cases_list:
            case.distances = calculate_case_distances(pmg, case)
Ejemplo n.º 3
0
    def test_release_cases_from_memory(self, process):
        case1 = Case("1")
        case2 = Case("2")
        case3 = Case("3")
        case4 = Case("4")
        case4.add_event({
            "concept:name": "activity1",
            "time:timestamp": datetime(2015, 5, 10, 8, 30, 00),
        })
        case1.add_event({
            "concept:name": "activity1",
            "time:timestamp": datetime(2015, 5, 10, 9, 00, 00),
        })
        case3.add_event({
            "concept:name": "activity1",
            "time:timestamp": datetime(2015, 5, 10, 9, 30, 00),
        })
        case2.add_event({
            "concept:name": "activity1",
            "time:timestamp": datetime(2015, 5, 10, 10, 00, 00),
        })

        process.cases = [case2, case3, case1, case4]
        process.release_cases_from_memory()
        assert process.cases == []

        process.cases = [case2, case3, case1, case4]
        process.nyquist = 1
        process.release_cases_from_memory()
        assert process.cases == [case2]

        process.cases = [case2, case3, case1, case4]
        process.nyquist = 2
        process.release_cases_from_memory()
        assert process.cases == [case2, case3]

        process.cases = [case2, case3, case1, case4]
        process.nyquist = 3
        process.release_cases_from_memory()
        assert process.cases == [case2, case3, case1]

        process.cases = [case2, case3, case1, case4]
        process.nyquist = 4
        process.release_cases_from_memory()
        assert process.cases == [case2, case3, case1, case4]
Ejemplo n.º 4
0
    def cases_list(self):
        case_1 = Case("1")
        case_1.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case_1.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })
        case_1.add_event({
            "concept:name": "activityC",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
        })

        case_2 = Case("2")
        case_2.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case_2.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })

        case_3 = Case("3")
        case_3.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case_3.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })
        case_3.add_event({
            "concept:name": "activityC",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
        })
        case_3.add_event({
            "concept:name": "activityD",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 30),
        })

        return [case_3, case_2, case_1]
Ejemplo n.º 5
0
    def test_calculate_actual_distances(self):
        case_one = Case("Case 1")
        case_one.add_event({
            "concept:name": "",
            "time:timestamp": datetime(2015, 5, 10, 8, 30, 30)
        })
        case_one.add_event({
            "concept:name": "",
            "time:timestamp": datetime(2015, 5, 10, 8, 45, 30)
        })
        case_one.add_event({
            "concept:name": "",
            "time:timestamp": datetime(2015, 5, 10, 8, 50, 30)
        })
        case_one.add_event({
            "concept:name": "",
            "time:timestamp": datetime(2015, 5, 10, 8, 53, 30)
        })
        case_one.add_event({
            "concept:name": "",
            "time:timestamp": datetime(2015, 5, 10, 8, 59, 30)
        })
        case_one.add_event({
            "concept:name": "",
            "time:timestamp": datetime(2015, 5, 10, 9, 1, 30)
        })

        expected_distances = [900, 300, 180, 360, 120]

        assert calculate_case_time_distances(case_one) == expected_distances
Ejemplo n.º 6
0
    def test_add_point(self, denstream: DenStream):
        case_list = []
        case_1 = Case("1")
        case_1.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case_1.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })
        case_1.add_event({
            "concept:name": "activityC",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
        })
        case_list.append(case_1)

        case_2 = Case("2")
        case_2.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case_2.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })
        case_list.append(case_2)

        graph = initialize_graph(case_list)

        case_3 = Case("3")
        case_3.add_event({
            "concept:name": "activityA",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
        })
        case_3.add_event({
            "concept:name": "activityB",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
        })
        case_3.add_event({
            "concept:name": "activityC",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
        })
        case_3.add_event({
            "concept:name": "activityD",
            "time:timestamp": datetime(2015, 5, 10, 8, 00, 30),
        })

        case_3.distances = calculate_case_distances(graph, case_3)

        micro_cluster = MicroCluster(10, 2, 0, 0.15)
        micro_cluster.cf1 = np.array([0.5, -0.5])
        micro_cluster.cf2 = np.array([0.5, -0.1])
        micro_cluster.weight = 10
        denstream.p_micro_clusters.append(micro_cluster)

        micro_cluster = MicroCluster(11, 2, 0, 0.15)
        micro_cluster.cf1 = np.array([0.0, 0.0])
        micro_cluster.cf2 = np.array([0.0, 0.0])
        micro_cluster.weight = 5
        denstream.o_micro_clusters.append(micro_cluster)
        denstream.mc_id = 2

        mc_id = denstream.add_point(case_3)
        assert mc_id == 2
        assert len(denstream.o_micro_clusters) == 2
        assert denstream.o_micro_clusters[1].radius == 0
        assert denstream.o_micro_clusters[1].weight == 1
        assert np.all(denstream.o_micro_clusters[1].cf1 == case_3.point)
        assert np.all(denstream.o_micro_clusters[1].cf2 == case_3.point *
                      case_3.point)

        cf = denstream.o_micro_clusters[1].cf1.copy()
        cf2 = denstream.o_micro_clusters[1].cf2.copy()
        mc_id = denstream.add_point(case_3)
        assert mc_id == 2
        assert len(denstream.o_micro_clusters) == 1
        assert len(denstream.p_micro_clusters) == 2
        assert denstream.p_micro_clusters[1].weight == 2
        assert np.all(denstream.p_micro_clusters[1].cf1 == cf + case_3.point)
        assert np.all(denstream.p_micro_clusters[1].cf2 == cf2 +
                      case_3.point * case_3.point)