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]
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_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 test_generate_outlier_clusters(self, denstream): assert denstream.generate_outlier_clusters() == [] case_0 = Case("0") case_1 = Case("1") case_2 = Case("2") case_3 = Case("3") micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.weight = 3 denstream.o_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.weight = 4 denstream.o_micro_clusters.append(micro_cluster) denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(3, 2, 0, 0.15) micro_cluster.weight = 6 denstream.o_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id assert denstream.all_cases == {"0": 0, "1": 1, "2": 3, "3": 3} cluster_list = denstream.generate_outlier_clusters() cluster = cluster_list[0] assert cluster.id == 0 assert np.all(cluster.centroid == [0, 0]) assert cluster.radius == 0 assert cluster.weight == 3 assert cluster.case_ids == ["0"] cluster = cluster_list[1] assert cluster.id == 1 assert np.all(cluster.centroid == [0, 0]) assert cluster.radius == 0 assert cluster.weight == 4 assert cluster.case_ids == ["1"] cluster = cluster_list[2] assert cluster.id == 3 assert np.all(cluster.centroid == [0, 0]) assert cluster.radius == 0 assert cluster.weight == 6 assert cluster.case_ids == ["2", "3"]
def test_get_case(self, process): case1 = Case("1") case2 = Case("2") case3 = Case("3") case4 = Case("4") process.cases = [case1, case2, case3, case4] case = process.get_case_index("1") assert case == 0 case = process.get_case_index("3") assert case == 2 process.cases = [case4, case1, case3, case2] case = process.get_case_index("1") assert case == 1 case = process.get_case_index("2") assert case == 3 case = process.get_case_index("5") assert case is None
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)
assert denstream.no_processed_points == 5 assert len(denstream.o_micro_clusters) == 1 assert len(denstream.p_micro_clusters) == 1 assert denstream.p_micro_clusters[0].id == 0 assert np.all(denstream.p_micro_clusters[0].cf1 == [0.75, 0]) assert np.all(denstream.p_micro_clusters[0].cf2 == [0.125, 0]) assert denstream.p_micro_clusters[0].weight == 6 assert denstream.o_micro_clusters[0].id == 1 assert np.all(denstream.o_micro_clusters[0].cf1 == [(5 / 8), 0]) assert np.all(denstream.o_micro_clusters[0].cf2 == [(5 / 8) ** 2, 0]) assert denstream.o_micro_clusters[0].weight == 1 assert denstream.o_micro_clusters[0].creation_time == 0 case = Case("6") case.add_event( { "concept:name": "activityE", "time:timestamp": datetime(2015, 5, 10, 8, 00, 40), } ) case.add_event( { "concept:name": "activityF", "time:timestamp": datetime(2015, 5, 10, 8, 00, 50), } ) case.distances = calculate_case_distances(pmg, case) cases_list.insert(0, case)
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]
def test_generate_clusters(self, denstream): assert len(denstream.p_micro_clusters) == 0 dense_group, not_dense_group = denstream.generate_clusters() assert dense_group == [[]] assert not_dense_group == [[]] case_0 = Case("0") case_1 = Case("1") micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([5.0, 5.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 5 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id assert len(denstream.p_micro_clusters) == 1 assert micro_cluster.weight >= denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert not dense_group == [[]] assert not_dense_group == [[]] cluster_list = dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 5 assert cluster.case_ids == ["0", "1"] micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([3.0, 3.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 3 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id assert len(denstream.p_micro_clusters) == 1 assert micro_cluster.weight < denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert dense_group == [[]] assert not not_dense_group == [[]] cluster_list = not_dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 3 assert cluster.case_ids == ["0", "1"] case_2 = Case("2") case_3 = Case("3") micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([3.0, 3.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 3 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.cf1 = np.array([4.0, 4.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 4 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id cl1 = denstream.p_micro_clusters[0] cl2 = denstream.p_micro_clusters[1] assert len(denstream.p_micro_clusters) > 1 assert ( denstream.euclidean_distance(cl1.centroid, cl2.centroid) <= 2 * denstream.epsilon ) assert cl1.weight + cl2.weight >= denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert not dense_group == [[]] assert not_dense_group == [[]] cluster_list = dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 3 assert cluster.case_ids == ["0", "1"] cluster = cluster_list[1] assert isinstance(cluster, Cluster) assert cluster.id == 1 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 4 assert cluster.case_ids == ["2", "3"] with pytest.raises(IndexError): assert dense_group[1] assert cluster_list[2] micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([3.0, 3.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 1 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.cf1 = np.array([3.0, 3.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 1 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id cl1 = denstream.p_micro_clusters[0] cl2 = denstream.p_micro_clusters[1] assert len(denstream.p_micro_clusters) > 1 assert ( denstream.euclidean_distance(cl1.centroid, cl2.centroid) <= 2 * denstream.epsilon ) assert cl1.weight + cl2.weight < denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert dense_group == [[]] assert not not_dense_group == [[]] cluster_list = not_dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [3, 3]) assert cluster.radius == 0 assert cluster.weight == 1 assert cluster.case_ids == ["0", "1"] cluster = cluster_list[1] assert isinstance(cluster, Cluster) assert cluster.id == 1 assert np.all(cluster.centroid == [3, 3]) assert cluster.radius == 0 assert cluster.weight == 1 assert cluster.case_ids == ["2", "3"] with pytest.raises(IndexError): assert not_dense_group[1] assert cluster_list[2] micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([3.0, 3.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 3 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.cf1 = np.array([1.0, 1.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 4 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id cl1 = denstream.p_micro_clusters[0] cl2 = denstream.p_micro_clusters[1] assert len(denstream.p_micro_clusters) > 1 assert ( denstream.euclidean_distance(cl1.centroid, cl2.centroid) > 2 * denstream.epsilon ) assert cl1.weight < denstream.mu assert cl2.weight >= denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert not dense_group == [[]] assert not not_dense_group == [[]] cluster_list = not_dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 3 assert cluster.case_ids == ["0", "1"] with pytest.raises(IndexError): assert cluster_list[1] cluster_list = dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 1 assert np.all(cluster.centroid == [0.25, 0.25]) assert cluster.radius == cl2.radius assert cluster.weight == 4 assert cluster.case_ids == ["2", "3"] with pytest.raises(IndexError): assert not_dense_group[1] assert dense_group[1] assert cluster_list[1] micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([6.0, 6.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 6 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.cf1 = np.array([1.0, 1.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 2 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id cl1 = denstream.p_micro_clusters[0] cl2 = denstream.p_micro_clusters[1] assert len(denstream.p_micro_clusters) > 1 assert ( denstream.euclidean_distance(cl1.centroid, cl2.centroid) > 2 * denstream.epsilon ) assert cl1.weight >= denstream.mu assert cl2.weight < denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert not dense_group == [[]] assert not not_dense_group == [[]] cluster_list = dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 6 assert cluster.case_ids == ["0", "1"] with pytest.raises(IndexError): assert cluster_list[1] cluster_list = not_dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 1 assert np.all(cluster.centroid == [0.5, 0.5]) assert cluster.radius == cl2.radius assert cluster.weight == 2 assert cluster.case_ids == ["2", "3"] with pytest.raises(IndexError): assert not_dense_group[1] assert dense_group[1] assert cluster_list[1] micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([6.0, 6.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 6 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.cf1 = np.array([1.0, 1.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 4 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id cl1 = denstream.p_micro_clusters[0] cl2 = denstream.p_micro_clusters[1] assert len(denstream.p_micro_clusters) > 1 assert ( denstream.euclidean_distance(cl1.centroid, cl2.centroid) > 2 * denstream.epsilon ) assert cl1.weight >= denstream.mu assert cl2.weight >= denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert not dense_group == [[]] assert not_dense_group == [[]] cluster_list = dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [1, 1]) assert cluster.radius == 0 assert cluster.weight == 6 assert cluster.case_ids == ["0", "1"] with pytest.raises(IndexError): assert cluster_list[1] cluster_list = dense_group[1] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 1 assert np.all(cluster.centroid == [0.25, 0.25]) assert cluster.radius == cl2.radius assert cluster.weight == 4 assert cluster.case_ids == ["2", "3"] with pytest.raises(IndexError): assert dense_group[2] assert cluster_list[1] micro_cluster = MicroCluster(0, 2, 0, 0.15) micro_cluster.cf1 = np.array([1.0, 1.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 3 denstream.p_micro_clusters = [] denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_0.id] = micro_cluster.id denstream.all_cases[case_1.id] = micro_cluster.id micro_cluster = MicroCluster(1, 2, 0, 0.15) micro_cluster.cf1 = np.array([1.0, 1.0]) micro_cluster.cf2 = np.array([1.0, 1.0]) micro_cluster.weight = 2 denstream.p_micro_clusters.append(micro_cluster) denstream.all_cases[case_2.id] = micro_cluster.id denstream.all_cases[case_3.id] = micro_cluster.id cl1 = denstream.p_micro_clusters[0] cl2 = denstream.p_micro_clusters[1] assert len(denstream.p_micro_clusters) > 1 assert ( denstream.euclidean_distance(cl1.centroid, cl2.centroid) > 2 * denstream.epsilon ) assert cl1.weight < denstream.mu assert cl2.weight < denstream.mu dense_group, not_dense_group = denstream.generate_clusters() assert dense_group == [[]] assert not not_dense_group == [[]] cluster_list = not_dense_group[0] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 0 assert np.all(cluster.centroid == [(1 / 3), (1 / 3)]) assert cluster.radius == cl1.radius assert cluster.weight == 3 assert cluster.case_ids == ["0", "1"] with pytest.raises(IndexError): assert cluster_list[1] cluster_list = not_dense_group[1] cluster = cluster_list[0] assert isinstance(cluster, Cluster) assert cluster.id == 1 assert np.all(cluster.centroid == [0.5, 0.5]) assert cluster.radius == cl2.radius assert cluster.weight == 2 assert cluster.case_ids == ["2", "3"] with pytest.raises(IndexError): assert not_dense_group[2] assert cluster_list[1]
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 cases_list(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) 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), } ) case_list.append(case) return case_list
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 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 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
class TestCalculateCaseDistances: @pytest.fixture 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_calculate_case_distances_with_attributes( self, simple_graph_with_attributes: nx.DiGraph, ): case = Case("4") case.add_event( { "concept:name": "activityA", "time:timestamp": datetime(2015, 5, 10, 8, 00, 00), "attribute_one": 9, "attribute_two": 6, "color": "red", } ) case.add_event( { "concept:name": "activityB", "time:timestamp": datetime(2015, 5, 10, 9, 18, 20), "attribute_one": 5, "attribute_two": 10, "color": "red", } ) case.add_event( { "concept:name": "activityC", "time:timestamp": datetime(2015, 5, 10, 10, 8, 20), "attribute_one": 2, "attribute_two": 2, "color": "green", } ) distances = calculate_case_distances( simple_graph_with_attributes, case, additional_attributes=["attribute_one", "attribute_two", "color"], ) assert distances.get("attribute_one") == pytest.approx(0.4121, rel=1e-2) assert distances.get("attribute_two") == pytest.approx(0.2651, rel=1e-2) assert distances.get("color") == pytest.approx(0.6111, rel=1e-2)
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 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]
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