nirdizati_light.labeling.common
1from enum import Enum 2from nirdizati_light.utils.log_metrics import events_by_date, resources_by_date, new_trace_start 3from nirdizati_light.utils.time_metrics import elapsed_time_id, remaining_time_id, count_on_event_day, duration 4from pm4py.objects.log.obj import EventLog, Trace 5 6def get_intercase_attributes(log, encoding): 7 """Dict of kwargs 8 These intercase attributes are expensive operations!!! 9 """ 10 # Expensive operations 11 executed_events = events_by_date(log) if encoding.add_executed_events else None 12 resources_used = resources_by_date(log) if encoding.add_resources_used else None 13 new_traces = new_trace_start(log) if encoding.add_new_traces else None 14 kwargs = {'executed_events': executed_events, 'resources_used': resources_used, 'new_traces': new_traces} 15 # 'label': label} TODO: is it really necessary to add this field in the dict? 16 return kwargs 17 18class LabelTypes(Enum): 19 """ 20 Possible labels for the predictive task 21 """ 22 NEXT_ACTIVITY = 'next_activity' 23 ATTRIBUTE_STRING = 'label_attribute_string' 24 REMAINING_TIME = 'remaining_time' 25 DURATION = 'duration' 26 NO_LABEL = 'no_label' 27 28class ThresholdTypes(Enum): 29 """ 30 ThresholdTypes 31 """ 32 THRESHOLD_MEAN = 'threshold_mean' 33 THRESHOLD_CUSTOM = 'threshold_custom' 34 NONE = 'none' 35 36 37def add_label_column(trace, labeling_type, prefix_length: int): 38 """TODO COMMENT ME 39 """ 40 if labeling_type == LabelTypes.NEXT_ACTIVITY.value: 41 return next_event_name(trace, prefix_length) 42 elif labeling_type == LabelTypes.ATTRIBUTE_STRING.value: 43 try: 44 return trace.attributes['label'] 45 except KeyError: 46 return trace[0]['label'] 47 elif labeling_type == LabelTypes.REMAINING_TIME.value: 48 return remaining_time_id(trace, prefix_length) 49 elif labeling_type == LabelTypes.DURATION.value: 50 return duration(trace) 51 elif labeling_type == LabelTypes.NO_LABEL.value: 52 return 0 53 else: 54 raise Exception('Label not set please select one of LabelTypes(Enum) values!') 55 56 57 58 59def next_event_name(trace: list, prefix_length: int): 60 """Return the event event_name at prefix length or 0 if out of range. 61 62 """ 63 if prefix_length < len(trace): 64 next_event = trace[prefix_length] 65 name = next_event['concept:name'] 66 return name 67 else: 68 return 0
def
get_intercase_attributes(log, encoding):
7def get_intercase_attributes(log, encoding): 8 """Dict of kwargs 9 These intercase attributes are expensive operations!!! 10 """ 11 # Expensive operations 12 executed_events = events_by_date(log) if encoding.add_executed_events else None 13 resources_used = resources_by_date(log) if encoding.add_resources_used else None 14 new_traces = new_trace_start(log) if encoding.add_new_traces else None 15 kwargs = {'executed_events': executed_events, 'resources_used': resources_used, 'new_traces': new_traces} 16 # 'label': label} TODO: is it really necessary to add this field in the dict? 17 return kwargs
Dict of kwargs These intercase attributes are expensive operations!!!
class
LabelTypes(enum.Enum):
19class LabelTypes(Enum): 20 """ 21 Possible labels for the predictive task 22 """ 23 NEXT_ACTIVITY = 'next_activity' 24 ATTRIBUTE_STRING = 'label_attribute_string' 25 REMAINING_TIME = 'remaining_time' 26 DURATION = 'duration' 27 NO_LABEL = 'no_label'
Possible labels for the predictive task
NEXT_ACTIVITY =
<LabelTypes.NEXT_ACTIVITY: 'next_activity'>
ATTRIBUTE_STRING =
<LabelTypes.ATTRIBUTE_STRING: 'label_attribute_string'>
REMAINING_TIME =
<LabelTypes.REMAINING_TIME: 'remaining_time'>
DURATION =
<LabelTypes.DURATION: 'duration'>
NO_LABEL =
<LabelTypes.NO_LABEL: 'no_label'>
Inherited Members
- enum.Enum
- name
- value
class
ThresholdTypes(enum.Enum):
29class ThresholdTypes(Enum): 30 """ 31 ThresholdTypes 32 """ 33 THRESHOLD_MEAN = 'threshold_mean' 34 THRESHOLD_CUSTOM = 'threshold_custom' 35 NONE = 'none'
ThresholdTypes
THRESHOLD_MEAN =
<ThresholdTypes.THRESHOLD_MEAN: 'threshold_mean'>
THRESHOLD_CUSTOM =
<ThresholdTypes.THRESHOLD_CUSTOM: 'threshold_custom'>
NONE =
<ThresholdTypes.NONE: 'none'>
Inherited Members
- enum.Enum
- name
- value
def
add_label_column(trace, labeling_type, prefix_length: int):
38def add_label_column(trace, labeling_type, prefix_length: int): 39 """TODO COMMENT ME 40 """ 41 if labeling_type == LabelTypes.NEXT_ACTIVITY.value: 42 return next_event_name(trace, prefix_length) 43 elif labeling_type == LabelTypes.ATTRIBUTE_STRING.value: 44 try: 45 return trace.attributes['label'] 46 except KeyError: 47 return trace[0]['label'] 48 elif labeling_type == LabelTypes.REMAINING_TIME.value: 49 return remaining_time_id(trace, prefix_length) 50 elif labeling_type == LabelTypes.DURATION.value: 51 return duration(trace) 52 elif labeling_type == LabelTypes.NO_LABEL.value: 53 return 0 54 else: 55 raise Exception('Label not set please select one of LabelTypes(Enum) values!')
TODO COMMENT ME
def
next_event_name(trace: list, prefix_length: int):
60def next_event_name(trace: list, prefix_length: int): 61 """Return the event event_name at prefix length or 0 if out of range. 62 63 """ 64 if prefix_length < len(trace): 65 next_event = trace[prefix_length] 66 name = next_event['concept:name'] 67 return name 68 else: 69 return 0
Return the event event_name at prefix length or 0 if out of range.