Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ppinot4py/model/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def __repr__(self):
if self.applies_to == AppliesTo.DATA:
return f"{self.changes_to_state}"
elif self.applies_to == AppliesTo.PROCESS:
return f"{self.changes_to_state} - {self.applies_to}"
return f"{self.changes_to_state} the {self.applies_to.name}"
else:
return f"{self.changes_to_state} - {self.applies_to} - {self.activity_name}"
return f"{self.changes_to_state} the {self.applies_to.name} with name {self.activity_name}"



Expand Down
26 changes: 24 additions & 2 deletions ppinot4py/model/measures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .conditions import TimeInstantCondition
import datetime
import calendar

def _time_instance_auto_wrap(condition):
if condition is None:
Expand All @@ -11,6 +12,7 @@ def _time_instance_auto_wrap(condition):
return condition

def _name_of_aggregation(agg):
agg = agg.upper()
if agg == "AVG":
return "average"
if agg == "MIN":
Expand Down Expand Up @@ -187,9 +189,29 @@ def conversion(self):
time_delta_type = lambda x: (datetime.timedelta(minutes = x))
elif(self.unit_hour == 'sec'):
time_delta_type = lambda x: (datetime.timedelta(seconds = x))

return time_delta_type

def day_of_the_week(weekend_list):
weekDayInNumber = list(calendar.day_name)
newWeekList = []


for x in weekend_list:
newWeekList.append(weekDayInNumber[x])

daysInText = ", ".join([f"{g}" for g in newWeekList])

return daysInText

def holidays_in_the_year(holidays):
listOfNames = []

daysInText = ", ".join([f"{name}" for date, name in sorted(holidays.items())])
return daysInText

def __str__(self):

daysInText = BusinessDuration.day_of_the_week(self.weekend_list)
listOfNamesInYear = BusinessDuration.holidays_in_the_year(self.holiday_list)
text = f"The business time starts at {self.business_start}, ends at {self.business_end}, the weekend is defined in the days {daysInText}, the name of the holidays days are: {listOfNamesInYear} and the unit of time used is {self.unit_hour}"

return text
7 changes: 7 additions & 0 deletions ppinot4py/model/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class RuntimeState():

def __init__(self, state):
self.state = state

def __repr__(self) -> str:
if(self.state == 'START'):
return f"when starts"
else:
return "when ends"


RuntimeState.START = RuntimeState('START')
RuntimeState.END = RuntimeState('END')
Expand Down
59 changes: 59 additions & 0 deletions ppinot4py/model/tests/test_measures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from ppinot4py.model import *
from datetime import time
from ppinot4py.computers import *
import holidays as pyholidays
import numpy as np
import calendar

def test_count_text():
c = CountMeasure("ACT == 'open'")
Expand All @@ -22,3 +27,57 @@ def test_derived_text():
t = TimeMeasure("ACT == 'open'", "ACT == 'close'", first_to=True)
d = DerivedMeasure("c/t", {"c": c, "t": t})
assert f"{d}" == "the function c/t where c is the number of times ACT == 'open', t is the duration between the first time instant when ACT == 'open' and the first time instant when ACT == 'close'"

def test_Business_Duration_text():

newWeekEnd = []
b = BusinessDuration(business_start = time(7,0,0),
business_end = time(17,0,0),
weekend_list = [5,6],
holiday_list = pyholidays.ES(prov ='AN', years=2018),
unit_hour = 'sec')

daysInText = BusinessDuration.day_of_the_week(b.weekend_list)
listOfNamesInYear = BusinessDuration.holidays_in_the_year(b.holiday_list)

assert f"{b}" == f"The business time starts at {b.business_start}, ends at {b.business_end}, the weekend is defined in the days {daysInText}, the name of the holidays days are: {listOfNamesInYear} and the unit of time used is {b.unit_hour}"

def test_cyclic_time_text():

t = TimeMeasure(
from_condition='`lifecycle:transition` == "In Progress"',
to_condition='`lifecycle:transition` == "Awaiting Assignment"',
single_instance_agg_function='SUM',
time_measure_type='CYCLIC')

precon_text = f" if {t.precondition}" if t.precondition is not None else ""

assert f"{t}" == f"the sum duration between the pairs of time instants when {t.from_condition} and when {t.to_condition}{precon_text}"

def test_aggregated_filter_to_apply_text():
c = CountMeasure("ACT == 'open'")
d = CountMeasure("ACT == 'closed'")
aggregatedMeasure = AggregatedMeasure(
base_measure=c,
single_instance_agg_function='AVG',
filter_to_apply=d)

assert f"{aggregatedMeasure}" == "the average of the number of times ACT == 'open' filtered by the number of times ACT == 'closed'"

def test_data_first_text():
t = TimeMeasure("ACT == 'open'", "ACT == 'close'")
d = DataMeasure(
data_content_selection="lifecycle:transition",
first=True)
assert f"{d}" == "the first value of lifecycle:transition"

def test_aggregated_text_lower_case():
a = AggregatedMeasure(CountMeasure("concept:name=='Appeal to Judge'"), 'avg')
assert f"{a}" == "the average of the number of times concept:name=='Appeal to Judge'"


def test_aggregated_text_time_instant_condition():
b = AggregatedMeasure(CountMeasure(TimeInstantCondition(RuntimeState.START, AppliesTo.ACTIVITY, "Appeal to Judge")), 'avg')
assert f"{b}" == "the average of the number of times when starts the ACTIVITY with name Appeal to Judge"