pm4py.util package

Submodules

pm4py.util.business_hours module

class pm4py.util.business_hours.BusinessHours(datetime1, datetime2, worktiming=[7, 17], weekends=[6, 7])[source]

Bases: object

getdays()[source]
gethours()[source]
getminutes()[source]

Return the difference in minutes.

getseconds()[source]
is_weekend(datetime)[source]

Returns True if datetime lands on a weekend.

pm4py.util.business_hours.soj_time_business_hours_diff(st: datetime.datetime, et: datetime.datetime, worktiming: List[int], weekends: List[int]) → float[source]

Calculates the difference between the provided timestamps based on the business hours

Parameters
  • st – Start timestamp

  • et – Complete timestamp

  • worktiming

    work schedule of the company (provided as a list where the first number is the start
    of the work time, and the second number is the end of the work time), if business hours are enabled

    Default: [7, 17] (work shift from 07:00 to 17:00)

  • weekends

    indexes of the days of the week that are weekend

    Default: [6, 7] (weekends are Saturday and Sunday)

Returns

Difference in business hours

Return type

diff

pm4py.util.colors module

pm4py.util.colors.get_corr_hex(num)[source]

Gets correspondence between a number and an hexadecimal string

Parameters

num – Number

Returns

Hexadecimal string

Return type

hex_string

pm4py.util.colors.get_string_from_int_below_255(factor)[source]

Gets a string from an integer below 255

Parameters

factor – Factor

Returns

Length 2 string

Return type

stru

pm4py.util.colors.get_transitions_color(count_move_on_model, count_fit)[source]

Gets the color associated to the transition

Parameters
  • count_move_on_model – Number of move on models

  • count_fit – Number of fit moves

Returns

Color associated to the transition

Return type

color

pm4py.util.constants module

class pm4py.util.constants.AvailableSerializations(value)[source]

Bases: enum.Enum

An enumeration.

BPMN = 'bpmn'
DATAFRAME = 'dataframe'
DFG = 'dfg'
EVENT_LOG = 'event_log'
PETRI_NET = 'petri_net'
PROCESS_TREE = 'process_tree'

pm4py.util.exec_utils module

pm4py.util.exec_utils.get_param_value(p, parameters, default)[source]
pm4py.util.exec_utils.get_variant(variant)[source]
pm4py.util.exec_utils.unroll(value)[source]

pm4py.util.pandas_utils module

pm4py.util.pandas_utils.check_dataframe_columns(df)[source]

Checks if the dataframe contains all the required columns. If not, raise an exception

Parameters

df – Pandas dataframe

Deprecated since version 2.2.8: This will be removed in 3.0.0. use check_pandas_dataframe_columns instead

pm4py.util.pandas_utils.check_is_dataframe(log)[source]

Checks if a log object is a dataframe

Parameters

log – Log object

Returns

Is dataframe?

Return type

boolean

Deprecated since version 2.2.8: This will be removed in 3.0.0. use check_is_pandas_dataframe instead

pm4py.util.pandas_utils.check_is_pandas_dataframe(log)[source]

Checks if a log object is a dataframe

Parameters

log – Log object

Returns

Is dataframe?

Return type

boolean

pm4py.util.pandas_utils.check_pandas_dataframe_columns(df)[source]

Checks if the dataframe contains all the required columns. If not, raise an exception

Parameters

df – Pandas dataframe

pm4py.util.pandas_utils.insert_ev_in_tr_index(df: pandas.core.frame.DataFrame, case_id: str = 'case:concept:name', column_name: str = '@@index_in_trace') → pandas.core.frame.DataFrame[source]

Inserts a column that specify the index of the event inside the case

Parameters
  • df – Dataframe

  • case_id – Column that hosts the case identifier

  • column_name – Name of the column that should host the index

Returns

Dataframe with index

Return type

df

pm4py.util.pandas_utils.insert_index(df, column_name='@@index')[source]

Inserts the dataframe index in the specified column

Parameters
  • df – Dataframe

  • column_name – Name of the column that should host the index

Returns

Dataframe with index

Return type

df

pm4py.util.pandas_utils.to_dict_index(df)[source]

Pandas dataframe to dictionary (index method)

Parameters

df – Dataframe

Returns

dict like {index -> {column -> value}}

Return type

dict

pm4py.util.pandas_utils.to_dict_records(df)[source]

Pandas dataframe to dictionary (records method)

Parameters

df – Dataframe

Returns

List containing a dictionary for each row

Return type

list_dictio

pm4py.util.parameters module

pm4py.util.parameters.fetch(p, params)[source]

Assumes a given parameter p (enum) and a collection of (enum) -> value mappings. If the param exists, it is returned, if not, the default value is given.

Parameters
  • p

  • params

pm4py.util.points_subset module

pm4py.util.points_subset.pick_chosen_points(m, n)[source]

Pick chosen points in a list

Parameters
  • m – Number of wanted points

  • n – Number of current points

Returns

Indexes of chosen points

Return type

indexes

pm4py.util.points_subset.pick_chosen_points_list(m, lst)[source]

Pick a chosen number of points from a list

Parameters
  • m – Number of wanted points

  • lst – List

Returns

Reduced list

Return type

reduced_lst

pm4py.util.regex module

class pm4py.util.regex.SharedObj[source]

Bases: object

pm4py.util.regex.check_reg_matching(reg, stringa)[source]

Check if a regular expression matches a given string

Parameters
  • reg – Regular expression

  • stringa – String

Returns

Matches or not?

Return type

boolean

pm4py.util.regex.get_new_char(label, shared_obj)[source]

Get a new single character describing the activity, for the regex

Parameters
  • label – Label of the transition

  • shared_obj – Shared object

pm4py.util.regex.regex_replace_mapping(reg_stri, mapping, special_char='@@', parameters=None)[source]

Replace strings in a regex given the mapping

Parameters
  • reg_stri – Regex string

  • mapping – Mapping

  • special_char – Specification of the special character

  • parameters – Parameters of the algorithm

Returns

Compiled Regex where the elements where replaced according to the mapping

Return type

reg

pm4py.util.string_distance module

pm4py.util.string_distance.argmax_levenshtein(stru: str, list_stri: List[str]) → Optional[str][source]

Given a string (stru), finds a string in a list of strings (list_stri) that maximizes the Levenshtein distance.

Parameters
  • stru – String (that is compared)

  • list_stri – List of comparison strings

Returns

String (belonging to list_stri) that maximizes the Levenshtein distance with the ‘stru’ argument

Return type

argmax_dist

pm4py.util.string_distance.argmin_levenshtein(stru: str, list_stri: List[str]) → Optional[str][source]

Given a string (stru), finds a string in a list of strings (list_stri) that minimizes the Levenshtein distance.

Parameters
  • stru – String (that is compared)

  • list_stri – List of comparison strings

Returns

String (belonging to list_stri) that minimizes the Levenshtein distance with the ‘stru’ argument

Return type

argmin_dist

pm4py.util.string_distance.levenshtein(stru1, stru2)

pm4py.util.typing module

pm4py.util.variants_util module

class pm4py.util.variants_util.Parameters(value)[source]

Bases: enum.Enum

An enumeration.

ACTIVITY_KEY = 'pm4py:param:activity_key'
PARAMETER_VARIANT_DELIMITER = 'variant_delimiter'
class pm4py.util.variants_util.VariantsSpecifications(value)[source]

Bases: enum.Enum

An enumeration.

LIST = 'list'
STRING = 'string'
pm4py.util.variants_util.get_activities_from_variant(variant, parameters=None)[source]
pm4py.util.variants_util.get_variant_from_trace(trace, parameters=None)[source]
pm4py.util.variants_util.variant_to_trace(variant, parameters=None)[source]

pm4py.util.vers_checker module

pm4py.util.vers_checker.check_pandas_ge_024()[source]

Checks if the Pandas version is >= 0.24

pm4py.util.vers_checker.check_pandas_ge_110()[source]

Checks if the Pandas version is >= 1.1.0

pm4py.util.vis_utils module

pm4py.util.vis_utils.check_visualization_inside_jupyter()[source]

Checks if the visualization of the model is performed inside a Jupyter notebook

pm4py.util.vis_utils.get_arc_penwidth(arc_measure, min_arc_measure, max_arc_measure)[source]

Calculate arc width given the current arc measure value, the minimum arc measure value and the maximum arc measure value

Parameters
  • arc_measure – Current arc measure value

  • min_arc_measure – Minimum measure value among all arcs

  • max_arc_measure – Maximum measure value among all arcs

Returns

Current arc width in the graph

Return type

penwidth

pm4py.util.vis_utils.get_base64_from_file(temp_file)[source]

Get base 64 from string content of the file

Parameters

temp_file – Temporary file path

Returns

Base64 string

Return type

base64

pm4py.util.vis_utils.get_base64_from_gviz(gviz)[source]

Get base 64 from string content of the file

Parameters

gviz – Graphviz diagram

Returns

Base64 string

Return type

base64

pm4py.util.vis_utils.get_trans_freq_color(trans_count, min_trans_count, max_trans_count)[source]

Gets transition frequency color

Parameters
  • trans_count – Current transition count

  • min_trans_count – Minimum transition count

  • max_trans_count – Maximum transition count

Returns

Frequency color for visible transition

Return type

color

pm4py.util.vis_utils.human_readable_stat(c)[source]

Transform a timedelta expressed in seconds into a human readable string

Parameters

c – Timedelta expressed in seconds

Returns

Human readable string

Return type

string

pm4py.util.vis_utils.open_opsystem_image_viewer(file_name)[source]

Visualizes a picture using the image viewer of the operating system

Parameters

file_name – Name of the file

pm4py.util.vis_utils.view_image_in_jupyter(file_name)[source]

Visualizes a picture inside the Jupyter notebooks

Parameters

file_name – Name of the file

pm4py.util.xes_constants module

Module contents