utility

  • Prefix: class to handle the prefix shared by events within traces.
  • Buffer: class to handle the features of a single event required for predictive models.
  1"""
  2* Prefix: Class to handle the prefix shared by events within traces.
  3* Buffer: Class to handle the features of a single event required for predictive models.
  4"""
  5
  6import os
  7
  8
  9def define_folder_output(directory):
 10    if not os.path.exists(directory):
 11        os.makedirs(directory)
 12
 13
 14class ParallelObject(object):
 15
 16    def __init__(self):
 17        self._am_parallel = []
 18
 19    def _set_last_events(self, am):
 20        for token in am:
 21            self._am_parallel.append(token)
 22
 23    def _get_last_events(self):
 24        tokens = set(self._am_parallel)
 25        self._am_parallel = []
 26        return tokens
 27
 28    def _update_last_events(self):
 29        self._am_parallel = []
 30
 31
 32class Prefix(object):
 33
 34    def __init__(self):
 35        self._list_activities = list()
 36
 37    def add_activity(self, activity):
 38        self._list_activities.append(activity)
 39
 40    def get_prefix(self, time):
 41        return self._list_activities
 42
 43
 44class Buffer(object):
 45
 46    def __init__(self, writer, values=None):
 47        self.buffer = {
 48            "id_case": -1,
 49            "activity": None,
 50            "enabled_time": None,
 51            "start_time": None,
 52            "end_time": None,
 53            "role": None,
 54            "resource": None,
 55            "wip_wait": -1,
 56            "wip_start": -1,
 57            "wip_end": -1,
 58            "wip_activity": -1,
 59            "ro_total": [],
 60            "ro_single": -1,
 61            "queue": -1,
 62            "prefix": Prefix,
 63            "attribute_case": dict(),
 64            "attribute_event": dict()
 65        }
 66        if values:
 67            self._decopy_value(values)
 68        self.writer = writer
 69
 70    def _decopy_value(self, values):
 71        for key in values:
 72            self.buffer[key] = values[key]
 73
 74    def _get_dictionary(self):
 75        return self.buffer
 76
 77    def set_feature(self, feature, value):
 78        if isinstance(self.buffer[feature], list):
 79            self.buffer[feature] = value
 80        else:
 81            self.buffer[feature] = value
 82
 83    def get_feature(self, feature):
 84        return self.buffer[feature]
 85
 86    def print_values(self):
 87        print(*self.buffer.values())
 88        self.writer.writerow(self.buffer.values())
 89
 90    def get_buffer_keys(self):
 91        return self.buffer.keys()
 92
 93    def reset(self):
 94        self.buffer["enabled_time"] = None
 95        self.buffer["start_time"] = None
 96        self.buffer["end_time"] = None
 97        self.buffer["resource"] = None
 98        self.buffer["wip_wait"] = -1
 99        self.buffer["wip_start"] = -1
100        self.buffer["wip_end"] = -1
101        self.buffer["wip_activity"] = -1
102        self.buffer["ro_total"] = []
103        self.buffer["ro_single"] = -1
104        self.buffer["queue"] = -1
105        self.buffer["attribute_event"] = dict()
def define_folder_output(directory):
10def define_folder_output(directory):
11    if not os.path.exists(directory):
12        os.makedirs(directory)
class ParallelObject:
15class ParallelObject(object):
16
17    def __init__(self):
18        self._am_parallel = []
19
20    def _set_last_events(self, am):
21        for token in am:
22            self._am_parallel.append(token)
23
24    def _get_last_events(self):
25        tokens = set(self._am_parallel)
26        self._am_parallel = []
27        return tokens
28
29    def _update_last_events(self):
30        self._am_parallel = []
class Prefix:
33class Prefix(object):
34
35    def __init__(self):
36        self._list_activities = list()
37
38    def add_activity(self, activity):
39        self._list_activities.append(activity)
40
41    def get_prefix(self, time):
42        return self._list_activities
def add_activity(self, activity):
38    def add_activity(self, activity):
39        self._list_activities.append(activity)
def get_prefix(self, time):
41    def get_prefix(self, time):
42        return self._list_activities
class Buffer:
 45class Buffer(object):
 46
 47    def __init__(self, writer, values=None):
 48        self.buffer = {
 49            "id_case": -1,
 50            "activity": None,
 51            "enabled_time": None,
 52            "start_time": None,
 53            "end_time": None,
 54            "role": None,
 55            "resource": None,
 56            "wip_wait": -1,
 57            "wip_start": -1,
 58            "wip_end": -1,
 59            "wip_activity": -1,
 60            "ro_total": [],
 61            "ro_single": -1,
 62            "queue": -1,
 63            "prefix": Prefix,
 64            "attribute_case": dict(),
 65            "attribute_event": dict()
 66        }
 67        if values:
 68            self._decopy_value(values)
 69        self.writer = writer
 70
 71    def _decopy_value(self, values):
 72        for key in values:
 73            self.buffer[key] = values[key]
 74
 75    def _get_dictionary(self):
 76        return self.buffer
 77
 78    def set_feature(self, feature, value):
 79        if isinstance(self.buffer[feature], list):
 80            self.buffer[feature] = value
 81        else:
 82            self.buffer[feature] = value
 83
 84    def get_feature(self, feature):
 85        return self.buffer[feature]
 86
 87    def print_values(self):
 88        print(*self.buffer.values())
 89        self.writer.writerow(self.buffer.values())
 90
 91    def get_buffer_keys(self):
 92        return self.buffer.keys()
 93
 94    def reset(self):
 95        self.buffer["enabled_time"] = None
 96        self.buffer["start_time"] = None
 97        self.buffer["end_time"] = None
 98        self.buffer["resource"] = None
 99        self.buffer["wip_wait"] = -1
100        self.buffer["wip_start"] = -1
101        self.buffer["wip_end"] = -1
102        self.buffer["wip_activity"] = -1
103        self.buffer["ro_total"] = []
104        self.buffer["ro_single"] = -1
105        self.buffer["queue"] = -1
106        self.buffer["attribute_event"] = dict()
Buffer(writer, values=None)
47    def __init__(self, writer, values=None):
48        self.buffer = {
49            "id_case": -1,
50            "activity": None,
51            "enabled_time": None,
52            "start_time": None,
53            "end_time": None,
54            "role": None,
55            "resource": None,
56            "wip_wait": -1,
57            "wip_start": -1,
58            "wip_end": -1,
59            "wip_activity": -1,
60            "ro_total": [],
61            "ro_single": -1,
62            "queue": -1,
63            "prefix": Prefix,
64            "attribute_case": dict(),
65            "attribute_event": dict()
66        }
67        if values:
68            self._decopy_value(values)
69        self.writer = writer
buffer
writer
def set_feature(self, feature, value):
78    def set_feature(self, feature, value):
79        if isinstance(self.buffer[feature], list):
80            self.buffer[feature] = value
81        else:
82            self.buffer[feature] = value
def get_feature(self, feature):
84    def get_feature(self, feature):
85        return self.buffer[feature]
def print_values(self):
87    def print_values(self):
88        print(*self.buffer.values())
89        self.writer.writerow(self.buffer.values())
def get_buffer_keys(self):
91    def get_buffer_keys(self):
92        return self.buffer.keys()
def reset(self):
 94    def reset(self):
 95        self.buffer["enabled_time"] = None
 96        self.buffer["start_time"] = None
 97        self.buffer["end_time"] = None
 98        self.buffer["resource"] = None
 99        self.buffer["wip_wait"] = -1
100        self.buffer["wip_start"] = -1
101        self.buffer["wip_end"] = -1
102        self.buffer["wip_activity"] = -1
103        self.buffer["ro_total"] = []
104        self.buffer["ro_single"] = -1
105        self.buffer["queue"] = -1
106        self.buffer["attribute_event"] = dict()