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.usability; |
---|
16 | |
---|
17 | import java.util.ArrayList; |
---|
18 | import java.util.HashMap; |
---|
19 | import java.util.LinkedList; |
---|
20 | import java.util.List; |
---|
21 | import java.util.ListIterator; |
---|
22 | import java.util.Map; |
---|
23 | import java.util.logging.Level; |
---|
24 | |
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
29 | import de.ugoe.cs.util.console.Console; |
---|
30 | |
---|
31 | /** |
---|
32 | * TODO comment |
---|
33 | * |
---|
34 | * @version $Revision: $ $Date: 16.07.2012$ |
---|
35 | * @author 2012, last modified by $Author: pharms$ |
---|
36 | */ |
---|
37 | public class UsabilityEvaluationManager { |
---|
38 | |
---|
39 | /** */ |
---|
40 | private List<UsabilityEvaluationRule> rules = new ArrayList<UsabilityEvaluationRule>(); |
---|
41 | |
---|
42 | /** |
---|
43 | * |
---|
44 | */ |
---|
45 | public UsabilityEvaluationManager() { |
---|
46 | super(); |
---|
47 | init(); |
---|
48 | } |
---|
49 | |
---|
50 | /** |
---|
51 | * |
---|
52 | */ |
---|
53 | private void init() { |
---|
54 | // rules.add(new TaskTreeTestRule()); |
---|
55 | |
---|
56 | rules.add(new EventCoverageRatioRule()); |
---|
57 | rules.add(new RequiredInefficientActionsRule()); |
---|
58 | rules.add(new TargetDistanceRule()); |
---|
59 | rules.add(new MissingFeedbackRule()); |
---|
60 | rules.add(new DataEntryMethodChangeRule()); |
---|
61 | rules.add(new CommonTaskRateRule()); |
---|
62 | rules.add(new TextInputStatisticsRule()); |
---|
63 | rules.add(new CheckBoxMultipleSelectionRule()); |
---|
64 | rules.add(new MisleadingClickCueRule()); |
---|
65 | rules.add(new DefaultCursorPositioningRule()); |
---|
66 | rules.add(new DefaultValueRule()); |
---|
67 | rules.add(new UnusedGUIElementsRule()); |
---|
68 | |
---|
69 | // rules.add(new TaskCooccurrenceRule()); |
---|
70 | } |
---|
71 | |
---|
72 | /** |
---|
73 | * |
---|
74 | */ |
---|
75 | public UsabilityEvaluationResult evaluateUsability(ITaskModel taskModel, int maxCount) { |
---|
76 | Console.traceln(Level.INFO, "evaluating usability of task model " + taskModel); |
---|
77 | |
---|
78 | List<UsabilityEvaluationResult> interimResults = new ArrayList<UsabilityEvaluationResult>(); |
---|
79 | |
---|
80 | for (UsabilityEvaluationRule rule : rules) { |
---|
81 | Console.traceln(Level.INFO, "\napplying rule " + rule.getClass().getSimpleName()); |
---|
82 | UsabilityEvaluationResult result = rule.evaluate(taskModel); |
---|
83 | |
---|
84 | Map<String, List<UsabilitySmell>> smellGroups = new HashMap<>(); |
---|
85 | |
---|
86 | for (UsabilitySmell smell : result.getAllSmells()) { |
---|
87 | List<UsabilitySmell> smellGroup = smellGroups.get(smell.getBriefDescription()); |
---|
88 | |
---|
89 | if (smellGroup == null) { |
---|
90 | smellGroup = new LinkedList<>(); |
---|
91 | smellGroups.put(smell.getBriefDescription(), smellGroup); |
---|
92 | } |
---|
93 | |
---|
94 | smellGroup.add(smell); |
---|
95 | } |
---|
96 | |
---|
97 | for (Map.Entry<String, List<UsabilitySmell>> smellGroup : smellGroups.entrySet()) { |
---|
98 | Console.traceln(Level.INFO, "the rule found " + smellGroup.getValue().size() + |
---|
99 | " usability smells of type \"" + smellGroup.getKey() + "\""); |
---|
100 | |
---|
101 | result = new UsabilityEvaluationResult(taskModel, smellGroup.getValue()); |
---|
102 | |
---|
103 | checkDuplicates(result); |
---|
104 | |
---|
105 | if (maxCount < result.getAllSmells().size()) { |
---|
106 | Console.traceln(Level.INFO, "filtering for " + maxCount + |
---|
107 | " smells of same type with highest event coverage."); |
---|
108 | |
---|
109 | LinkedList<UsabilitySmell> sortedSmells = new LinkedList<>(); |
---|
110 | |
---|
111 | for (UsabilitySmell smell : result.getAllSmells()) { |
---|
112 | ListIterator<UsabilitySmell> iterator = sortedSmells.listIterator(); |
---|
113 | |
---|
114 | boolean added = false; |
---|
115 | |
---|
116 | while (iterator.hasNext()) { |
---|
117 | if (iterator.next().getIntensity().getEventCoverage() < |
---|
118 | smell.getIntensity().getEventCoverage()) |
---|
119 | { |
---|
120 | iterator.previous(); |
---|
121 | iterator.add(smell); |
---|
122 | added = true; |
---|
123 | break; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | if (!added) { |
---|
128 | sortedSmells.add(smell); |
---|
129 | } |
---|
130 | |
---|
131 | while (sortedSmells.size() > maxCount) { |
---|
132 | sortedSmells.removeLast(); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | result = new UsabilityEvaluationResult(taskModel, sortedSmells); |
---|
137 | checkDuplicates(result); |
---|
138 | } |
---|
139 | |
---|
140 | interimResults.add(result); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | UsabilityEvaluationResult result = new UsabilityEvaluationResult(taskModel, interimResults); |
---|
145 | Console.println("the evaluation result contains " + result.getAllSmells().size() + |
---|
146 | " smells."); |
---|
147 | |
---|
148 | return result; |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * |
---|
153 | */ |
---|
154 | private void checkDuplicates(UsabilityEvaluationResult result) { |
---|
155 | List<ITask> referredTasks = new ArrayList<ITask>(); |
---|
156 | |
---|
157 | for (UsabilitySmell smell : result.getAllSmells()) { |
---|
158 | if (smell.getSmellingTask() != null) { |
---|
159 | referredTasks.add(smell.getSmellingTask()); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | int counter = 0; |
---|
164 | for (int i = 0; i < referredTasks.size(); i++) { |
---|
165 | for (int j = 0; j < referredTasks.size(); j++) { |
---|
166 | if (isChildOf(referredTasks.get(i), referredTasks.get(j))) { |
---|
167 | counter++; |
---|
168 | break; |
---|
169 | } |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | if (counter > 0) { |
---|
174 | Console.traceln(Level.INFO, counter + " of the findings are duplicates in " + |
---|
175 | "that they refer to tasks whose parent tasks are also " + |
---|
176 | "referred by the findings"); |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * |
---|
182 | */ |
---|
183 | private boolean isChildOf(final ITask potChild, ITask potParent) { |
---|
184 | |
---|
185 | if (potParent instanceof IStructuringTemporalRelationship) { |
---|
186 | for (ITask child : ((IStructuringTemporalRelationship) potParent).getChildren()) { |
---|
187 | if ((child == potChild) || isChildOf(potChild, child)) { |
---|
188 | return true; |
---|
189 | } |
---|
190 | } |
---|
191 | } |
---|
192 | else if (potParent instanceof IMarkingTemporalRelationship) { |
---|
193 | ITask child = ((IMarkingTemporalRelationship) potParent).getMarkedTask(); |
---|
194 | if ((child == potChild) || isChildOf(potChild, child)) { |
---|
195 | return true; |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | return false; |
---|
200 | } |
---|
201 | |
---|
202 | } |
---|