Changeset 2042 for trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CheckBoxMultipleSelectionRule.java
- Timestamp:
- 10/20/15 10:11:04 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CheckBoxMultipleSelectionRule.java
r1918 r2042 15 15 package de.ugoe.cs.autoquest.usability; 16 16 17 import java.util.ArrayList; 17 18 import java.util.Collection; 18 19 import java.util.HashMap; 19 20 import java.util.HashSet; 21 import java.util.LinkedList; 20 22 import java.util.List; 21 23 import java.util.Map; 22 24 import java.util.Set; 23 25 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; 24 29 import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox; 25 30 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; 31 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; 27 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 28 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship;30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship;31 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 32 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 33 37 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 34 import de.ugoe.cs.autoquest.tasktrees.treeifc. TaskMetric;38 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 35 39 36 40 /** … … 68 72 UsabilityEvaluationResult results) 69 73 { 74 System.out.println("\n\n########################################\n"); 75 final List<List<IEventTaskInstance>> actionInstancesInSameView = new LinkedList<>(); 76 77 for (IUserSession session : taskModel.getUserSessions()) { 78 for (ITaskInstance instance : session) { 79 final LinkedList<IEventTaskInstance> currentList = new LinkedList<>(); 80 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 } 107 } 108 }); 109 110 if (currentList.size() > 0) { 111 actionInstancesInSameView.add(new ArrayList<>(currentList)); 112 } 113 } 114 } 115 116 70 117 Map<IGUIElement, List<IGUIElement>> checkBoxGroups = statistics.getCheckBoxGroups(); 71 118 72 CHECK_NEXT_GROUP: 73 for (List<IGUIElement> group : checkBoxGroups.values()) { 74 Set<ITask> tasksUsingGroup = new HashSet<>(); 75 76 for (IGUIElement checkBox : group) { 77 Set<ITask> tasksUsingCheckBox = getTasksUsingCheckBox(checkBox, taskModel); 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(); 78 128 79 for (ITask taskUsingCheckBox : tasksUsingCheckBox) { 80 if (tasksUsingGroup.contains(taskUsingCheckBox)) { 81 continue CHECK_NEXT_GROUP; 82 } 83 else { 84 tasksUsingGroup.add(taskUsingCheckBox); 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++; 146 } 147 index++; 148 } 149 } 150 151 int noOfCheckedBoxes = 0; 152 153 for (int i = 0; i < checkBoxUsages.length; i++) { 154 if (checkBoxUsages[i]) { 155 noOfCheckedBoxes++; 156 } 157 } 158 159 if (noOfCheckedBoxes == 1) { 160 noOfSingleCheckBoxUsages++; 85 161 } 86 162 } 87 163 } 88 164 89 if (tasksUsingGroup.size() > 0) { 90 int eventCoverage = 0; 91 int allRecordedEvents = 0; 92 93 for (ITask task : tasksUsingGroup) { 94 if (task instanceof IEventTask) { 95 eventCoverage += 96 taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 97 } 98 } 99 100 for (ITask task : taskModel.getTasks()) { 101 if (task instanceof IEventTask) { 102 allRecordedEvents += 103 taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 104 } 105 } 106 107 108 UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity 109 ((int) (1000 * eventCoverage / allRecordedEvents), eventCoverage, -1); 110 111 if (intensity != null) { 112 Map<String, Object> parameters = new HashMap<String, Object>(); 113 parameters.put("radioButtons", group); 114 115 results.addSmell 116 (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, 117 parameters); 118 } 119 } 120 } 121 } 122 123 /** 124 * 125 */ 126 private Set<ITask> getTasksUsingCheckBox(final IGUIElement checkBox, ITaskModel taskModel) { 127 final Set<ITask> tasksUsingCheckBox = new HashSet<ITask>(); 128 129 for (ITask candidate : taskModel.getTasks()) { 130 candidate.accept(new DefaultTaskTraversingVisitor() { 131 @Override 132 public void visit(IEventTask eventTask) { 133 if (!eventTask.getInstances().isEmpty()) { 134 IEventTaskInstance instance = 135 (IEventTaskInstance) eventTask.getInstances().iterator().next(); 136 137 if (checkBox.equals(instance.getEvent().getTarget())) { 138 tasksUsingCheckBox.add(eventTask); 139 } 140 } 141 } 142 143 @Override 144 public void visit(IStructuringTemporalRelationship relationship) { 145 if (tasksUsingCheckBox.contains(relationship)) { 146 return; 147 } 148 else { 149 for (ITask child : relationship.getChildren()) { 150 if (tasksUsingCheckBox.contains(child)) { 151 tasksUsingCheckBox.add(relationship); 152 return; 153 } 154 } 155 156 super.visit(relationship); 157 158 for (ITask child : relationship.getChildren()) { 159 if (tasksUsingCheckBox.contains(child)) { 160 tasksUsingCheckBox.add(relationship); 161 break; 162 } 163 } 164 } 165 } 166 167 @Override 168 public void visit(IMarkingTemporalRelationship relationship) { 169 if (tasksUsingCheckBox.contains(relationship)) { 170 return; 171 } 172 else { 173 if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) { 174 tasksUsingCheckBox.add(relationship); 175 return; 176 } 177 178 super.visit(relationship); 179 180 if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) { 181 tasksUsingCheckBox.add(relationship); 182 return; 183 } 184 } 185 } 186 }); 187 } 188 189 return tasksUsingCheckBox; 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()); 182 183 results.addSmell 184 (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, parameters); 185 } 186 } 190 187 } 191 188
Note: See TracChangeset
for help on using the changeset viewer.