- Timestamp:
- 08/24/16 09:58:25 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/TaskTreePlotUtils.java
r2061 r2128 28 28 import java.util.Map; 29 29 import java.util.Set; 30 import java.util.TreeMap;31 30 32 31 import org.jfree.chart.ChartFactory; … … 57 56 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 58 57 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 59 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo;60 58 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 61 59 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 62 import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric;63 60 import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeUtils; 64 61 … … 101 98 102 99 if (TASK_COUNT__EVENT_COVERAGE_PLOT.equals(name)) { 103 XYDataset dataset1 = createTaskCountEventCoveragePlotDataSet(models.get(0)); 100 XYDataset dataset1 = createTaskCountEventCoveragePlotDataSet(models.get(0), 101 modelNames.get(0)); 104 102 105 103 chart = ChartFactory.createXYLineChart 106 (TASK_COUNT__EVENT_COVERAGE_PLOT, "task counts", "event coverage", 104 (TASK_COUNT__EVENT_COVERAGE_PLOT, "Sequences ordered by coverage in % of sequences", 105 "action instances in % of all recorded action instances covered by the sequence", 107 106 dataset1, PlotOrientation.VERTICAL, models.size() > 1, false, false); 108 107 109 108 for (int i = 1; i < models.size(); i++) { 110 109 chart.getXYPlot().setDataset 111 (i, createTaskCountEventCoveragePlotDataSet(models.get(i))); 110 (i, createTaskCountEventCoveragePlotDataSet(models.get(i), 111 modelNames.get(i))); 112 112 } 113 113 114 114 XYPlot plot = chart.getXYPlot(); 115 NumberAxis domainAxis = new LogarithmicAxis("task counts"); 116 NumberAxis rangeAxis = new LogarithmicAxis("event coverage"); 115 plot.setBackgroundPaint(java.awt.Color.WHITE); 116 plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); 117 118 XYLineAndShapeRenderer scatterRenderer = new XYLineAndShapeRenderer(false, true); 119 scatterRenderer.setSeriesShapesFilled(0, false); 120 scatterRenderer.setSeriesShape(0, new Ellipse2D.Float(-3.0f, -3.0f, 6.0f, 6.0f)); 121 scatterRenderer.setSeriesPaint(0, colors[0]); 122 plot.setRenderer(0, scatterRenderer); 123 124 for (int i = 1; i < models.size(); i++) { 125 chart.getXYPlot().setDataset 126 (i, createOrderedTaskCountPlotDataSet(models.get(i), modelNames.get(i))); 127 128 scatterRenderer = new XYLineAndShapeRenderer(false, true); 129 scatterRenderer.setSeriesShapesFilled(0, false); 130 scatterRenderer.setSeriesShape(0, new Ellipse2D.Float(-3.0f, -3.0f, 6.0f, 6.0f)); 131 scatterRenderer.setSeriesPaint(0, colors[i]); 132 plot.setRenderer(i, scatterRenderer); 133 } 134 135 NumberAxis domainAxis = new NumberAxis 136 ("Sequences ordered by coverage in % of sequences"); 137 138 domainAxis.setUpperBound(100); 117 139 plot.setDomainAxis(domainAxis); 140 141 NumberAxis rangeAxis = new LogarithmicAxis 142 ("action instances in % of all recorded action instances covered by the sequence"); 143 144 rangeAxis.setAutoRange(true); 118 145 plot.setRangeAxis(rangeAxis); 119 146 } … … 285 312 * 286 313 */ 287 private static XYDataset createTaskCountEventCoveragePlotDataSet(ITaskModel taskModel) { 288 // tree maps required to have sorted maps 289 TreeMap<Integer, Integer> minValues = new TreeMap<>(); 290 TreeMap<Integer, List<Integer>> allValues = new TreeMap<>(); 291 TreeMap<Integer, Integer> maxValues = new TreeMap<>(); 314 private static XYDataset createTaskCountEventCoveragePlotDataSet(ITaskModel taskModel, 315 String taskModelName) 316 { 317 Map<Integer, List<ISequence>> coverageCounts = new HashMap<>(); 318 Map<ISequence, Set<IEventTaskInstance>> coverages = new HashMap<>(); 319 Set<IEventTaskInstance> allEvents = new HashSet<>(); 320 int maxCoverage = 0; 292 321 293 322 for (ITask task : taskModel.getTasks()) { 294 323 if (task instanceof ISequence) { 295 ITaskInfo info = taskModel.getTaskInfo(task); 296 int count = task.getInstances().size(); 297 int eventCoverage = info.getMeasureValue(TaskMetric.EVENT_COVERAGE); 298 299 Integer minValue = minValues.get(count); 300 301 if ((minValue == null) || (minValue > eventCoverage)) { 302 minValues.put(count, eventCoverage); 303 } 304 305 Integer maxValue = maxValues.get(count); 306 307 if ((maxValue == null) || (maxValue < eventCoverage)) { 308 maxValues.put(count, eventCoverage); 309 } 310 311 List<Integer> values = allValues.get(count); 312 313 if (values == null) { 314 values = new LinkedList<Integer>(); 315 allValues.put(count, values); 316 } 317 318 values.add(eventCoverage); 324 final Set<IEventTaskInstance> coveredEvents = new HashSet<>(); 325 326 for (ITaskInstance instance : task.getInstances()) { 327 instance.accept(new DefaultTaskInstanceTraversingVisitor() { 328 @Override 329 public void visit(IEventTaskInstance eventTaskInstance) { 330 coveredEvents.add(eventTaskInstance); 331 } 332 }); 333 } 334 335 coverages.put((ISequence) task, coveredEvents); 336 337 List<ISequence> tasksWithSameCoverage = coverageCounts.get(coveredEvents.size()); 338 339 if (tasksWithSameCoverage == null) { 340 tasksWithSameCoverage = new LinkedList<>(); 341 coverageCounts.put(coveredEvents.size(), tasksWithSameCoverage); 342 } 343 344 tasksWithSameCoverage.add((ISequence) task); 345 346 maxCoverage = Math.max(maxCoverage, coveredEvents.size()); 347 } 348 else if (task instanceof IEventTask) { 349 for (ITaskInstance instance : task.getInstances()) { 350 allEvents.add((IEventTaskInstance) instance); 351 } 352 } 353 } 354 355 XYSeries countSeries = new XYSeries(taskModelName, true, false); 356 357 // entries are correctly sorted due to the map 358 int sequenceIndex = 1; 359 360 for (int i = maxCoverage; i > 0; i--) { 361 List<ISequence> sequencesWithSameCoverage = coverageCounts.get(i); 362 363 if (sequencesWithSameCoverage == null) { 364 continue; 365 } 366 367 for (ISequence sequence : sequencesWithSameCoverage) { 368 double xvalue = (double) 100 * sequenceIndex / coverages.size(); 369 double yvalue = (double) 100 * coverages.get(sequence).size() / allEvents.size(); 370 countSeries.add(xvalue, yvalue); 371 sequenceIndex++; 319 372 } 320 373 } 321 374 322 375 DefaultTableXYDataset dataset = new DefaultTableXYDataset(); 323 XYSeries minSeries = new XYSeries("min values", true, false); 324 XYSeries avgSeries = new XYSeries("avg values", true, false); 325 XYSeries maxSeries = new XYSeries("max values", true, false); 326 327 // entries are correctly sorted due to the map 328 for (Map.Entry<Integer, List<Integer>> entry : allValues.entrySet()) { 329 int count = entry.getKey(); 330 331 minSeries.add(count, minValues.get(count)); 332 maxSeries.add(count, maxValues.get(count)); 333 334 avgSeries.add(count, getAverage(entry.getValue())); 335 } 336 337 dataset.addSeries(minSeries); 338 dataset.addSeries(avgSeries); 339 dataset.addSeries(maxSeries); 376 dataset.addSeries(countSeries); 340 377 return dataset; 341 378 } … … 474 511 } 475 512 476 477 /**478 *479 */480 private static double getAverage(List<Integer> values) {481 int all = 0;482 483 for (Integer value : values) {484 all += value;485 }486 487 return ((double) all) / values.size();488 }489 513 }
Note: See TracChangeset
for help on using the changeset viewer.