Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusRostSAP committed Jun 5, 2024
1 parent 109f81e commit 1efe7db
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 327 deletions.
177 changes: 0 additions & 177 deletions explainer/explainer.py

This file was deleted.

44 changes: 6 additions & 38 deletions explainer/explainer_regex.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import math
import re
from itertools import combinations, product, chain
from explainer.explainer_util import (
Trace,
get_sublists,
levenshtein_distance,
)
from itertools import product
from explainer.explainer_util import *


class ExplainerRegex:
Expand Down Expand Up @@ -382,7 +378,7 @@ def determine_fitness_rate(self, event_log, constraints=None):

def variant_ctrb_to_fitness(self, event_log, trace, constraints=None):
"""
Determines the contribution of a specific trace variant to the fitness of the event log.
Determines the contribution of a specific trace variant to the fitness loss of the event log.
:param event_log: The event log to analyze.
:param trace: The trace variant to calculate its contribution.
Expand All @@ -396,7 +392,7 @@ def variant_ctrb_to_fitness(self, event_log, trace, constraints=None):
total_traces = len(event_log)
contribution_of_trace = 0
for con in constraints:
if re.search(con, "".join(trace)):
if not re.search(con, "".join(trace)):
contribution_of_trace += 1
nr = event_log.get_variant_count(trace)
contribution_of_trace = contribution_of_trace / len(constraints)
Expand Down Expand Up @@ -458,7 +454,7 @@ def constraint_ctrb_to_conformance(self, log, constraints, index):

def constraint_ctrb_to_fitness(self, log, constraints, index):
"""
Determines the Shapley value-based contribution of a constraint to the overall conformance rate.
Determines the Shapley value-based contribution of a constraint to the overall fitness rate.
:param log: The event log, where keys are strings and values are counts of trace variants.
:param constraints: A list of constraints (regexp strings).
Expand All @@ -474,34 +470,6 @@ def constraint_ctrb_to_fitness(self, log, constraints, index):
contributor = constraints[index]
ctrb_count = 0
for trace, count in log.log.items():
if re.search(contributor, "".join(trace)):
if not re.search(contributor, "".join(trace)):
ctrb_count += count
return ctrb_count / (len(log) * len(constraints))


def determine_powerset(elements):
"""Determines the powerset of a list of elements
Args:
elements (set): Set of elements
Returns:
list: Powerset of elements
"""
lset = list(elements)
ps_elements = chain.from_iterable(
combinations(lset, option) for option in range(len(lset) + 1)
)
return [set(ps_element) for ps_element in ps_elements]


def get_iterative_subtrace(trace):
"""
Generates all possible non-empty contiguous sublists of a list, maintaining order.
:param lst: The input list.
n: the minmum length of sublists
:return: A list of all non-empty contiguous sublists.
"""
sublists = []
for i in range(0, len(trace)):
sublists.append(trace.nodes[0 : i + 1])
return sublists
31 changes: 1 addition & 30 deletions explainer/explainer_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import re
import math
from tutorial.SignavioAuthenticator import SignavioAuthenticator
from itertools import combinations, chain
import requests
from tutorial.conf import system_instance, workspace_id, user_name, pw
from tutorial.conf import *


class ExplainerSignal:
Expand Down Expand Up @@ -551,31 +550,3 @@ def load_variants(self):
# Add each activity variant to the event_log
for activity in data:
self.event_log.add_trace(Trace(activity[0]))


def determine_powerset(elements):
"""Determines the powerset of a list of elements
Args:
elements (set): Set of elements
Returns:
list: Powerset of elements
"""
lset = list(elements)
ps_elements = chain.from_iterable(
combinations(lset, option) for option in range(len(lset) + 1)
)
return [set(ps_element) for ps_element in ps_elements]


def get_iterative_subtrace(trace):
"""
Generates all possible non-empty contiguous sublists of a list, maintaining order.
:param lst: The input list.
n: the minmum length of sublists
:return: A list of all non-empty contiguous sublists.
"""
sublists = []
for i in range(0, len(trace)):
sublists.append(trace.nodes[0 : i + 1])
return sublists
29 changes: 28 additions & 1 deletion explainer/explainer_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from itertools import combinations
from itertools import combinations, chain


class Trace:
Expand Down Expand Up @@ -177,6 +177,33 @@ def levenshtein_distance(seq1, seq2):
)
return matrix[size_x - 1][size_y - 1]

def determine_powerset(elements):
"""Determines the powerset of a list of elements
Args:
elements (set): Set of elements
Returns:
list: Powerset of elements
"""
lset = list(elements)
ps_elements = chain.from_iterable(
combinations(lset, option) for option in range(len(lset) + 1)
)
return [set(ps_element) for ps_element in ps_elements]


def get_iterative_subtrace(trace):
"""
Generates all possible non-empty contiguous sublists of a list, maintaining order.
:param lst: The input list.
n: the minmum length of sublists
:return: A list of all non-empty contiguous sublists.
"""
sublists = []
for i in range(0, len(trace)):
sublists.append(trace.nodes[0 : i + 1])
return sublists


SIGNAL_KEYWORDS = [
"ABS",
Expand Down
Loading

0 comments on commit 1efe7db

Please sign in to comment.