This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
discovery_test.py
185 lines (174 loc) · 6.66 KB
/
discovery_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import pandas as pd
from prioritization_discovery.config import DEFAULT_CSV_IDS
from prioritization_discovery.discovery import _discover_prioritized_instances, _split_to_individual_observations, discover_priority_rules
def test_discover_prioritized_instances():
# Read event log
event_log = pd.read_csv("./tests/assets/event_log_1.csv")
event_log[DEFAULT_CSV_IDS.enabled_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.enabled_time], utc=True)
event_log[DEFAULT_CSV_IDS.start_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.start_time], utc=True)
event_log[DEFAULT_CSV_IDS.end_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.end_time], utc=True)
# Discover prioritization
attributes = [DEFAULT_CSV_IDS.activity]
prioritizations = _discover_prioritized_instances(event_log, attributes)
prioritizations.sort_values(['Activity'], inplace=True)
assert prioritizations.equals(
pd.DataFrame(
data=[
['B', 0], ['B', 0], ['B', 0],
['B', 0], ['B', 0], ['B', 0],
['C', 1], ['C', 1], ['C', 1],
['C', 1], ['C', 1], ['C', 1]
],
index=[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5],
columns=['Activity', 'outcome']
)
)
def test_discover_prioritized_instances_with_extra_attribute():
# Read event log
event_log = pd.read_csv("./tests/assets/event_log_2.csv")
event_log[DEFAULT_CSV_IDS.enabled_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.enabled_time], utc=True)
event_log[DEFAULT_CSV_IDS.start_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.start_time], utc=True)
event_log[DEFAULT_CSV_IDS.end_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.end_time], utc=True)
# Discover prioritization
attributes = [DEFAULT_CSV_IDS.activity, 'loan_amount']
prioritizations = _discover_prioritized_instances(event_log, attributes)
prioritizations.sort_values(['Activity', 'loan_amount', 'outcome'], inplace=True)
assert prioritizations.equals(
pd.DataFrame(
data=[
['A', 500, 0],
['A', 500, 0],
['A', 500, 1],
['B', 100, 0],
['B', 100, 0],
['B', 100, 0],
['B', 100, 0],
['B', 100, 0],
['B', 500, 1],
['B', 1000, 1],
['B', 1000, 1],
['C', 100, 0],
['C', 500, 1],
['C', 500, 1],
['C', 1000, 1],
['C', 1000, 1]
],
index=[0, 1, 2, 2, 3, 4, 5, 6, 4, 0, 3, 7, 6, 7, 1, 5],
columns=['Activity', 'loan_amount', 'outcome']
)
)
def test__split_to_individual_observations():
# Create simple prioritizations with only the activity
prioritizations = pd.DataFrame(
[["B", "C"], ["B", "C"], ["B", "C"], ["B", "C"], ["B", "C"], ["B", "C"]],
columns=['delayed_Activity', 'prioritized_Activity']
)
# Split the prioritizations to the individual delayed/prioritized instances
prioritized_instances = _split_to_individual_observations(
prioritizations,
['delayed_Activity'],
['prioritized_Activity'],
'outcome'
)
# Assert that the split was done correctly, even maintaining the indexes
assert prioritized_instances.equals(
pd.DataFrame(
data=[
['B', 0], ['B', 0], ['B', 0],
['B', 0], ['B', 0], ['B', 0],
['C', 1], ['C', 1], ['C', 1],
['C', 1], ['C', 1], ['C', 1]
],
index=[0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5],
columns=['Activity', 'outcome']
)
)
def test__split_to_individual_observations_with_extra_attribute():
# Create simple prioritizations with only the activity
prioritizations = pd.DataFrame(
[
['A', 500, 'B', 1000],
['A', 500, 'C', 1000],
['B', 100, 'A', 500],
['B', 100, 'B', 500],
['B', 100, 'B', 1000],
['B', 100, 'C', 500],
['B', 100, 'C', 1000],
['C', 100, 'C', 500]
],
columns=[
'delayed_Activity',
'delayed_loan_amount',
'prioritized_Activity',
'prioritized_loan_amount'
]
)
# Split the prioritizations to the individual delayed/prioritized instances
prioritized_instances = _split_to_individual_observations(
prioritizations,
['delayed_Activity', 'delayed_loan_amount'],
['prioritized_Activity', 'prioritized_loan_amount'],
'outcome'
)
# Assert that the split was done correctly, even maintaining the indexes
assert prioritized_instances.equals(
pd.DataFrame(
data=[
['A', 500, 0],
['A', 500, 0],
['B', 100, 0],
['B', 100, 0],
['B', 100, 0],
['B', 100, 0],
['B', 100, 0],
['C', 100, 0],
['B', 1000, 1],
['C', 1000, 1],
['A', 500, 1],
['B', 500, 1],
['B', 1000, 1],
['C', 500, 1],
['C', 1000, 1],
['C', 500, 1]
],
index=[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7],
columns=['Activity', 'loan_amount', 'outcome']
)
)
def test_discover_priority_rules_naive():
# Read event log
event_log = pd.read_csv("./tests/assets/event_log_3.csv")
event_log[DEFAULT_CSV_IDS.enabled_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.enabled_time], utc=True)
event_log[DEFAULT_CSV_IDS.start_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.start_time], utc=True)
event_log[DEFAULT_CSV_IDS.end_time] = pd.to_datetime(event_log[DEFAULT_CSV_IDS.end_time], utc=True)
# Discover prioritization
attributes = ['urgency']
# Get priority levels and their rules
prioritization_levels = discover_priority_rules(event_log, attributes)
# Assert expected levels and rules
assert prioritization_levels == [
{
'priority_level': 0,
'rules': [
[
{
'attribute': 'urgency',
'condition': '=',
'value': 'high'
}
]
]
},
{
'priority_level': 1,
'rules': [
[
{
'attribute': 'urgency',
'condition': '=',
'value': 'medium'
}
]
]
}
]