Beispiel #1
0
def test_pipeline():
    event_stream_test = read_csv(f"demo/sudden_trace_noise20_500_cb.csv")
    cdesf = CDESF(
        name="sudden_trace_noise20_500_cb",
        time_horizon=259200,
        lambda_=0.05,
        beta=0.2,
        epsilon=0.6,
        mu=4,
        stream_speed=100,
        gen_metrics=True,
        gen_plot=False,
    )
    cdesf.run(event_stream_test)
Beispiel #2
0
def test_attributed_pipeline():
    event_stream_test = read_csv(
        f"demo/sudden_trace_noise20_500_cb_attributed.csv")
    cdesf = CDESF(
        name="sudden_trace_noise20_500_cb_attributed",
        time_horizon=259200,
        lambda_=0.05,
        beta=0.2,
        epsilon=0.6,
        mu=4,
        stream_speed=100,
        gen_metrics=True,
        gen_plot=False,
        additional_attributes=["first", "second", "country"],
    )
    cdesf.run(event_stream_test)
Beispiel #3
0
def test_pipeline():
    path = 'demo'
    filename = 'sudden_trace_noise20_500_cb.csv'

    event_stream_test = read_csv(f'{path}/{filename}')
    cdesf = CDESF(name='sudden_trace_noise20_500_cb',
                  time_horizon=259200,
                  lambda_=0.05,
                  beta=0.2,
                  epsilon=0.6,
                  mu=4,
                  stream_speed=100,
                  n_features=2,
                  gen_metrics=True,
                  gen_plot=False)
    cdesf.run(event_stream_test)
Beispiel #4
0
    def test_initialize_case_metrics(self, process: CDESF,
                                     cases_list: "list[Case]"):
        process.initialize_case_metrics()
        assert process.cases == []

        process.cases = cases_list

        case_3 = process.cases[0]
        assert case_3.distances.get("graph") is None
        assert case_3.distances.get("graph") is None
        case_2 = process.cases[1]
        assert case_2.distances.get("graph") is None
        assert case_2.distances.get("graph") is None
        case_1 = process.cases[2]
        assert case_1.distances.get("graph") is None
        assert case_1.distances.get("graph") is None

        process.initialize_case_metrics()

        case_3 = process.cases[0]
        assert case_3.distances["graph"] == 0
        assert case_3.distances["time"] == 0
        case_2 = process.cases[1]
        assert case_2.distances["graph"] == 0
        assert case_2.distances["time"] == 0
        case_1 = process.cases[2]
        assert case_1.distances["graph"] == 0
        assert case_1.distances["time"] == 0

        process.cases = cases_list
        process.process_model_graph = initialize_graph(process.cases)
        process.initialize_case_metrics()
        case_3 = process.cases[0]

        # Verify that the distances are applied.
        distances_for_case_3 = calculate_case_distances(
            process.process_model_graph, case_3)
        assert case_3.distances["graph"] == distances_for_case_3["graph"]
        assert case_3.distances["time"] == distances_for_case_3["time"]

        distances_for_case_2 = calculate_case_distances(
            process.process_model_graph, case_2)
        case_2 = process.cases[1]
        assert case_2.distances["graph"] == distances_for_case_2["graph"]
        assert case_2.distances["time"] == distances_for_case_2["time"]

        distances_for_case_1 = calculate_case_distances(
            process.process_model_graph, case_1)
        case_1 = process.cases[2]
        assert case_1.distances["graph"] == distances_for_case_1["graph"]
        assert case_1.distances["time"] == distances_for_case_1["time"]
Beispiel #5
0
 def process(self):
     process = CDESF(name='test',
                     time_horizon=43200,
                     lambda_=0.15,
                     beta=0.3,
                     epsilon=0.1,
                     mu=4,
                     stream_speed=1000,
                     n_features=2,
                     gen_plot=False,
                     gen_metrics=False)
     return process
Beispiel #6
0
    def test_set_case(self, process: CDESF):
        assert process.check_point_cases == 0
        assert process.cases == []
        process.set_case(
            "5",
            {
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
            },
        )
        assert process.check_point_cases == 1
        assert process.cases
        case_test = process.cases[0]
        assert case_test.id == "5"
        assert case_test.events[0].get("concept:name") == "activityA"
        assert case_test.events[0].get("time:timestamp") == datetime(
            2015, 5, 10, 8, 00, 00)

        case1 = Case("1")
        case2 = Case("2")
        case3 = Case("3")
        case4 = Case("4")
        process.check_point_cases = 0
        process.cases = [case1, case2, case3, case4]
        process.set_case(
            "3",
            {
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
            },
        )
        assert process.check_point_cases == 0
        assert process.cases
        case_test = process.cases[0]
        assert case_test.id == "3"
        assert case_test.events[0].get("concept:name") == "activityA"
        assert case_test.events[0].get("time:timestamp") == datetime(
            2015, 5, 10, 8, 00, 00)
Beispiel #7
0
    def test_process_event(self, process: CDESF):
        process.gen_metrics = True
        assert process.event_index == 0
        assert process.cases == []
        assert process.check_point == datetime(2010, 1, 1)
        process.check_point = datetime(2015, 5, 10, 8, 22, 53)

        process.process_event(
            {
                "case:concept:name": "1",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
            }, )
        assert process.event_index == 0
        assert process.total_cases == {"1"}

        assert process.check_point_cases == 1
        assert process.cases
        case_test = process.cases[0]
        assert case_test.id == "1"
        event = case_test.events[0]
        assert event.get("concept:name") == "activityA"
        assert event.get("time:timestamp") == datetime(2015, 5, 10, 8, 00, 00)
        assert process.check_point == datetime(2015, 5, 10, 8, 22, 53)
        assert not process.initialized

        process.process_event(
            {
                "case:concept:name": "2",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
            }, )
        process.process_event(
            {
                "case:concept:name": "1",
                "concept:name": "activityB",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
            }, )
        process.process_event(
            {
                "case:concept:name": "3",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
            }, )
        process.process_event(
            {
                "case:concept:name": "3",
                "concept:name": "activityB",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 10),
            }, )
        process.process_event(
            {
                "case:concept:name": "4",
                "concept:name": "activityC",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
            }, )
        process.process_event(
            {
                "case:concept:name": "3",
                "concept:name": "activityC",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 20),
            }, )
        process.process_event(
            {
                "case:concept:name": "4",
                "concept:name": "activityD",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 30),
            }, )
        process.process_event(
            {
                "case:concept:name": "5",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 00),
            }, )
        process.process_event(
            {
                "case:concept:name": "5",
                "concept:name": "activityD",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 30),
            }, )

        assert process.check_point_cases == 5
        assert process.total_cases == {"1", "2", "3", "4", "5"}
        assert process.cases
        assert len(process.cases) == 5
        case_test = process.cases[0]
        assert case_test.id == "5"
        event = case_test.events[0]
        assert event.get("concept:name") == "activityA"
        assert event.get("time:timestamp") == datetime(2015, 5, 10, 8, 00, 00)
        event = case_test.events[1]
        assert event.get("concept:name") == "activityD"
        assert event.get("time:timestamp") == datetime(2015, 5, 10, 8, 00, 30)
        assert process.check_point == datetime(2015, 5, 10, 8, 22, 53)
        assert not process.initialized

        process.process_event(
            {
                "case:concept:name": "4",
                "concept:name": "activityE",
                "time:timestamp": datetime(2015, 5, 10, 8, 00, 40),
            }, )
        assert process.check_point == datetime(2015, 5, 10, 8, 22, 53)
        assert process.check_point_cases == 5
        assert not process.initialized

        process.process_event(
            {
                "case:concept:name": "4",
                "concept:name": "activityE",
                "time:timestamp": datetime(2015, 5, 10, 21, 00, 40),
            }, )
        assert process.initialized
        assert process.check_point_cases == 5
        assert process.check_point == datetime(2015, 5, 10, 21, 00, 40)
        assert len(process.process_model_graph.nodes) == 5
        # print(list(process.process_model_graph.edges(data=True)))
        assert len(process.process_model_graph.edges) == 6
        # assert len(process.denstream.p_micro_clusters) == 2
        assert len(process.denstream.o_micro_clusters) == 0
        assert process.nyquist == 10

        process.process_event(
            {
                "case:concept:name": "1",
                "concept:name": "activityC",
                "time:timestamp": datetime(2015, 5, 10, 21, 00, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "1",
                "concept:name": "activityD",
                "time:timestamp": datetime(2015, 5, 10, 21, 50, 50),
            }, )
        assert process.check_point_cases == 5
        assert process.total_cases == {"1", "2", "3", "4", "5"}
        assert process.denstream.all_cases.keys() == {"1", "2", "3", "4", "5"}
        assert process.check_point == datetime(2015, 5, 10, 21, 00, 40)
        assert len(process.process_model_graph.nodes) == 5
        assert len(process.process_model_graph.edges) == 6
        # assert len(process.denstream.p_micro_clusters) == 2
        # assert len(process.denstream.o_micro_clusters) == 2
        assert process.nyquist == 10

        process.process_event(
            {
                "case:concept:name": "1",
                "concept:name": "activityE",
                "time:timestamp": datetime(2015, 5, 10, 21, 50, 50),
            }, )
        assert process.check_point == datetime(2015, 5, 10, 21, 00, 40)
        assert process.check_point_cases == 5
        assert process.total_cases == {"1", "2", "3", "4", "5"}
        assert process.denstream.all_cases.keys() == {"1", "2", "3", "4", "5"}
        assert process.check_point == datetime(2015, 5, 10, 21, 00, 40)
        assert len(process.process_model_graph.nodes) == 5
        assert len(process.process_model_graph.edges) == 6
        # assert len(process.denstream.p_micro_clusters) == 3
        # assert len(process.denstream.o_micro_clusters) == 1
        assert process.nyquist == 10

        process.process_event(
            {
                "case:concept:name": "6",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 11, 10, 50, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "7",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 11, 10, 50, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "8",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 11, 10, 50, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "9",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 11, 10, 50, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "10",
                "concept:name": "activityA",
                "time:timestamp": datetime(2015, 5, 11, 10, 50, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "2",
                "concept:name": "activityB",
                "time:timestamp": datetime(2015, 5, 12, 22, 50, 50),
            }, )
        process.process_event(
            {
                "case:concept:name": "2",
                "concept:name": "activityB",
                "time:timestamp": datetime(2015, 5, 13, 22, 50, 50),
            }, )

        assert process.cp_count == 1
        assert path.isfile(
            f"output/metrics/{process.name}_process_model_graphs/process_model_graph_{process.cp_count}.json"
        )

        assert process.check_point_cases == 0
        assert process.check_point == datetime(2015, 5, 13, 22, 50, 50)
        assert len(process.process_model_graph.nodes) == 5
        assert len(process.process_model_graph.edges) == 6
        # assert len(process.denstream.p_micro_clusters) == 4
        # assert len(process.denstream.o_micro_clusters) == 1
        assert process.total_cases == {
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "10",
        }
        assert process.denstream.all_cases.keys() == {"1", "2", "3", "4", "5"}
        assert process.nyquist == 10
        assert len(process.cases) == 10

        process.process_event(
            {
                "case:concept:name": "11",
                "concept:name": "activityB",
                "time:timestamp": datetime(2015, 5, 13, 23, 00, 00),
            }, )
        assert len(process.cases) == 11
        assert process.total_cases == {
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "10",
            "11",
        }
        assert process.denstream.all_cases.keys() == {"1", "2", "3", "4", "5"}
        assert process.nyquist == 10
        process.process_event(
            {
                "case:concept:name": "11",
                "concept:name": "activityC",
                "time:timestamp": datetime(2015, 5, 14, 12, 00, 00),
            }, )

        assert process.cp_count == 2
        assert path.isfile(
            f"output/metrics/{process.name}_process_model_graphs/process_model_graph_{process.cp_count}.json"
        )

        assert len(process.cases) == 10
        assert process.total_cases == {
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "10",
            "11",
        }
        assert process.denstream.all_cases.keys() == {
            "1", "2", "3", "4", "5", "11"
        }
        assert process.nyquist == 10

        process.process_event(
            {
                "case:concept:name": "11",
                "concept:name": "activityE",
                "time:timestamp": datetime(2015, 5, 15, 1, 00, 00),
            }, )
        assert process.cp_count == 3
        assert path.isfile(
            f"output/metrics/{process.name}_process_model_graphs/process_model_graph_{process.cp_count}.json"
        )

        assert len(process.cases) == 10
        assert process.cases[0].id == "11"
        assert process.cases[1].id == "2"
        assert process.total_cases == {
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9",
            "10",
            "11",
        }
        assert process.denstream.all_cases.keys() == {
            "1", "2", "3", "4", "5", "11"
        }
        assert process.nyquist == 10

        assert len(process.process_model_graph.nodes) == 5
        assert len(process.process_model_graph.edges) == 7