Social Network Analysis

Social Network Analysis

Social Network Analysis from event logs means inferring the relationships between the resources of an organization. For measuring these, several metrics exist.

To obtain a Social Network in PM4Py, the following steps could be followed:

  • Importing the log
  • Calculating a metric
  • Doing a visualization

Importing a log

A log object could be imported, for example using the following code:

import os
from pm4py.objects.log.importer.xes import factory as xes_importer

log = xes_importer.apply(os.path.join("tests", "input_data", "running-example.xes"))

Doing a visualization

Following visualizations are available for Social Network in PM4Py:

  • Static image visualization (based on NetworkX; variant=”networkx”)
  • Dynamic image visualization (based on Pyvis; variant=”pyvis”)

The chosen visualization could be applied using the following code, given the values of the metric:

from pm4py.visualization.sna import factory as sna_vis_factory
representation = sna_vis_factory.apply(metric_values, variant="<VARIANT>")

and visualized:

sna_vis_factory.view(representation , variant="<VARIANT>")

or saved to disk:

sna_vis_factory.save(representation, "IMAGE.png", variant="<VARIANT>")

Calculating a metric

Handover of Work metric

The Handover of Work metric measures how many times an individual is followed by another individual in the execution of a business process. To calculate the Handover of Work metric, the following code could be used:

from pm4py.algo.enhancement.sna import factory as sna_factory
hw_values = sna_factory.apply(log, variant="handover")

Then, a visualization could be obtained through the NetworkX or through the Pyvis:

from pm4py.visualization.sna import factory as sna_vis_factory
gviz_hw_py = sna_vis_factory.apply(hw_values, variant="pyvis")
sna_vis_factory.view(gviz_hw_py, variant="pyvis")

Subcontracting metric

The subcontracting metric calculates how many times the work of an individual is interleaved by the work of some other individual, only to eventually “return” to the original individual. To measure the subcontracting metric, the following code could be used:

from pm4py.algo.enhancement.sna import factory as sna_factory
sub_values = sna_factory.apply(log, variant="subcontracting")

Then, a visualization could be obtained through the NetworkX or through the Pyvis:

from pm4py.visualization.sna import factory as sna_vis_factory
gviz_sub_py = sna_vis_factory.apply(sub_values, variant="pyvis")
sna_vis_factory.view(gviz_sub_py, variant="pyvis")

Working Together metric

The Working together metric calculates how many times two individuals work together for resolving a process instance. To measure the Working Together metric, the following code could be used:

from pm4py.algo.enhancement.sna import factory as sna_factory
wt_values = sna_factory.apply(log, variant="working_together")

Then, a visualization could be obtained through the NetworkX or through the Pyvis:

Similar Activities metric

The Similar Activities metric calculates how much similar is the work pattern between two individuals. To measure the Similar Activities metric, the following code could be used:

from pm4py.algo.enhancement.sna import factory as sna_factory
ja_values = sna_factory.apply(log, variant="jointactivities")

Then, a visualization could be obtained through the NetworkX or through the Pyvis:

from pm4py.visualization.sna import factory as sna_vis_factory
gviz_ja_py = sna_vis_factory.apply(ja_values, variant="pyvis")
sna_vis_factory.view(gviz_ja_py, variant="pyvis")

.