[1918] | 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 | |
---|
[2042] | 17 | import java.util.ArrayList; |
---|
[1918] | 18 | import java.util.Collection; |
---|
| 19 | import java.util.HashMap; |
---|
| 20 | import java.util.HashSet; |
---|
[2042] | 21 | import java.util.LinkedList; |
---|
[1918] | 22 | import java.util.List; |
---|
| 23 | import java.util.Map; |
---|
| 24 | import java.util.Set; |
---|
| 25 | |
---|
[2042] | 26 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
| 27 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; |
---|
| 28 | import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; |
---|
[1918] | 29 | import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox; |
---|
| 30 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
[2042] | 31 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; |
---|
| 32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; |
---|
[1918] | 33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
| 34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
| 35 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 36 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 37 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
[2042] | 38 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
[1918] | 39 | |
---|
| 40 | /** |
---|
| 41 | * TODO comment |
---|
| 42 | * |
---|
| 43 | * @version $Revision: $ $Date: 16.07.2012$ |
---|
| 44 | * @author 2012, last modified by $Author: pharms$ |
---|
| 45 | */ |
---|
| 46 | public class CheckBoxMultipleSelectionRule implements UsabilityEvaluationRule { |
---|
| 47 | |
---|
| 48 | /* |
---|
| 49 | * (non-Javadoc) |
---|
| 50 | * |
---|
| 51 | * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree) |
---|
| 52 | */ |
---|
| 53 | @Override |
---|
| 54 | public UsabilityEvaluationResult evaluate(ITaskModel taskModel) { |
---|
| 55 | ValueChangeStatistics statistics = new ValueChangeStatistics(); |
---|
| 56 | |
---|
| 57 | calculateStatistics(taskModel.getTasks(), statistics); |
---|
| 58 | |
---|
| 59 | statistics.condenseCheckBoxGroups(); |
---|
| 60 | |
---|
| 61 | UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel); |
---|
| 62 | analyzeStatistics(statistics, taskModel, results); |
---|
| 63 | |
---|
| 64 | return results; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | /** |
---|
| 68 | * |
---|
| 69 | */ |
---|
| 70 | private void analyzeStatistics(ValueChangeStatistics statistics, |
---|
| 71 | ITaskModel taskModel, |
---|
| 72 | UsabilityEvaluationResult results) |
---|
| 73 | { |
---|
[2042] | 74 | System.out.println("\n\n########################################\n"); |
---|
| 75 | final List<List<IEventTaskInstance>> actionInstancesInSameView = new LinkedList<>(); |
---|
[1918] | 76 | |
---|
[2042] | 77 | for (IUserSession session : taskModel.getUserSessions()) { |
---|
| 78 | for (ITaskInstance instance : session) { |
---|
| 79 | final LinkedList<IEventTaskInstance> currentList = new LinkedList<>(); |
---|
[1918] | 80 | |
---|
[2042] | 81 | instance.accept(new DefaultTaskInstanceTraversingVisitor() { |
---|
| 82 | @Override |
---|
| 83 | public void visit(IEventTaskInstance eventTaskInstance) { |
---|
| 84 | if (eventTaskInstance.getEvent().getTarget() instanceof IGUIElement) { |
---|
| 85 | IEventTarget target = eventTaskInstance.getEvent().getTarget(); |
---|
| 86 | IGUIView currentView = ((IGUIElement) target).getView(); |
---|
| 87 | |
---|
| 88 | IGUIView previousView = null; |
---|
| 89 | if (currentList.size() > 0) { |
---|
| 90 | target = currentList.getLast().getEvent().getTarget(); |
---|
| 91 | previousView = ((IGUIElement) target).getView(); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | if ((previousView == currentView) || |
---|
| 95 | ((previousView != null) && (previousView.equals(currentView)))) |
---|
| 96 | { |
---|
| 97 | currentList.add(eventTaskInstance); |
---|
| 98 | } |
---|
| 99 | else { |
---|
| 100 | if (currentList.size() > 0) { |
---|
| 101 | actionInstancesInSameView.add(new ArrayList<>(currentList)); |
---|
| 102 | } |
---|
| 103 | currentList.clear(); |
---|
| 104 | currentList.add(eventTaskInstance); |
---|
| 105 | } |
---|
| 106 | } |
---|
[1918] | 107 | } |
---|
[2042] | 108 | }); |
---|
[1918] | 109 | |
---|
[2042] | 110 | if (currentList.size() > 0) { |
---|
| 111 | actionInstancesInSameView.add(new ArrayList<>(currentList)); |
---|
[1918] | 112 | } |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | |
---|
[2042] | 117 | Map<IGUIElement, List<IGUIElement>> checkBoxGroups = statistics.getCheckBoxGroups(); |
---|
| 118 | |
---|
| 119 | for (Map.Entry<IGUIElement, List<IGUIElement>> group : checkBoxGroups.entrySet()) { |
---|
| 120 | IGUIView currentView = group.getKey().getView(); |
---|
| 121 | int noOfEvents = 0; |
---|
| 122 | int noOfGroupUsages = 0; |
---|
| 123 | int noOfSingleCheckBoxUsages = 0; |
---|
| 124 | |
---|
| 125 | for (List<IEventTaskInstance> actionInstanceList : actionInstancesInSameView) { |
---|
| 126 | IEventTarget target = actionInstanceList.get(0).getEvent().getTarget(); |
---|
| 127 | IGUIView viewOfList = ((IGUIElement) target).getView(); |
---|
[1918] | 128 | |
---|
[2042] | 129 | if ((viewOfList == currentView) || |
---|
| 130 | ((viewOfList != null) && (viewOfList.equals(currentView)))) |
---|
| 131 | { |
---|
| 132 | noOfGroupUsages++; |
---|
| 133 | boolean[] checkBoxUsages = new boolean[group.getValue().size()]; |
---|
| 134 | |
---|
| 135 | for (IEventTaskInstance actionInstance : actionInstanceList) { |
---|
| 136 | int index = 0; |
---|
| 137 | for (IGUIElement checkBox : group.getValue()) { |
---|
| 138 | if ((("JFC".equals(actionInstance.getEvent().getTarget().getPlatform())) && |
---|
| 139 | (actionInstance.getEvent().getType() instanceof MouseClick) && |
---|
| 140 | (actionInstance.getEvent().getTarget().equals(checkBox))) || |
---|
| 141 | ((actionInstance.getEvent().getType() instanceof ValueSelection<?>) && |
---|
| 142 | (actionInstance.getEvent().getTarget().equals(checkBox)))) |
---|
| 143 | { |
---|
| 144 | checkBoxUsages[index] = !checkBoxUsages[index]; |
---|
| 145 | noOfEvents++; |
---|
[1918] | 146 | } |
---|
[2042] | 147 | index++; |
---|
[1918] | 148 | } |
---|
[2042] | 149 | } |
---|
| 150 | |
---|
| 151 | int noOfCheckedBoxes = 0; |
---|
| 152 | |
---|
| 153 | for (int i = 0; i < checkBoxUsages.length; i++) { |
---|
| 154 | if (checkBoxUsages[i]) { |
---|
| 155 | noOfCheckedBoxes++; |
---|
[1918] | 156 | } |
---|
| 157 | } |
---|
[2042] | 158 | |
---|
| 159 | if (noOfCheckedBoxes == 1) { |
---|
| 160 | noOfSingleCheckBoxUsages++; |
---|
| 161 | } |
---|
[1918] | 162 | } |
---|
[2042] | 163 | } |
---|
| 164 | |
---|
| 165 | // get a value that is 1 if for one group usage there is on average one check box usage |
---|
| 166 | // get a value of 0 if for one group usage there is on average two check box usages |
---|
| 167 | |
---|
| 168 | int ratio = noOfGroupUsages > 0 ? 1000 * noOfSingleCheckBoxUsages / noOfGroupUsages : 0; |
---|
| 169 | |
---|
| 170 | System.out.println(currentView + " " + ratio + " " + noOfGroupUsages + " " + |
---|
| 171 | noOfSingleCheckBoxUsages); |
---|
| 172 | |
---|
| 173 | UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity |
---|
| 174 | (ratio, noOfEvents, -1); |
---|
| 175 | |
---|
| 176 | if (intensity != null) { |
---|
| 177 | Map<String, Object> parameters = new HashMap<String, Object>(); |
---|
| 178 | parameters.put("allUsages", noOfGroupUsages); |
---|
| 179 | parameters.put("singleUsages", noOfSingleCheckBoxUsages); |
---|
| 180 | parameters.put("ratio", 100 * noOfSingleCheckBoxUsages / noOfGroupUsages); |
---|
| 181 | parameters.put("radioButtons", group.getValue()); |
---|
[1918] | 182 | |
---|
[2042] | 183 | results.addSmell |
---|
| 184 | (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, parameters); |
---|
| 185 | } |
---|
[1918] | 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | /** |
---|
| 190 | * |
---|
| 191 | */ |
---|
| 192 | private void calculateStatistics(Collection<ITask> tasks, |
---|
| 193 | ValueChangeStatistics statistics) |
---|
| 194 | { |
---|
| 195 | for (ITask task : tasks) { |
---|
| 196 | if (task instanceof IEventTask) { |
---|
| 197 | for (ITaskInstance taskInstance : task.getInstances()) { |
---|
| 198 | statistics.addValueChange((IEventTaskInstance) taskInstance); |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | /** |
---|
| 205 | * |
---|
| 206 | */ |
---|
| 207 | private static class ValueChangeStatistics { |
---|
| 208 | |
---|
| 209 | /** */ |
---|
| 210 | private Set<IGUIElement> checkBoxes = new HashSet<>(); |
---|
| 211 | |
---|
| 212 | /** */ |
---|
| 213 | private Map<IGUIElement, List<IGUIElement>> checkBoxGroups = new HashMap<>(); |
---|
| 214 | |
---|
| 215 | /** |
---|
| 216 | * |
---|
| 217 | */ |
---|
| 218 | private void addValueChange(IEventTaskInstance instance) { |
---|
[2135] | 219 | IEventTarget target = instance.getEvent().getTarget(); |
---|
[1918] | 220 | |
---|
| 221 | if (target instanceof ICheckBox) { |
---|
[2135] | 222 | checkBoxes.add((ICheckBox) target); |
---|
[1918] | 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | /** |
---|
| 227 | * |
---|
| 228 | */ |
---|
| 229 | private void condenseCheckBoxGroups() { |
---|
| 230 | checkBoxGroups = RuleUtils.getGroups(checkBoxes, 3); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | /** |
---|
| 234 | * |
---|
| 235 | */ |
---|
| 236 | private Map<IGUIElement, List<IGUIElement>> getCheckBoxGroups() { |
---|
| 237 | return checkBoxGroups; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | } |
---|