{ "cells": [ { "metadata": { "ExecuteTime": { "end_time": "2026-05-29T13:43:25.562344500Z", "start_time": "2026-05-29T13:43:25.535835800Z" } }, "cell_type": "code", "source": [ "import warnings\n", "warnings.filterwarnings(\"ignore\", category=UserWarning)" ], "id": "35856331eab1284c", "outputs": [], "execution_count": 14 }, { "metadata": {}, "cell_type": "markdown", "source": [ "# Managing Event Logs\n", "\n", "This tutorial will go through the steps necessary to import and manage an event log.\n", "\n", "## The `D4PyEventLog` class\n", "\n", "The `Declare4Py.D4PyEventLog.D4PyEventLog` class is responsible for managing with `.xes` event log. It methods utilities for importing an event log, retrieving useful information, exporting it in a `.xes` format or converting it in a Pandas dataframe and computing the frequent itemsets of activities or other attributes.\n", "\n", "We show how to instantiate a `D4PyEventLog`, notice that the name of the case id is required." ], "id": "c2e67e3859298dbb" }, { "cell_type": "code", "id": "8b6c9e04", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T13:43:25.590698Z", "start_time": "2026-05-29T13:43:25.570344800Z" } }, "source": [ "import os\n", "from Declare4Py.D4PyEventLog import D4PyEventLog\n", "\n", "event_log: D4PyEventLog = D4PyEventLog(case_name=\"case:concept:name\")" ], "outputs": [], "execution_count": 15 }, { "cell_type": "markdown", "id": "1225a100", "metadata": {}, "source": [ "The next step is the parsing of the log with the `parse_xes_log` function. Logs can be passed both in the `.xes` or `xes.gz` formats." ] }, { "cell_type": "code", "id": "e5ae55fa", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T13:43:26.731973800Z", "start_time": "2026-05-29T13:43:25.592702Z" } }, "source": [ "log_path = os.path.join(\"../../../\", \"tests\", \"test_logs\", \"Sepsis Cases.xes.gz\")\n", "\n", "# Parses a xes log to EventLog\n", "event_log.parse_xes_log(log_path)" ], "outputs": [ { "data": { "text/plain": [ "parsing log, completed traces :: 0%| | 0/1050 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
InfectionSuspectedorg:groupDiagnosticBloodDisfuncOrgSIRSCritTachypneaHypotensieSIRSCritHeartRateInfusionDiagnosticArtAstrupconcept:name...DiagnosticLacticAcidlifecycle:transitionDiagnoseHypoxieDiagnosticUrinarySedimentDiagnosticECGLeucocytesCRPLacticAcidcase:concept:name
0TrueATrueTrueTrueTrueTrueTrueTrueER Registration...TruecompleteAFalseTrueTrueNaNNaNNaNA
1NaNBNaNNaNNaNNaNNaNNaNNaNLeucocytes...NaNcompleteNaNNaNNaNNaN9.6NaNNaNA
2NaNBNaNNaNNaNNaNNaNNaNNaNCRP...NaNcompleteNaNNaNNaNNaNNaN21.0NaNA
3NaNBNaNNaNNaNNaNNaNNaNNaNLacticAcid...NaNcompleteNaNNaNNaNNaNNaNNaN2.2A
4NaNCNaNNaNNaNNaNNaNNaNNaNER Triage...NaNcompleteNaNNaNNaNNaNNaNNaNNaNA
\n", "

5 rows × 32 columns

\n", "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 24 }, { "cell_type": "markdown", "id": "4f8dd30a", "metadata": {}, "source": [ "### The `to_eventlog` method\n", "\n", "The event log can be converted in a EventLog with the `to_eventlog` method." ] }, { "cell_type": "code", "id": "4a895b28", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T13:43:27.639609700Z", "start_time": "2026-05-29T13:43:27.212577Z" } }, "source": [ "event_log.to_eventlog()\n", "event_log.get_log()" ], "outputs": [ { "data": { "text/plain": [ "[{'attributes': {'concept:name': 'A'}, 'events': [{'InfectionSuspected': True, 'org:group': 'A', 'DiagnosticBlood': True, 'DisfuncOrg': True, 'SIRSCritTachypnea': True, 'Hypotensie': True, 'SIRSCritHeartRate': True, 'Infusion': True, 'DiagnosticArtAstrup': True, 'concept:name': 'ER Registration', 'Age': 85.0, 'DiagnosticIC': True, 'DiagnosticSputum': False, 'DiagnosticLiquor': False, 'DiagnosticOther': False, 'SIRSCriteria2OrMore': True, 'DiagnosticXthorax': True, 'SIRSCritTemperature': True, 'time:timestamp': Timestamp('2014-10-22 09:15:41+0000', tz='UTC'), 'DiagnosticUrinaryCulture': True, 'SIRSCritLeucos': False, 'Oligurie': False, 'DiagnosticLacticAcid': True, 'lifecycle:transition': 'complete', 'Diagnose': 'A', 'Hypoxie': False, 'DiagnosticUrinarySediment': True, 'DiagnosticECG': True, 'Leucocytes': nan, 'CRP': nan, 'LacticAcid': nan}, '..', {'InfectionSuspected': nan, 'org:group': 'E', 'DiagnosticBlood': nan, 'DisfuncOrg': nan, 'SIRSCritTachypnea': nan, 'Hypotensie': nan, 'SIRSCritHeartRate': nan, 'Infusion': nan, 'DiagnosticArtAstrup': nan, 'concept:name': 'Release A', 'Age': nan, 'DiagnosticIC': nan, 'DiagnosticSputum': nan, 'DiagnosticLiquor': nan, 'DiagnosticOther': nan, 'SIRSCriteria2OrMore': nan, 'DiagnosticXthorax': nan, 'SIRSCritTemperature': nan, 'time:timestamp': Timestamp('2014-11-02 14:15:00+0000', tz='UTC'), 'DiagnosticUrinaryCulture': nan, 'SIRSCritLeucos': nan, 'Oligurie': nan, 'DiagnosticLacticAcid': nan, 'lifecycle:transition': 'complete', 'Diagnose': nan, 'Hypoxie': nan, 'DiagnosticUrinarySediment': nan, 'DiagnosticECG': nan, 'Leucocytes': nan, 'CRP': nan, 'LacticAcid': nan}]}, '....', {'attributes': {'concept:name': 'LNA'}, 'events': [{'InfectionSuspected': False, 'org:group': 'L', 'DiagnosticBlood': False, 'DisfuncOrg': False, 'SIRSCritTachypnea': False, 'Hypotensie': False, 'SIRSCritHeartRate': False, 'Infusion': False, 'DiagnosticArtAstrup': False, 'concept:name': 'ER Registration', 'Age': 50.0, 'DiagnosticIC': False, 'DiagnosticSputum': False, 'DiagnosticLiquor': False, 'DiagnosticOther': False, 'SIRSCriteria2OrMore': False, 'DiagnosticXthorax': False, 'SIRSCritTemperature': False, 'time:timestamp': Timestamp('2014-12-03 09:50:28+0000', tz='UTC'), 'DiagnosticUrinaryCulture': False, 'SIRSCritLeucos': False, 'Oligurie': False, 'DiagnosticLacticAcid': False, 'lifecycle:transition': 'complete', 'Diagnose': nan, 'Hypoxie': False, 'DiagnosticUrinarySediment': False, 'DiagnosticECG': False, 'Leucocytes': nan, 'CRP': nan, 'LacticAcid': nan}, '..', {'InfectionSuspected': nan, 'org:group': 'L', 'DiagnosticBlood': nan, 'DisfuncOrg': nan, 'SIRSCritTachypnea': nan, 'Hypotensie': nan, 'SIRSCritHeartRate': nan, 'Infusion': nan, 'DiagnosticArtAstrup': nan, 'concept:name': 'ER Sepsis Triage', 'Age': nan, 'DiagnosticIC': nan, 'DiagnosticSputum': nan, 'DiagnosticLiquor': nan, 'DiagnosticOther': nan, 'SIRSCriteria2OrMore': nan, 'DiagnosticXthorax': nan, 'SIRSCritTemperature': nan, 'time:timestamp': Timestamp('2014-12-03 09:54:39+0000', tz='UTC'), 'DiagnosticUrinaryCulture': nan, 'SIRSCritLeucos': nan, 'Oligurie': nan, 'DiagnosticLacticAcid': nan, 'lifecycle:transition': 'complete', 'Diagnose': nan, 'Hypoxie': nan, 'DiagnosticUrinarySediment': nan, 'DiagnosticECG': nan, 'Leucocytes': nan, 'CRP': nan, 'LacticAcid': nan}]}]" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 25 }, { "cell_type": "markdown", "id": "7c3e6fdf", "metadata": {}, "source": [ "### The `save_xes` method\n", "\n", "The event log can be saved in `xes` format with the `save_xes` method." ] }, { "cell_type": "code", "id": "3cf82cee", "metadata": { "ExecuteTime": { "end_time": "2026-05-29T13:43:29.535246200Z", "start_time": "2026-05-29T13:43:28.030120600Z" } }, "source": [ "event_log.save_xes(\"saved_log.xes\")" ], "outputs": [ { "data": { "text/plain": [ "exporting log, completed traces :: 0%| | 0/1050 [00:00\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
supportitemsetslength
01.000000(concept:name_ER Triage)1
11.000000(concept:name_ER Registration)1
20.999048(concept:name_ER Sepsis Triage)1
30.963810(concept:name_Leucocytes)1
40.959048(concept:name_CRP)1
50.819048(concept:name_LacticAcid)1
61.000000(concept:name_ER Registration, concept:name_ER...2
70.999048(concept:name_ER Registration, concept:name_ER...2
80.999048(concept:name_ER Triage, concept:name_ER Sepsi...2
90.999048(concept:name_ER Registration, concept:name_ER...3
100.963810(concept:name_ER Registration, concept:name_Le...2
110.963810(concept:name_ER Triage, concept:name_Leucocytes)2
120.962857(concept:name_Leucocytes, concept:name_ER Seps...2
130.963810(concept:name_ER Registration, concept:name_Le...3
140.962857(concept:name_ER Registration, concept:name_Le...3
150.962857(concept:name_ER Triage, concept:name_Leucocyt...3
170.959048(concept:name_CRP, concept:name_ER Registration)2
180.959048(concept:name_CRP, concept:name_ER Triage)2
190.958095(concept:name_CRP, concept:name_Leucocytes)2
200.958095(concept:name_CRP, concept:name_ER Sepsis Triage)2
210.959048(concept:name_CRP, concept:name_ER Registratio...3
220.958095(concept:name_CRP, concept:name_ER Triage, con...3
230.958095(concept:name_CRP, concept:name_ER Registratio...3
250.958095(concept:name_CRP, concept:name_ER Triage, con...3
260.958095(concept:name_CRP, concept:name_ER Registratio...3
270.957143(concept:name_CRP, concept:name_Leucocytes, co...3
320.819048(concept:name_LacticAcid, concept:name_CRP)2
330.819048(concept:name_LacticAcid, concept:name_Leucocy...2
340.819048(concept:name_LacticAcid, concept:name_ER Regi...2
350.819048(concept:name_LacticAcid, concept:name_ER Triage)2
360.818095(concept:name_LacticAcid, concept:name_ER Seps...2
370.819048(concept:name_LacticAcid, concept:name_CRP, co...3
380.819048(concept:name_LacticAcid, concept:name_ER Regi...3
390.819048(concept:name_LacticAcid, concept:name_ER Tria...3
400.818095(concept:name_LacticAcid, concept:name_CRP, co...3
410.819048(concept:name_LacticAcid, concept:name_ER Regi...3
420.819048(concept:name_LacticAcid, concept:name_ER Tria...3
430.818095(concept:name_LacticAcid, concept:name_Leucocy...3
440.819048(concept:name_LacticAcid, concept:name_ER Regi...3
450.818095(concept:name_LacticAcid, concept:name_ER Regi...3
460.818095(concept:name_LacticAcid, concept:name_ER Tria...3
\n", "" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 27 } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" }, "vscode": { "interpreter": { "hash": "05d4b7c3cd0aad81aa9df4db91d3eeeb2841d831664bc3cb6ce2ef5b755f059a" } } }, "nbformat": 4, "nbformat_minor": 5 }