[1769] | 1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
| 2 | //
|
---|
| 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 4 | // you may not use this file except in compliance with the License.
|
---|
| 5 | // You may obtain a copy of the License at
|
---|
| 6 | //
|
---|
| 7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 8 | //
|
---|
| 9 | // Unless required by applicable law or agreed to in writing, software
|
---|
| 10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 12 | // See the License for the specific language governing permissions and
|
---|
| 13 | // limitations under the License.
|
---|
| 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.commands.usability;
|
---|
| 16 |
|
---|
| 17 | import java.util.HashSet;
|
---|
| 18 | import java.util.List;
|
---|
| 19 | import java.util.Set;
|
---|
| 20 |
|
---|
| 21 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 22 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor;
|
---|
| 23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
| 24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
|
---|
[1886] | 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
|
---|
| 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional;
|
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection;
|
---|
| 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
|
---|
[1769] | 29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
| 30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
|
---|
| 31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric;
|
---|
| 33 | import de.ugoe.cs.util.console.Command;
|
---|
| 34 | import de.ugoe.cs.util.console.Console;
|
---|
| 35 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 36 |
|
---|
| 37 | /**
|
---|
| 38 | * <p>
|
---|
| 39 | * This command provides statistical information about a given task tree.
|
---|
| 40 | * </p>
|
---|
| 41 | *
|
---|
| 42 | * @author Patrick Harms
|
---|
| 43 | * @version 1.0
|
---|
| 44 | */
|
---|
| 45 | public class CMDtaskTreeStatistics implements Command {
|
---|
| 46 |
|
---|
| 47 | /*
|
---|
| 48 | * (non-Javadoc)
|
---|
| 49 | *
|
---|
| 50 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 51 | */
|
---|
| 52 | @Override
|
---|
| 53 | public String help() {
|
---|
| 54 | return "taskTreeStatistics <tasktree>";
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /*
|
---|
| 58 | * (non-Javadoc)
|
---|
| 59 | *
|
---|
| 60 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 61 | */
|
---|
| 62 | @Override
|
---|
| 63 | public void run(List<Object> parameters) {
|
---|
| 64 | String tasktreeName;
|
---|
| 65 | try {
|
---|
| 66 | tasktreeName = (String) parameters.get(0);
|
---|
| 67 | }
|
---|
| 68 | catch (Exception e) {
|
---|
| 69 | throw new IllegalArgumentException("must provide a task tree name");
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | Object dataObject = GlobalDataContainer.getInstance().getData(tasktreeName);
|
---|
| 73 | if (dataObject == null) {
|
---|
| 74 | CommandHelpers.objectNotFoundMessage(tasktreeName);
|
---|
| 75 | return;
|
---|
| 76 | }
|
---|
| 77 | if (!(dataObject instanceof ITaskModel)) {
|
---|
| 78 | CommandHelpers.objectNotType(tasktreeName, "ITaskModel");
|
---|
| 79 | return;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | ITaskModel taskModel = (ITaskModel) dataObject;
|
---|
| 83 |
|
---|
| 84 | int taskCount = 0;
|
---|
| 85 | int allTasks = taskModel.getTasks().size();
|
---|
| 86 | Set<IEventTaskInstance> coveredEvents = new HashSet<IEventTaskInstance>();
|
---|
| 87 | int allEvents = 0;
|
---|
| 88 |
|
---|
[1886] | 89 | int noOfEventTasks = 0;
|
---|
| 90 | int noOfSequences = 0;
|
---|
| 91 | int noOfIterations = 0;
|
---|
| 92 | int noOfSelections = 0;
|
---|
| 93 | int noOfOptionals = 0;
|
---|
| 94 |
|
---|
[1769] | 95 | for (ITask task : taskModel.getTasks()) {
|
---|
| 96 | int covQuant =
|
---|
| 97 | taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE_QUANTILE);
|
---|
| 98 |
|
---|
| 99 | if (covQuant >= 950) {
|
---|
| 100 | taskCount++;
|
---|
| 101 | getCoveredEvents(task, coveredEvents);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | if (task instanceof IEventTask) {
|
---|
[1886] | 105 | noOfEventTasks++;
|
---|
[1769] | 106 | allEvents += task.getInstances().size();
|
---|
| 107 | }
|
---|
[1886] | 108 | else if (task instanceof ISequence) {
|
---|
| 109 | noOfSequences++;
|
---|
| 110 | }
|
---|
| 111 | else if (task instanceof IIteration) {
|
---|
| 112 | noOfIterations++;
|
---|
| 113 | }
|
---|
| 114 | else if (task instanceof ISelection) {
|
---|
| 115 | noOfSelections++;
|
---|
| 116 | }
|
---|
| 117 | else if (task instanceof IOptional) {
|
---|
| 118 | noOfOptionals++;
|
---|
| 119 | }
|
---|
[1769] | 120 | }
|
---|
| 121 |
|
---|
[1886] | 122 | Console.println(noOfEventTasks + " eventTasks, " + noOfSequences + " sequences, " +
|
---|
| 123 | noOfIterations + " iterations, " + noOfSelections + " selections, " +
|
---|
| 124 | noOfOptionals + " optionals");
|
---|
[1769] | 125 | Console.println(taskCount + " of " + allTasks + " tasks (" + (taskCount * 100 / allTasks) +
|
---|
| 126 | "%) covered " + coveredEvents.size() + " of " + allEvents +
|
---|
| 127 | " recorded events (" + (coveredEvents.size() * 100 / allEvents) + "%)");
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /**
|
---|
| 131 | * <p>
|
---|
| 132 | * convenience method to determine the number of covered events by a task
|
---|
| 133 | * </p>
|
---|
| 134 | *
|
---|
| 135 | * @param task the task to count the covered events for
|
---|
| 136 | * @param coveredEvents the events covered by the task (in/out parameter)
|
---|
| 137 | */
|
---|
| 138 | private void getCoveredEvents(ITask task, final Set<IEventTaskInstance> coveredEvents) {
|
---|
| 139 | for (ITaskInstance instance : task.getInstances()) {
|
---|
| 140 | instance.accept(new DefaultTaskInstanceTraversingVisitor() {
|
---|
| 141 | @Override
|
---|
| 142 | public void visit(IEventTaskInstance eventTaskInstance) {
|
---|
| 143 | coveredEvents.add(eventTaskInstance);
|
---|
| 144 | }
|
---|
| 145 | });
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | }
|
---|