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)
def simple_graph(self): case_list = [] case = Case("1") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), }) case_list.append(case) case = Case("2") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), }) case_list.append(case) case = Case("3") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), }) case.add_event({ "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 8, 00, 30), }) case_list.append(case) graph = initialize_graph(case_list) return graph
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"]
def test_check_point_update(self, process, cases_list): assert process.cp_count == 0 process.check_point_update() assert process.cp_count == 1 assert process.check_point_cases == 0 assert process.nyquist == 0 assert len(process.process_model_graph.edges) == 0 assert len(process.process_model_graph.nodes) == 0 process.nyquist = 1 process.check_point_update() assert process.cp_count == 2 assert process.nyquist == 1 assert process.check_point_cases == 0 assert len(process.process_model_graph.edges) == 0 assert len(process.process_model_graph.nodes) == 0 # self.cases > nyquist # nyquist = 0 # process_model_graph = 0 process.cases = cases_list process.check_point_cases = 1 process.nyquist = 0 with pytest.raises(Exception): assert process.check_point_update() # initialize_graph -> extract_cases_time_and_trace # Exception("Extracting trace and timestamp list out of a list with no cases") assert process.cp_count == 3 # even if error, cp_count incremented!!! # self.cases > nyquist # nyquist = 1 # process_model_graph = 0 case3 = cases_list[0] process.cases = cases_list process.check_point_cases = 1 process.nyquist = 1 process.check_point_update() assert process.cp_count == 4 assert process.cases == [case3] assert process.check_point_cases == 0 assert process.nyquist == 1 assert len(process.process_model_graph.edges) == 3 assert len(process.process_model_graph.nodes) == 4 check_point_graph = initialize_graph(process.cases) for node1, node2, _ in process.process_model_graph.edges.data(): assert (process.process_model_graph[node1][node2] == check_point_graph[node1][node2]) assert (process.process_model_graph[node1][node2]["weight"] == check_point_graph[node1][node2]["weight"]) assert (process.process_model_graph[node1][node2]["time"] == check_point_graph[node1][node2]["time"]) # self.cases > nyquist # nyquist = 1 # process_model_graph = 1 process.process_model_graph = initialize_graph([cases_list[2]]) pmg = process.process_model_graph assert pmg["activityA"]["activityB"] assert pmg["activityB"]["activityC"] with pytest.raises(Exception): assert pmg["activityC"]["activityD"] assert pmg["activityD"]["activityE"] case3 = cases_list[0] process.cases = cases_list process.check_point_cases = 1 process.nyquist = 1 process.check_point_update() assert process.cp_count == 5 assert process.cases == [case3] assert process.check_point_cases == 0 assert process.nyquist == 1 assert len(process.process_model_graph.edges) == 3 assert len(process.process_model_graph.nodes) == 4 assert pmg["activityA"]["activityB"] assert pmg["activityB"]["activityC"] assert pmg["activityC"]["activityD"] check_point_graph = initialize_graph(process.cases) for node1, node2, _ in process.process_model_graph.edges.data(): pmg[node1][node2]["weight"] *= 0.95 pmg[node1][node2]["weight"] += check_point_graph[node1][node2][ "weight"] pmg[node1][node2]["time"] += check_point_graph[node1][node2][ "time"] pmg = normalize_graph(pmg) assert (process.process_model_graph[node1][node2]["weight"] == pmg[node1][node2]["weight"]) assert ( process.process_model_graph[node1][node2]["weight_normalized"] == pmg[node1][node2]["weight_normalized"]) assert (process.process_model_graph[node1][node2]["time"] == pmg[node1][node2]["time"]) assert ( process.process_model_graph[node1][node2]["time_normalized"] == pmg[node1][node2]["time_normalized"]) # self.cases > nyquist # nyquist = 2 # process_model_graph = 1 case2 = cases_list[1] case3 = cases_list[0] process.process_model_graph = initialize_graph([cases_list[1]]) pmg = process.process_model_graph assert pmg["activityA"]["activityB"] with pytest.raises(Exception): assert pmg["activityC"]["activityD"] assert pmg["activityD"]["activityE"] process.cases = cases_list process.check_point_cases = 1 process.nyquist = 2 process.check_point_update() assert process.cp_count == 6 assert process.cases == [case3, case2] assert process.check_point_cases == 0 assert process.nyquist == 1 * 2 assert len(process.process_model_graph.edges) == 3 assert len(process.process_model_graph.nodes) == 4 assert process.process_model_graph["activityA"]["activityB"] assert process.process_model_graph["activityB"]["activityC"] assert process.process_model_graph["activityC"]["activityD"] check_point_graph = initialize_graph(process.cases) for node1, node2, _ in process.process_model_graph.edges.data(): pmg[node1][node2]["weight"] *= 0.95 pmg[node1][node2]["weight"] += check_point_graph[node1][node2][ "weight"] pmg[node1][node2]["time"] += check_point_graph[node1][node2][ "time"] pmg = normalize_graph(pmg) assert (process.process_model_graph[node1][node2]["weight"] == pmg[node1][node2]["weight"]) assert ( process.process_model_graph[node1][node2]["weight_normalized"] == pmg[node1][node2]["weight_normalized"]) assert (process.process_model_graph[node1][node2]["time"] == pmg[node1][node2]["time"]) assert ( process.process_model_graph[node1][node2]["time_normalized"] == pmg[node1][node2]["time_normalized"]) # self.cases > nyquist # nyquist = 2 # process_model_graph = 2 case2 = cases_list[1] case3 = cases_list[0] process.process_model_graph = initialize_graph( [cases_list[1], cases_list[2]]) pmg = process.process_model_graph assert pmg["activityA"]["activityB"] assert pmg["activityB"]["activityC"] with pytest.raises(Exception): assert pmg["activityC"]["activityD"] assert pmg["activityD"]["activityE"] process.cases = cases_list process.check_point_cases = 1 process.nyquist = 2 process.check_point_update() assert process.cp_count == 7 assert process.cases == [case3, case2] assert process.check_point_cases == 0 assert process.nyquist == 1 * 2 assert len(process.process_model_graph.edges) == 3 assert len(process.process_model_graph.nodes) == 4 assert process.process_model_graph["activityA"]["activityB"] assert process.process_model_graph["activityB"]["activityC"] assert process.process_model_graph["activityC"]["activityD"] check_point_graph = initialize_graph(process.cases) for node1, node2, _ in process.process_model_graph.edges.data(): pmg[node1][node2]["weight"] *= 0.95 pmg[node1][node2]["weight"] += check_point_graph[node1][node2][ "weight"] pmg[node1][node2]["time"] += check_point_graph[node1][node2][ "time"] pmg = normalize_graph(pmg) assert (process.process_model_graph[node1][node2]["weight"] == pmg[node1][node2]["weight"]) assert ( process.process_model_graph[node1][node2]["weight_normalized"] == pmg[node1][node2]["weight_normalized"]) assert (process.process_model_graph[node1][node2]["time"] == pmg[node1][node2]["time"]) assert ( process.process_model_graph[node1][node2]["time_normalized"] == pmg[node1][node2]["time_normalized"])
def test_train(self, denstream: DenStream): # anomalous_denstream = DenStream(2, 0.15, 0.3, 0.1, 4, 1000) cases_list = [] case = Case("5") case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), } ) case.add_event( { "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 8, 00, 30), } ) case.add_event( { "concept:name": "activityE", "time:timestamp": datetime(2015, 5, 10, 8, 00, 40), } ) cases_list.append(case) case = Case("3") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), } ) case.add_event( { "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 8, 00, 30), } ) cases_list.append(case) case = Case("1") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), } ) cases_list.append(case) case = Case("4") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), } ) cases_list.append(case) case = Case("2") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), } ) cases_list.append(case) pmg = initialize_graph(cases_list) for case in cases_list: case.distances = calculate_case_distances(pmg, case)
def test_dbscan(self, denstream: DenStream, cases_list): graph = initialize_graph(cases_list) for case in cases_list: case.distances = calculate_case_distances(graph, case)
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 )
def simple_graph_with_attributes(self): case_list = [] case = Case("1") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), "attribute_one": 10, "attribute_two": 5, "color": "red", } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), "attribute_one": 0, "attribute_two": 7, "color": "green", } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), "attribute_one": 2, "attribute_two": 4, "color": "green", } ) case_list.append(case) case = Case("2") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), "attribute_one": 3, "attribute_two": 10, "color": "blue", } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), "attribute_one": 6, "attribute_two": 2, "color": "green", } ) case_list.append(case) case = Case("3") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), "attribute_one": 8, "attribute_two": 4, "color": "red", } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 10), "attribute_one": 1, "attribute_two": 12, "color": "blue", } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), "attribute_one": 2, "attribute_two": 2, "color": "blue", } ) case.add_event( { "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 8, 00, 30), "attribute_one": 1, "attribute_two": 1, "color": "blue", } ) case_list.append(case) graph = initialize_graph(case_list, ["attribute_one", "attribute_two", "color"]) return graph
def test_calculate_case_distances(self): case_list = [] case = Case("1") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity D", "time:timestamp": datetime(2015, 5, 10, 8, 33, 20), } ) case.add_event( { "concept:name": "Activity E", "time:timestamp": datetime(2015, 5, 10, 14, 6, 40), } ) case_list.append(case) case = Case("2") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 1, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 14, 40, 00), } ) case.add_event( { "concept:name": "Activity D", "time:timestamp": datetime(2015, 5, 10, 15, 5, 00), } ) case_list.append(case) case = Case("3") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 13, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 13, 00), } ) case_list.append(case) case = Case("4") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), } ) case_list.append(case) case = Case("5") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case_list.append(case) case = Case("6") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 15, 30, 00), } ) case.add_event( { "concept:name": "Activity F", "time:timestamp": datetime(2015, 5, 10, 15, 30, 00), } ) case_list.append(case) case = Case("7") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity F", "time:timestamp": datetime(2015, 5, 11, 8, 00, 00), } ) case_list.append(case) case = Case("8") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity F", "time:timestamp": datetime(2015, 5, 10, 11, 46, 40), } ) case_list.append(case) case = Case("9") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity F", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case_list.append(case) case = Case("10") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity F", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case_list.append(case) case = Case("11") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case_list.append(case) graph = initialize_graph(case_list) case = Case("12") case.add_event( { "concept:name": "Activity A", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "Activity B", "time:timestamp": datetime(2015, 5, 10, 9, 18, 20), } ) case.add_event( { "concept:name": "Activity C", "time:timestamp": datetime(2015, 5, 10, 10, 8, 20), } ) distances = calculate_case_distances(graph, case) assert distances.get("graph") == pytest.approx(0.05) assert distances.get("time") == pytest.approx(-1.42, rel=1e-2)
def test_update(): case_list = [] micro_cluster = MicroCluster(0, 2, 0, 0.15) case = Case("1") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 8, 33, 20), } ) case.add_event( { "concept:name": "activityE", "time:timestamp": datetime(2015, 5, 10, 14, 6, 40), } ) case_list.append(case) case = Case("2") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 1, 00, 00), } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 14, 40, 00), } ) case.add_event( { "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 15, 5, 00), } ) case_list.append(case) graph = initialize_graph(case_list) case = Case("3") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 13, 00), } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 13, 00), } ) case.distances = calculate_case_distances(graph, case) cf = micro_cluster.cf1.copy() cf2 = micro_cluster.cf2.copy() weight = micro_cluster.weight micro_cluster.update(case) assert np.all(micro_cluster.cf1 == cf + case.point) assert np.all(micro_cluster.cf2 == cf2 + case.point * case.point) assert micro_cluster.weight == weight + 1 case = case_list[0] case.distances = calculate_case_distances(graph, case) cf = micro_cluster.cf1.copy() cf2 = micro_cluster.cf2.copy() weight = micro_cluster.weight micro_cluster.update(case) assert np.all(micro_cluster.cf1 == cf + case.point) assert np.all(micro_cluster.cf2 == cf2 + case.point * case.point) assert micro_cluster.weight == weight + 1
def complex_graph(self): case_list = [] case = Case("1") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 8, 33, 20), }) case.add_event({ "concept:name": "activityE", "time:timestamp": datetime(2015, 5, 10, 14, 6, 40), }) case_list.append(case) case = Case("2") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 1, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 14, 40, 00), }) case.add_event({ "concept:name": "activityD", "time:timestamp": datetime(2015, 5, 10, 15, 5, 00), }) case_list.append(case) case = Case("3") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 13, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 13, 00), }) case_list.append(case) case = Case("4") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 20), }) case_list.append(case) case = Case("5") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case_list.append(case) case = Case("6") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 15, 30, 00), }) case.add_event({ "concept:name": "activityF", "time:timestamp": datetime(2015, 5, 10, 15, 30, 00), }) case_list.append(case) case = Case("7") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityF", "time:timestamp": datetime(2015, 5, 11, 8, 00, 00), }) case_list.append(case) case = Case("8") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityF", "time:timestamp": datetime(2015, 5, 10, 11, 46, 40), }) case_list.append(case) case = Case("9") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityF", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case_list.append(case) case = Case("10") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityF", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case_list.append(case) case = Case("11") case.add_event({ "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case.add_event({ "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), }) case_list.append(case) graph = initialize_graph(case_list) return graph