source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDtaskTreeStatistics.java @ 1769

Last change on this file since 1769 was 1769, checked in by pharms, 10 years ago
  • added command for task tree statistics
File size: 4.3 KB
Line 
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
15package de.ugoe.cs.autoquest.commands.usability;
16
17import java.util.HashSet;
18import java.util.List;
19import java.util.Set;
20
21import de.ugoe.cs.autoquest.CommandHelpers;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor;
23import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric;
29import de.ugoe.cs.util.console.Command;
30import de.ugoe.cs.util.console.Console;
31import de.ugoe.cs.util.console.GlobalDataContainer;
32
33/**
34 * <p>
35 * This command provides statistical information about a given task tree.
36 * </p>
37 *
38 * @author Patrick Harms
39 * @version 1.0
40 */
41public class CMDtaskTreeStatistics implements Command {
42
43    /*
44     * (non-Javadoc)
45     *
46     * @see de.ugoe.cs.util.console.Command#help()
47     */
48    @Override
49    public String help() {
50        return "taskTreeStatistics <tasktree>";
51    }
52
53    /*
54     * (non-Javadoc)
55     *
56     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
57     */
58    @Override
59    public void run(List<Object> parameters) {
60        String tasktreeName;
61        try {
62            tasktreeName = (String) parameters.get(0);
63        }
64        catch (Exception e) {
65            throw new IllegalArgumentException("must provide a task tree name");
66        }
67
68        Object dataObject = GlobalDataContainer.getInstance().getData(tasktreeName);
69        if (dataObject == null) {
70            CommandHelpers.objectNotFoundMessage(tasktreeName);
71            return;
72        }
73        if (!(dataObject instanceof ITaskModel)) {
74            CommandHelpers.objectNotType(tasktreeName, "ITaskModel");
75            return;
76        }
77
78        ITaskModel taskModel = (ITaskModel) dataObject;
79
80        int taskCount = 0;
81        int allTasks = taskModel.getTasks().size();
82        Set<IEventTaskInstance> coveredEvents = new HashSet<IEventTaskInstance>();
83        int allEvents = 0;
84       
85        for (ITask task : taskModel.getTasks()) {
86            int covQuant =
87                taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE_QUANTILE);
88           
89            if (covQuant >= 950) {
90                taskCount++;
91                getCoveredEvents(task, coveredEvents);
92            }
93           
94            if (task instanceof IEventTask) {
95                allEvents += task.getInstances().size();
96            }
97        }
98       
99        Console.println(taskCount + " of " + allTasks + " tasks (" + (taskCount * 100 / allTasks) +
100                        "%) covered " + coveredEvents.size() + " of " + allEvents +
101                        " recorded events (" + (coveredEvents.size() * 100 / allEvents) + "%)");
102    }
103
104    /**
105     * <p>
106     * convenience method to determine the number of covered events by a task
107     * </p>
108     *
109     * @param task          the task to count the covered events for
110     * @param coveredEvents the events covered by the task (in/out parameter)
111     */
112    private void getCoveredEvents(ITask task, final Set<IEventTaskInstance> coveredEvents) {
113        for (ITaskInstance instance : task.getInstances()) {
114            instance.accept(new DefaultTaskInstanceTraversingVisitor() {
115                @Override
116                public void visit(IEventTaskInstance eventTaskInstance) {
117                    coveredEvents.add(eventTaskInstance);
118                }
119            });
120        }
121    }
122
123}
Note: See TracBrowser for help on using the repository browser.