|
19 | 19 | import java.io.File; |
20 | 20 | import java.io.FileWriter; |
21 | 21 | import java.io.IOException; |
| 22 | +import java.util.ArrayList; |
| 23 | +import java.util.HashSet; |
| 24 | +import java.util.List; |
| 25 | +import java.util.Set; |
22 | 26 |
|
23 | 27 | import org.iobserve.analysis.cdoruserbehavior.filter.models.CallInformation; |
| 28 | +import org.iobserve.analysis.cdoruserbehavior.filter.models.EntryCallEdge; |
24 | 29 | import org.iobserve.analysis.cdoruserbehavior.filter.models.EntryCallNode; |
25 | 30 |
|
26 | 31 | import teetime.framework.AbstractConsumerStage; |
@@ -49,7 +54,37 @@ protected void execute(final ComparisonResult result) throws IOException { |
49 | 54 | final FileWriter fw = new FileWriter(this.outputFile); |
50 | 55 | final BufferedWriter writer = new BufferedWriter(fw); |
51 | 56 |
|
52 | | - writer.write("= " + this.outputFile.getName() + " ="); |
| 57 | + final int baselineNodeCount = result.getBaselineNodes().size(); |
| 58 | + final int testModelNodeCount = result.getTestModelNodes().size(); |
| 59 | + final int missingNodeCount = result.getMissingNodes().size(); |
| 60 | + final int additionalNodeCount = result.getAdditionalNodes().size(); |
| 61 | + |
| 62 | + final int baselineEdgeCount = result.getBaselineEdges().size(); |
| 63 | + final int testModelEdgeCount = result.getTestModelEdges().size(); |
| 64 | + final int missingEdgeCount = result.getMissingEdgeCount(); |
| 65 | + final int additionalEdgeCount = result.getAdditionalEdgeCount(); |
| 66 | + |
| 67 | + writer.write("CP;" + this.outputFile.getName() + ";" + baselineNodeCount + ";" + baselineEdgeCount + ";" |
| 68 | + + testModelNodeCount + ";" + testModelEdgeCount + ";" + missingNodeCount + ";" + additionalNodeCount |
| 69 | + + ";" + missingEdgeCount + ";" + additionalEdgeCount + ";" |
| 70 | + + (double) missingNodeCount / (double) baselineNodeCount + ";" |
| 71 | + + (double) additionalNodeCount / (double) baselineNodeCount + ";" |
| 72 | + + (double) missingEdgeCount / (double) baselineEdgeCount + ";" |
| 73 | + + (double) additionalEdgeCount / (double) baselineEdgeCount + "\n"); |
| 74 | + |
| 75 | + final List<EntryCallNode> allNodes = this.createAllNodesList(result.getBaselineNodes(), |
| 76 | + result.getTestModelNodes()); |
| 77 | + final List<EntryCallEdge> allEdges = this.createAllEdgesList(result.getBaselineEdges(), |
| 78 | + result.getTestModelEdges()); |
| 79 | + |
| 80 | + this.generateNodeCallInformation(writer, "baseline;" + this.outputFile.getName() + ";", allNodes, |
| 81 | + result.getBaselineNodes()); |
| 82 | + this.generateNodeCallInformation(writer, "compared;" + this.outputFile.getName() + ";", allNodes, |
| 83 | + result.getTestModelNodes()); |
| 84 | + writer.write("baseline;------------------------------------------ edges\n"); |
| 85 | + writer.write("compared;------------------------------------------ edges\n"); |
| 86 | + this.generateEdges(writer, "baseline;" + this.outputFile.getName() + ";", allEdges, result.getBaselineEdges()); |
| 87 | + this.generateEdges(writer, "compared;" + this.outputFile.getName() + ";", allEdges, result.getTestModelEdges()); |
53 | 88 | writer.write("Nodes:\n\tmissing=" + result.getMissingNodes().size() + "\n\tadditional=" |
54 | 89 | + result.getAdditionalNodes().size() + "\n"); |
55 | 90 | for (final EntryCallNode node : result.getMissingNodes()) { |
@@ -86,4 +121,158 @@ protected void execute(final ComparisonResult result) throws IOException { |
86 | 121 | fw.close(); |
87 | 122 | } |
88 | 123 |
|
| 124 | + private List<EntryCallEdge> createAllEdgesList(List<EntryCallEdge> baselineEdges, |
| 125 | + List<EntryCallEdge> testModelEdges) { |
| 126 | + final List<EntryCallEdge> result = new ArrayList<>(); |
| 127 | + for (final EntryCallEdge edge : baselineEdges) { |
| 128 | + final EntryCallEdge duplicateEdge = new EntryCallEdge(); |
| 129 | + duplicateEdge.setCalls(edge.getCalls()); |
| 130 | + duplicateEdge.setSource(edge.getSource()); |
| 131 | + duplicateEdge.setTarget(edge.getTarget()); |
| 132 | + result.add(duplicateEdge); |
| 133 | + } |
| 134 | + |
| 135 | + for (final EntryCallEdge edge : testModelEdges) { |
| 136 | + if (!this.edgeExists(baselineEdges, edge)) { |
| 137 | + result.add(edge); |
| 138 | + } else { |
| 139 | + final EntryCallEdge duplicateEdge = this.findEdge(result, edge); |
| 140 | + duplicateEdge.addCalls(edge.getCalls()); |
| 141 | + } |
| 142 | + } |
| 143 | + return result; |
| 144 | + } |
| 145 | + |
| 146 | + private boolean edgeExists(List<EntryCallEdge> edges, EntryCallEdge findEdge) { |
| 147 | + if (this.findEdge(edges, findEdge) != null) { |
| 148 | + return true; |
| 149 | + } else { |
| 150 | + return false; |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + private EntryCallEdge findEdge(List<EntryCallEdge> edges, EntryCallEdge findEdge) { |
| 155 | + for (final EntryCallEdge edge : edges) { |
| 156 | + if (findEdge.getSource().getSignature().equals(edge.getSource().getSignature()) |
| 157 | + && findEdge.getTarget().getSignature().equals(edge.getTarget().getSignature())) { |
| 158 | + return edge; |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + return null; |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Get all nodes used in this comparison. |
| 167 | + * |
| 168 | + * @param baselineNodes |
| 169 | + * @param testModelNodes |
| 170 | + * @return |
| 171 | + */ |
| 172 | + private List<EntryCallNode> createAllNodesList(List<EntryCallNode> baselineNodes, |
| 173 | + List<EntryCallNode> testModelNodes) { |
| 174 | + final List<EntryCallNode> result = new ArrayList<>(); |
| 175 | + result.addAll(baselineNodes); |
| 176 | + for (final EntryCallNode node : testModelNodes) { |
| 177 | + if (!this.nodeExists(baselineNodes, node)) { |
| 178 | + result.add(node); |
| 179 | + } |
| 180 | + } |
| 181 | + return result; |
| 182 | + } |
| 183 | + |
| 184 | + private boolean nodeExists(List<EntryCallNode> nodes, EntryCallNode findNode) { |
| 185 | + if (this.findNode(nodes, findNode) != null) { |
| 186 | + return true; |
| 187 | + } else { |
| 188 | + return false; |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + private EntryCallNode findNode(List<EntryCallNode> nodes, EntryCallNode findNode) { |
| 193 | + for (final EntryCallNode node : nodes) { |
| 194 | + if (findNode.getSignature().equals(node.getSignature())) { |
| 195 | + return node; |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + return null; |
| 200 | + } |
| 201 | + |
| 202 | + private void generateNodeCallInformation(BufferedWriter writer, String prefix, List<EntryCallNode> allNodes, |
| 203 | + List<EntryCallNode> selectedNodes) throws IOException { |
| 204 | + for (final EntryCallNode referenceNode : allNodes) { |
| 205 | + final EntryCallNode printNode = this.findNode(selectedNodes, referenceNode); |
| 206 | + if (printNode != null) { |
| 207 | + final Set<CallInformation> allEntryCallInformation = this.generateAllEntryCallInformationList( |
| 208 | + referenceNode.getEntryCallInformation(), printNode.getEntryCallInformation()); |
| 209 | + writer.write(prefix + printNode.getSignature().substring(18) + "\n"); |
| 210 | + this.generateCallInformation(writer, prefix + "\t", allEntryCallInformation, |
| 211 | + printNode.getEntryCallInformation()); |
| 212 | + } else { |
| 213 | + writer.write(prefix + " -- \n"); |
| 214 | + } |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + private Set<CallInformation> generateAllEntryCallInformationList(Set<CallInformation> entryCallInformation, |
| 219 | + Set<CallInformation> supplementalCallInfo) { |
| 220 | + final Set<CallInformation> allEntryCallInformation = new HashSet<>(); |
| 221 | + allEntryCallInformation.addAll(entryCallInformation); |
| 222 | + for (final CallInformation information : supplementalCallInfo) { |
| 223 | + boolean exists = false; |
| 224 | + for (final CallInformation referenceInfo : allEntryCallInformation) { |
| 225 | + if (referenceInfo.getInformationSignature().equals(information.getInformationSignature()) |
| 226 | + && referenceInfo.getInformationCode() == information.getInformationCode()) { |
| 227 | + exists = true; |
| 228 | + } |
| 229 | + } |
| 230 | + if (!exists) { |
| 231 | + allEntryCallInformation.add(information); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + return allEntryCallInformation; |
| 236 | + } |
| 237 | + |
| 238 | + private void generateCallInformation(BufferedWriter writer, String prefix, |
| 239 | + Set<CallInformation> allEntryCallInformation, Set<CallInformation> entryCallInformation) |
| 240 | + throws IOException { |
| 241 | + |
| 242 | + for (final CallInformation information : allEntryCallInformation) { |
| 243 | + if (this.isContainedIn(entryCallInformation, information)) { |
| 244 | + writer.write( |
| 245 | + prefix + information.getInformationSignature() + "=" + information.getInformationCode() + "\n"); |
| 246 | + } else { |
| 247 | + writer.write(prefix + information.getInformationSignature() + "---\n"); |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + |
| 252 | + private boolean isContainedIn(Set<CallInformation> entryCallInformation, CallInformation information) { |
| 253 | + for (final CallInformation referenceInfo : entryCallInformation) { |
| 254 | + if (referenceInfo.getInformationSignature().equals(information.getInformationSignature()) |
| 255 | + && referenceInfo.getInformationCode() == information.getInformationCode()) { |
| 256 | + return true; |
| 257 | + } |
| 258 | + } |
| 259 | + return false; |
| 260 | + } |
| 261 | + |
| 262 | + private void generateEdges(BufferedWriter writer, String prefix, List<EntryCallEdge> allEdges, |
| 263 | + List<EntryCallEdge> selectedEdges) throws IOException { |
| 264 | + for (final EntryCallEdge referenceEdge : allEdges) { |
| 265 | + final EntryCallEdge printEdge = this.findEdge(selectedEdges, referenceEdge); |
| 266 | + if (printEdge != null) { |
| 267 | + writer.write(prefix + printEdge.getSource().getSignature().substring(18) + " -- " + printEdge.getCalls() |
| 268 | + + ":" + referenceEdge.getCalls() + " -> " + printEdge.getTarget().getSignature().substring(18) |
| 269 | + + "\n"); |
| 270 | + } else { |
| 271 | + writer.write(prefix + referenceEdge.getSource().getSignature().substring(18) + " -- " + "X" + ":" |
| 272 | + + referenceEdge.getCalls() + " -> " + referenceEdge.getTarget().getSignature().substring(18) |
| 273 | + + "\n"); |
| 274 | + } |
| 275 | + } |
| 276 | + } |
| 277 | + |
89 | 278 | } |
0 commit comments