Skip to content

Commit 5159b53

Browse files
Reconstruct bpmn activity ids for resource utilization logs (#76) (#77)
* Reconstruct bpmn activity ids for resource utilization logs (#76) * Fix model element id relving in statslogger * Refactored process root level id generation and resolving to ProcessModel class methods --------- Co-authored-by: Matthias Kind <public@matthiaskind.com>
1 parent 4d33449 commit 5159b53

File tree

11 files changed

+56
-38
lines changed

11 files changed

+56
-38
lines changed

src/main/java/de/hpi/bpt/scylla/model/process/ProcessModel.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package de.hpi.bpt.scylla.model.process;
22

3-
import java.util.HashMap;
4-
import java.util.HashSet;
5-
import java.util.List;
6-
import java.util.Map;
7-
import java.util.Set;
3+
import java.util.*;
4+
import java.util.stream.Collectors;
85

96
import org.jdom2.Element;
107

@@ -122,6 +119,43 @@ public void setNodeIdInParent(Integer nodeIdInParent) {
122119
this.nodeIdInParent = nodeIdInParent;
123120
}
124121

122+
/**
123+
* Builds a identifier of a node which is unique across all levels of a BPMN process.
124+
*
125+
* @param nodeId
126+
* the identifier of the node
127+
* @return the identifier which is unique across all levels of the BPMN process
128+
*
129+
* TODO This method is only used for ProcessNodeInfo; consider replacing
130+
*/
131+
public String getRootProcessScopeNodeId(Integer nodeId) {
132+
String processScopeNodeId = nodeId.toString();
133+
ProcessModel processModel = this;
134+
while (processModel.getParent() != null) {
135+
Integer nodeIdInParent = processModel.getNodeIdInParent();
136+
processScopeNodeId = nodeIdInParent + "_" + processScopeNodeId;
137+
138+
processModel = processModel.getParent();
139+
}
140+
return processScopeNodeId;
141+
}
142+
143+
/**
144+
* Inverts {@link ProcessModel#getRootProcessScopeNodeId(Integer)}
145+
* @param nodeId
146+
* @return
147+
*/
148+
public String rootScopeIdToProcessElementId(String nodeId) {
149+
List<Integer> levelIds = Arrays.stream(nodeId.split("_")).map(Integer::parseInt).collect(Collectors.toList());
150+
ProcessModel contextModel = this;
151+
Integer id = levelIds.remove(0);
152+
for (Integer nextId : levelIds) {
153+
contextModel = contextModel.getSubProcesses().get(id);
154+
id = nextId;
155+
}
156+
return contextModel.getIdentifiers().get(id);
157+
}
158+
125159
public ProcessModel getParent() {
126160
return parent;
127161
}

src/main/java/de/hpi/bpt/scylla/plugin/batch/BatchCSVLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public void writeToLog(SimulationModel model, String outputPathWithoutExtension)
201201
batchActivity.clusterId = clusterId;
202202
/**Write information for all tasks inside cluster*/
203203
for(Integer taskId : tasksOfCluster) {
204-
BatchCSVEntry task = tasksOfProcessInstance.get(SimulationUtils.getProcessScopeNodeId(clusterSubProcess, taskId));
204+
BatchCSVEntry task = tasksOfProcessInstance.get(clusterSubProcess.getRootProcessScopeNodeId(taskId));
205205
if(task == null)continue; //Not all tasks are necessarily visited due to XOR-Gateways and similar
206206
task.batchNumber = batchNumber;
207207
task.batchType = batchType;

src/main/java/de/hpi/bpt/scylla/plugin/batch/ParallelBatchCluster.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void logBPMNEventForNonResponsiblePI(BPMNEvent event) {
106106

107107
String taskName = event.getDisplayName();
108108
int nodeId = event.getNodeId();
109-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
109+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
110110
String source = event.getSource();
111111

112112
int sourceSuffix = 0;
@@ -142,7 +142,7 @@ private void logTaskEventForNonResponsiblePI(TaskEvent event) throws ScyllaRunti
142142

143143
String taskName = event.getDisplayName();
144144
int nodeId = event.getNodeId();
145-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
145+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
146146
String source = event.getSource();
147147

148148
ProcessNodeTransitionType transition;

src/main/java/de/hpi/bpt/scylla/plugin/statslogger_nojar/StatisticsLogger.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import de.hpi.bpt.scylla.logger.ProcessNodeTransitionType;
1313
import de.hpi.bpt.scylla.logger.ResourceInfo;
1414
import de.hpi.bpt.scylla.logger.ResourceStatus;
15+
import de.hpi.bpt.scylla.model.process.ProcessModel;
1516
import de.hpi.bpt.scylla.plugin_type.logger.OutputLoggerPluggable;
1617
import de.hpi.bpt.scylla.simulation.ResourceObject;
1718
import de.hpi.bpt.scylla.simulation.SimulationModel;
@@ -33,7 +34,7 @@ public String getName() {
3334
}
3435

3536
public void writeToLog(SimulationModel model, String outputPathWithoutExtension) throws IOException {
36-
37+
3738
TimeUnit timeUnit = DateTimeUtils.getReferenceTimeUnit();
3839
double totalEndTime = model.presentTime().getTimeAsDouble(timeUnit);
3940
Map<String, Map<Integer, List<ProcessNodeInfo>>> processNodeInfos = model.getProcessNodeInfos();
@@ -352,8 +353,12 @@ else if (transition == ProcessNodeTransitionType.EVENT_BEGIN
352353

353354

354355
Map<String, Map<String, StatisticsTaskInstanceObject>> statsPerTaskOfProcess = statsPerTask.get(processId);
356+
ProcessModel rootProcessModel = model.getDesmojObjectsMap().get(processId).getProcessModel();
355357
// add activities
356358
for (String processScopeNodeId : statsPerTaskOfProcess.keySet()) {
359+
360+
361+
String originalId = rootProcessModel.rootScopeIdToProcessElementId(processScopeNodeId);
357362

358363
long taskDuration = 0;
359364
for (StatisticsTaskInstanceObject instance : statsPerTaskOfProcess.get(processScopeNodeId).values()) {
@@ -372,7 +377,7 @@ else if (transition == ProcessNodeTransitionType.EVENT_BEGIN
372377
Element activity = new Element("activity");
373378
processActivities.addContent(activity);
374379

375-
activity.addContent(new Element("id").setText(processScopeNodeId));
380+
activity.addContent(new Element("id").setText(originalId));
376381
Element activityName = new Element("name");
377382
Element activityCost = new Element("cost");
378383
Element activityTime = new Element("time");

src/main/java/de/hpi/bpt/scylla/simulation/event/BPMNEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected void addToLog(ProcessInstance processInstance) {
3434

3535
SimulationModel model = (SimulationModel) getModel();
3636
ProcessModel processModel = processInstance.getProcessModel();
37-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
37+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
3838

3939
ProcessNodeInfo info;
4040
info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
@@ -53,7 +53,7 @@ public void addToLogAsCanceled(ProcessInstance processInstance) {
5353

5454
SimulationModel model = (SimulationModel) getModel();
5555
ProcessModel processModel = processInstance.getProcessModel();
56-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
56+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
5757

5858
ProcessNodeInfo info;
5959
info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,

src/main/java/de/hpi/bpt/scylla/simulation/event/TaskBeginEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected void addToLog(ProcessInstance processInstance) {
127127

128128
SimulationModel model = (SimulationModel) getModel();
129129
ProcessModel processModel = processInstance.getProcessModel();
130-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
130+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
131131

132132
ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
133133
transition);

src/main/java/de/hpi/bpt/scylla/simulation/event/TaskCancelEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ protected void addToLog(ProcessInstance processInstance) {
118118

119119
SimulationModel model = (SimulationModel) getModel();
120120
ProcessModel processModel = processInstance.getProcessModel();
121-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
121+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
122122

123123
ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
124124
transition);

src/main/java/de/hpi/bpt/scylla/simulation/event/TaskEnableEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected void addToLog(ProcessInstance processInstance) {
130130

131131
SimulationModel model = (SimulationModel) getModel();
132132
ProcessModel processModel = processInstance.getProcessModel();
133-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
133+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
134134

135135
ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, getName(), timestamp, taskName, resources,
136136
transition);

src/main/java/de/hpi/bpt/scylla/simulation/event/TaskTerminateEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ protected void addToLog(ProcessInstance processInstance) {
139139

140140
if (!alreadyCanceled(model)) {
141141
ProcessModel processModel = processInstance.getProcessModel();
142-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
142+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
143143

144144
ProcessNodeInfo info = new ProcessNodeInfo(nodeId, processScopeNodeId, source, timestamp, taskName, resources,
145145
transition);

src/main/java/de/hpi/bpt/scylla/simulation/utils/DateTimeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public static TimeInstant getTaskTerminationTime(TimeSpan timeSpan, TimeInstant
327327
String source = event.getSource();
328328
String taskName = event.getDisplayName();
329329
int nodeId = event.getNodeId();
330-
String processScopeNodeId = SimulationUtils.getProcessScopeNodeId(processModel, nodeId);
330+
String processScopeNodeId = processModel.getRootProcessScopeNodeId(nodeId);
331331

332332
Set<String> resources = new HashSet<String>();
333333
Set<ResourceObject> resourceObjects = tuple.getResourceObjects();

0 commit comments

Comments
 (0)