[1326] | 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.plugin.usability2.rules.patterns;
|
---|
| 16 |
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.Collections;
|
---|
| 19 | import java.util.Comparator;
|
---|
| 20 | import java.util.HashMap;
|
---|
| 21 | import java.util.LinkedList;
|
---|
| 22 | import java.util.List;
|
---|
| 23 | import java.util.Map;
|
---|
| 24 |
|
---|
| 25 | import com.google.common.base.Optional;
|
---|
| 26 |
|
---|
| 27 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 28 | import de.ugoe.cs.autoquest.eventcore.IEventTarget;
|
---|
| 29 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
| 30 | import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
|
---|
| 31 | import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
|
---|
| 32 | import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
|
---|
| 33 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
|
---|
| 34 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
|
---|
| 35 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
| 36 | import de.ugoe.cs.autoquest.usability.rules.UsabilityUsageProblem;
|
---|
| 37 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * <p>
|
---|
| 41 | * Test Rule to see if new pattern method may be used for problem checking
|
---|
| 42 | * </p>
|
---|
| 43 | *
|
---|
| 44 | * @author Konni Hartmann
|
---|
| 45 | */
|
---|
| 46 | public class SessionPatternProblem extends UsabilityRule implements UsabilityUsageProblem {
|
---|
| 47 |
|
---|
| 48 | private final Collection<List<Event>> sessions;
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * <p>
|
---|
| 52 | * TODO: comment
|
---|
| 53 | * </p>
|
---|
| 54 | *
|
---|
| 55 | * @param taskTree
|
---|
| 56 | */
|
---|
| 57 | public SessionPatternProblem(ITaskModel taskModel, Collection<List<Event>> sessions) {
|
---|
| 58 | super(taskModel);
|
---|
| 59 | this.sessions = sessions;
|
---|
| 60 | this.name = "PatternProblem";
|
---|
| 61 | this.defect =
|
---|
| 62 | new UsabilityProblemDescriptionResolver().descriptionFor("PatternProblem");
|
---|
| 63 | initUsagePattern();
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /**
|
---|
| 67 | * <p>
|
---|
| 68 | * TODO: comment
|
---|
| 69 | * </p>
|
---|
| 70 | *
|
---|
| 71 | */
|
---|
| 72 | private void initUsagePattern() {
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | private class Statistics implements Comparable<Statistics> {
|
---|
| 76 |
|
---|
| 77 | private IEventTarget target;
|
---|
| 78 | private int match;
|
---|
| 79 | private int all;
|
---|
| 80 |
|
---|
| 81 | public Statistics(IEventTarget target) {
|
---|
| 82 | this.target = target;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | int matchCount() {
|
---|
| 86 | return match;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | int allCount() {
|
---|
| 90 | return all;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | float percent() {
|
---|
| 94 | return ((float) matchCount()) / allCount();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | @Override
|
---|
| 98 | public int compareTo(Statistics o) {
|
---|
| 99 | float thisPcnt = percent();
|
---|
| 100 | float otherPcnt = o.percent();
|
---|
| 101 |
|
---|
| 102 | if (thisPcnt < otherPcnt)
|
---|
| 103 | return -1;
|
---|
| 104 | if (thisPcnt > otherPcnt)
|
---|
| 105 | return 1;
|
---|
| 106 | return 0;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | @Override
|
---|
| 110 | public String toString() {
|
---|
| 111 | StringBuilder str = new StringBuilder();
|
---|
| 112 |
|
---|
| 113 | str.append(target.getStringIdentifier());
|
---|
| 114 | str.append(" (").append(percent()).append(')');
|
---|
| 115 |
|
---|
| 116 | return str.toString();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | public void increaseCount() {
|
---|
| 120 | this.all++;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | public void increaseMatchCount() {
|
---|
| 124 | this.match++;
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | /*
|
---|
| 129 | * (non-Javadoc)
|
---|
| 130 | *
|
---|
| 131 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 132 | */
|
---|
| 133 | @Override
|
---|
| 134 | public Optional<UsabilityProblemDescription> check() {
|
---|
| 135 | Optional<UsabilityProblemDescription> present = Optional.absent();
|
---|
| 136 |
|
---|
| 137 | System.out.println("--");
|
---|
| 138 | System.out.println("PP:");
|
---|
| 139 |
|
---|
| 140 | Map<IEventTarget, Statistics> results = new HashMap<IEventTarget, Statistics>();
|
---|
| 141 |
|
---|
| 142 | int cnt = 0, click=0, scroll=0;
|
---|
| 143 |
|
---|
| 144 | for (List<Event> events : this.sessions) {
|
---|
| 145 | IEventType last = null;
|
---|
| 146 |
|
---|
| 147 | for (Event event : events) {
|
---|
| 148 | IEventType type = event.getType();
|
---|
| 149 |
|
---|
| 150 | if (type instanceof MouseClick) {
|
---|
| 151 | click++;
|
---|
| 152 | IEventTarget target = event.getTarget();
|
---|
| 153 |
|
---|
| 154 | Statistics statistics = results.get(target);
|
---|
| 155 | if (statistics == null) {
|
---|
| 156 | statistics = new Statistics(target);
|
---|
| 157 | results.put(target, statistics);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | statistics.increaseCount();
|
---|
| 161 |
|
---|
| 162 | if(last != null && last instanceof Scroll) {
|
---|
| 163 | scroll++;
|
---|
| 164 | statistics.increaseMatchCount();
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | last = type;
|
---|
| 169 | cnt++;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 | System.out.printf("Analyzed %d events with %d clicks and %d scrolls before clicks.\n", cnt, click, scroll);
|
---|
| 173 |
|
---|
| 174 | analyzeResults(results);
|
---|
| 175 |
|
---|
| 176 | /*
|
---|
| 177 | * System.out.println("PATTERN2:"); for (ITask task : tasks) { IResult result =
|
---|
| 178 | * this.pattern2.match(task);
|
---|
| 179 | *
|
---|
| 180 | * result = this.pattern2.match(task);
|
---|
| 181 | *
|
---|
| 182 | * if (result.isPresent()) { present = Optional.of(this.defect);
|
---|
| 183 | * System.out.printf("2: %s, %s, %d\n", task.getId(), task.getDescription(), task
|
---|
| 184 | * .getInstances().size()); } }
|
---|
| 185 | */
|
---|
| 186 |
|
---|
| 187 | System.out.println("Finished Pattern analysis");
|
---|
| 188 | return present;
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | private void analyzeResults(Map<IEventTarget, Statistics> results) {
|
---|
| 192 |
|
---|
| 193 | List<Statistics> pcnt95 = new LinkedList<Statistics>();
|
---|
| 194 | List<Statistics> pcnt75 = new LinkedList<Statistics>();
|
---|
| 195 | List<Statistics> pcnt50 = new LinkedList<Statistics>();
|
---|
| 196 | List<Statistics> pcnt25 = new LinkedList<Statistics>();
|
---|
| 197 | List<Statistics> pcnt05 = new LinkedList<Statistics>();
|
---|
| 198 |
|
---|
| 199 | for (Statistics s : results.values()) {
|
---|
| 200 | float percent = s.percent();
|
---|
| 201 |
|
---|
| 202 | if (percent >= 0.95)
|
---|
| 203 | pcnt95.add(s);
|
---|
| 204 | else if (percent >= 0.75)
|
---|
| 205 | pcnt75.add(s);
|
---|
| 206 | else if (percent >= 0.50)
|
---|
| 207 | pcnt50.add(s);
|
---|
| 208 | else if (percent >= 0.25)
|
---|
| 209 | pcnt25.add(s);
|
---|
| 210 | else if (percent >= 0.05)
|
---|
| 211 | pcnt05.add(s);
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | Comparator<Statistics> reverse = new Comparator<Statistics>() {
|
---|
| 215 | @Override
|
---|
| 216 | public int compare(Statistics o1, Statistics o2) {
|
---|
| 217 | return o2.matchCount() - o1.matchCount();
|
---|
| 218 | }
|
---|
| 219 | };
|
---|
| 220 |
|
---|
| 221 | Collections.sort(pcnt95, reverse);
|
---|
| 222 | Collections.sort(pcnt75, reverse);
|
---|
| 223 | Collections.sort(pcnt50, reverse);
|
---|
| 224 | Collections.sort(pcnt25, reverse);
|
---|
| 225 | Collections.sort(pcnt05, reverse);
|
---|
| 226 |
|
---|
| 227 | printFirstN(pcnt95, 3, 0.95);
|
---|
| 228 | printFirstN(pcnt75, 3, 0.75);
|
---|
| 229 | printFirstN(pcnt50, 3, 0.50);
|
---|
| 230 | printFirstN(pcnt25, 3, 0.25);
|
---|
| 231 | printFirstN(pcnt05, 3, 0.05);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | private void printFirstN(List<Statistics> list, int i, double margin) {
|
---|
| 235 | if (!list.isEmpty()) {
|
---|
| 236 | System.out.printf(">= %f :\n", margin);
|
---|
| 237 | for (int j = 0; j < list.size() && j < i; j++) {
|
---|
| 238 | Statistics s = list.get(j);
|
---|
| 239 | System.out.printf("%d [%d]: %s\n", j + 1, s.matchCount(), s);
|
---|
| 240 | }
|
---|
| 241 | if (list.size() >= i) {
|
---|
| 242 | Statistics s = list.get(list.size() - 1);
|
---|
| 243 | System.out.printf("%d [%d]: %s\n", list.size() - 1, s.matchCount(), s);
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | /*
|
---|
| 249 | * (non-Javadoc)
|
---|
| 250 | *
|
---|
| 251 | * @see
|
---|
| 252 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
| 253 | * .usability.EvaluationMethodCaller)
|
---|
| 254 | */
|
---|
| 255 | @Override
|
---|
| 256 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
| 257 | {
|
---|
| 258 | return evaluationMethodCaller.check(this);
|
---|
| 259 | }
|
---|
| 260 | }
|
---|