<jupyter_start><jupyter_text>Temporal Process Mining DefinitionProcess mining algorithms find a suitable process model that describes the order of events or activities that are observed during a process execution.<jupyter_code>namespace, type = "default", "Foo"<jupyter_output><empty_output><jupyter_text>This notebook mines the workflow execution in namespace `namespace` of workflow type `type`<jupyter_code># python std
import datetime
# google grpc
import grpc
# pandas
import pandas
# temporal
from temporal.api.common.v1.message_pb2 import *
from temporal.api.enums.v1.event_type_pb2 import *
from temporal.api.workflowservice.v1.request_response_pb2 import *
from temporal.api.workflowservice.v1.service_pb2_grpc import *

wfss = WorkflowServiceStub(grpc.insecure_channel('host.docker.internal:7233'))

logs = []

for wfe in wfss.ScanWorkflowExecutions(ScanWorkflowExecutionsRequest(namespace=namespace, query=f"WorkflowType='{type}'")).executions:
    dtl = wfss.GetWorkflowExecutionHistory(GetWorkflowExecutionHistoryRequest(namespace=namespace, execution=WorkflowExecution(workflow_id=wfe.execution.workflow_id, run_id=wfe.execution.run_id)))
    for evt in dtl.history.events:
        if evt.event_type == EVENT_TYPE_ACTIVITY_TASK_SCHEDULED:
            logs.append([wfe.execution.run_id, evt.activity_task_scheduled_event_attributes.activity_type.name, datetime.datetime.fromtimestamp(evt.event_time.seconds)])
        
logs = pandas.DataFrame(logs, columns = ["case:concept:name", "concept:name", "time:timestamp"])
logs<jupyter_output><empty_output><jupyter_text>Process MiningFrom the website:Designed to be used in both academia and industry, PM4Py is the leading open source process mining platform written in Python.<jupyter_code>import sys
!{sys.executable} -m pip install pm4py
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
from pm4py.objects.conversion.log import converter as log_converter
from pm4py.visualization.petri_net import visualizer as pn_visualizer

logs = log_converter.apply(logs)

net, initial_marking, final_marking = alpha_miner.apply(logs)

pn_visualizer.apply(net, initial_marking, final_marking, variant=pn_visualizer.Variants.FREQUENCY, log=log_converter.apply(logs))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08684093929995569, 'fraction_numerical': 0.007532122286220647, 'mean_word_length': 7.362962962962963, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '614595', 'license': 'MIT', 'n_tokens_mistral': 719, 'n_tokens_neox': 700, 'n_words': 152, 'path': 'Mining.ipynb', 'repo_name': 'dtornow/temporal-process-mining', 'size': '2257'}