Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/hotfixes' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Jan 16, 2024
2 parents 7917258 + 0fc4a43 commit 685cfdd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pm4py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from pm4py import util, objects, statistics, algo, visualization, llm, connectors
from pm4py import analysis, conformance, convert, discovery, filtering, hof, ml, ocel, org, read, sim, stats, utils, vis, write
from pm4py.read import read_xes, read_dfg, read_bpmn, read_pnml, read_ptml, read_ocel, read_ocel_csv, read_ocel_xml, read_ocel_json, read_ocel_sqlite, read_ocel2, read_ocel2_sqlite, read_ocel2_xml
from pm4py.read import read_xes, read_dfg, read_bpmn, read_pnml, read_ptml, read_ocel, read_ocel_csv, read_ocel_xml, read_ocel_json, read_ocel_sqlite, read_ocel2, read_ocel2_sqlite, read_ocel2_json, read_ocel2_xml
from pm4py.write import write_xes, write_dfg, write_bpmn, write_pnml, write_ptml, write_ocel, write_ocel_json, write_ocel_csv, write_ocel_xml, write_ocel_sqlite, write_ocel2, write_ocel2_sqlite, write_ocel2_xml
from pm4py.utils import format_dataframe, parse_process_tree, serialize, deserialize, set_classifier, parse_event_log_string, project_on_event_attribute, \
sample_cases, sample_events, rebase, parse_powl_model_string
Expand Down
2 changes: 1 addition & 1 deletion pm4py/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'''

__name__ = 'pm4py'
VERSION = '2.7.9.2'
VERSION = '2.7.9.3'
__version__ = VERSION
__doc__ = 'Process mining for Python'
__author__ = 'Fraunhofer Institute for Applied Information Technology FIT'
Expand Down
12 changes: 8 additions & 4 deletions pm4py/objects/ocel/importer/jsonocel/variants/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ def get_base_ocel(json_obj: Any, parameters: Optional[Dict[Any, Any]] = None):
dct[k] = v
this_rel = {}
for obj in ev[constants.OCEL_OMAP_KEY]:
this_rel[obj] = {event_id: ev_id, event_activity: ev[event_activity],
event_timestamp: parser.apply(ev[event_timestamp]), object_id: obj,
object_type: types_dict[obj]}
if obj in types_dict:
this_rel[obj] = {event_id: ev_id, event_activity: ev[event_activity],
event_timestamp: parser.apply(ev[event_timestamp]), object_id: obj,
object_type: types_dict[obj]}
if constants.OCEL_TYPED_OMAP_KEY in ev:
for element in ev[constants.OCEL_TYPED_OMAP_KEY]:
this_rel[element[object_id]][constants.DEFAULT_QUALIFIER] = element[constants.DEFAULT_QUALIFIER]
if object_id in element:
key1 = element[object_id]
if key1 in this_rel:
this_rel[key1][constants.DEFAULT_QUALIFIER] = element[constants.DEFAULT_QUALIFIER]
for obj in this_rel:
relations.append(this_rel[obj])
events.append(dct)
Expand Down
8 changes: 8 additions & 0 deletions pm4py/objects/ocel/importer/sqlite/variants/ocel20.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Parameters(Enum):
INTERNAL_INDEX = constants.PARAM_INTERNAL_INDEX
QUALIFIER = constants.PARAM_QUALIFIER
CHANGED_FIELD = constants.PARAM_CHNGD_FIELD
CUMCOUNT = "cumcount"
VALIDATION = "validation"
EXCEPT_IF_INVALID = "except_if_invalid"

Expand All @@ -60,6 +61,7 @@ def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None):
internal_index = exec_utils.get_param_value(Parameters.INTERNAL_INDEX, parameters, constants.DEFAULT_INTERNAL_INDEX)
qualifier_field = exec_utils.get_param_value(Parameters.QUALIFIER, parameters, constants.DEFAULT_QUALIFIER)
changed_field = exec_utils.get_param_value(Parameters.CHANGED_FIELD, parameters, constants.DEFAULT_CHNGD_FIELD)
cumcount_field = exec_utils.get_param_value(Parameters.CUMCOUNT, parameters, "@@cumcount")

if validation:
satisfied, unsatisfied = ocel20_rel_validation.apply(file_path)
Expand Down Expand Up @@ -115,9 +117,14 @@ def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None):

events_timestamp = event_types_coll[[event_id, event_timestamp]].to_dict('records')
events_timestamp = {x[event_id]: x[event_timestamp] for x in events_timestamp}
object_types_coll[cumcount_field] = object_types_coll.groupby(object_id).cumcount()

if changed_field in object_types_coll:
objects = object_types_coll[object_types_coll[changed_field].isna()]
object_changes = object_types_coll[~object_types_coll[changed_field].isna()]
if len(objects) == 0:
objects = object_types_coll[object_types_coll[cumcount_field] == 0]
object_changes = object_types_coll[object_types_coll[cumcount_field] > 0]
if len(object_changes) == 0:
object_changes = None
del objects[changed_field]
Expand All @@ -126,6 +133,7 @@ def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None):
object_changes = None

del objects[event_timestamp]
del objects[cumcount_field]

E2O = pd.read_sql("SELECT * FROM event_object", conn)
E2O = E2O.rename(columns={"ocel_event_id": event_id, "ocel_object_id": object_id, "ocel_qualifier": qualifier_field})
Expand Down
26 changes: 19 additions & 7 deletions pm4py/objects/ocel/importer/xmlocel/variants/ocel20.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from pm4py.util import exec_utils, dt_parsing, pandas_utils
from pm4py.objects.ocel.util import ocel_consistency


class Parameters(Enum):
EVENT_ID = constants.PARAM_EVENT_ID
EVENT_ACTIVITY = constants.PARAM_EVENT_ACTIVITY
Expand All @@ -41,12 +40,25 @@ class Parameters(Enum):

def parse_xml(value, tag_str_lower, parser):
if "float" in tag_str_lower:
if value == "null":
return 0
return float(value)
elif "date" in tag_str_lower:
return parser.apply(value)
return embed_date_parser(parser.apply, value)
return str(value)


def embed_date_parser(date_parser, x):
try:
return date_parser(x)
except:
from dateutil.parser import parse
try:
return parse(x)
except:
return parse(x, fuzzy=True)


def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None) -> OCEL:
if parameters is None:
parameters = {}
Expand Down Expand Up @@ -134,7 +146,7 @@ def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None) -> OCEL:
if attribute_time == "0" or attribute_time.startswith("1970-01-01T00:00:00"):
obj_dict[attribute_name] = attribute_text
else:
attribute_time = date_parser.apply(attribute_time)
attribute_time = embed_date_parser(date_parser.apply, attribute_time)
obj_change_dict = {object_id_column: object_id, object_type_column: object_type, attribute_name: attribute_text, changed_field: attribute_name, event_timestamp_column: attribute_time}
object_changes_list.append(obj_change_dict)

Expand All @@ -148,7 +160,7 @@ def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None) -> OCEL:
for event in child:
event_id = event.get("id")
event_type = event.get("type")
event_time = date_parser.apply(event.get("time"))
event_time = embed_date_parser(date_parser.apply, event.get("time"))

ev_dict = {event_id_column: event_id, event_activity_column: event_type, event_timestamp_column: event_time}

Expand All @@ -158,9 +170,9 @@ def apply(file_path: str, parameters: Optional[Dict[Any, Any]] = None) -> OCEL:
target_object_id = target_object.get("object-id")
qualifier = target_object.get("qualifier")

rel_dict = {event_id_column: event_id, event_activity_column: event_type, event_timestamp_column: event_time, object_id_column: target_object_id, object_type_column: obj_type_dict[target_object_id], qualifier_field: qualifier}

relations_list.append(rel_dict)
if target_object_id in obj_type_dict:
rel_dict = {event_id_column: event_id, event_activity_column: event_type, event_timestamp_column: event_time, object_id_column: target_object_id, object_type_column: obj_type_dict[target_object_id], qualifier_field: qualifier}
relations_list.append(rel_dict)
elif child2.tag.endswith("attributes"):
for attribute in child2:
attribute_name = attribute.get("name")
Expand Down
2 changes: 1 addition & 1 deletion pm4py/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def read_ocel2(file_path: str, encoding: str = constants.DEFAULT_ENCODING) -> OC
return read_ocel2_sqlite(file_path, encoding=encoding)
elif file_path.lower().endswith("xml") or file_path.lower().endswith("xmlocel"):
return read_ocel2_xml(file_path, encoding=encoding)
elif file_path.lower().endswith("jsonocel"):
elif file_path.lower().endswith("json") or file_path.lower().endswith("jsonocel"):
return read_ocel2_json(file_path, encoding=encoding)


Expand Down

0 comments on commit 685cfdd

Please sign in to comment.