Source code for pm4py.objects.log.exporter.xes.exporter

'''
    PM4Py – A Process Mining Library for Python
Copyright (C) 2024 Process Intelligence Solutions UG (haftungsbeschränkt)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see this software project's root or
visit <https://www.gnu.org/licenses/>.

Website: https://processintelligence.solutions
Contact: info@processintelligence.solutions
'''
from enum import Enum

from pm4py.objects.conversion.log import converter as log_conversion
from pm4py.objects.log.exporter.xes.variants import etree_xes_exp, line_by_line
from pm4py.util import exec_utils


[docs] class Variants(Enum): ETREE = etree_xes_exp LINE_BY_LINE = line_by_line
DEFAULT_VARIANT = Variants.LINE_BY_LINE
[docs] def apply(log, output_file_path, variant=DEFAULT_VARIANT, parameters=None): """ Method to export a XES from a log Parameters ----------- log Trace log output_file_path Output file path variant Selected variant of the algorithm parameters Parameters of the algorithm: Parameters.COMPRESS -> Indicates that the XES file must be compressed """ parameters = dict() if parameters is None else parameters return exec_utils.get_variant(variant).apply( log_conversion.apply( log, variant=log_conversion.Variants.TO_EVENT_LOG, parameters=parameters, ), output_file_path, parameters=parameters, )
[docs] def serialize(log, variant=DEFAULT_VARIANT, parameters=None): """ Serialize a log into a binary string containing the XES of the log Parameters ----------- log Trace log variant Selected variant of the algorithm parameters Parameters of the algorithm Returns ----------- string String describing the XES """ parameters = dict() if parameters is None else parameters log_string = exec_utils.get_variant(variant).export_log_as_string( log_conversion.apply( log, variant=log_conversion.Variants.TO_EVENT_LOG, parameters=parameters, ), parameters=parameters, ) return log_string