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.metrics;
|
---|
16 |
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.HashMap;
|
---|
19 | import java.util.Map;
|
---|
20 | import java.util.Map.Entry;
|
---|
21 |
|
---|
22 | import com.google.common.base.Optional;
|
---|
23 |
|
---|
24 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
25 | import de.ugoe.cs.autoquest.eventcore.IEventTarget;
|
---|
26 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
27 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
|
---|
28 | import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection;
|
---|
29 | import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
|
---|
30 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
|
---|
31 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
|
---|
32 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
33 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
34 | import de.ugoe.cs.autoquest.plugin.usability2.rules.metrics.visitor.AbstractMetricVisitor;
|
---|
35 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
|
---|
36 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
|
---|
37 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
38 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * <p>
|
---|
42 | * Metric, which measures directed scrolling compared to back-and-forth type of scrolling. This is
|
---|
43 | * done by calculating the absolute distance scrolled compared to the relative >>>
|
---|
44 | * </p>
|
---|
45 | *
|
---|
46 | * @author Konni Hartmann
|
---|
47 | */
|
---|
48 | public class SameTargetEditingMetric extends UsabilityRule implements UsabilityMetric {
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * <p>
|
---|
52 | * Constructor. Creates a new {@code TextInputRatioMetric} for a given task model.
|
---|
53 | * </p>
|
---|
54 | *
|
---|
55 | * @param taskTree
|
---|
56 | */
|
---|
57 | public SameTargetEditingMetric(ITaskModel taskModel) {
|
---|
58 | super(taskModel);
|
---|
59 | this.name = "SameTargetEditingMetric";
|
---|
60 | this.defect =
|
---|
61 | new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
|
---|
62 | .getSimpleName());
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * (non-Javadoc)
|
---|
68 | *
|
---|
69 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
70 | */
|
---|
71 | @Override
|
---|
72 | public Optional<UsabilityProblemDescription> calculate() {
|
---|
73 | Collection<IUserSession> ses = taskModel.getUserSessions();
|
---|
74 | float evaluationMetric =
|
---|
75 | calculateEvaluationMetric(ses);
|
---|
76 | return this.defect.isPresent(evaluationMetric);
|
---|
77 | }
|
---|
78 |
|
---|
79 | class Data {
|
---|
80 | Map<IEventTarget, Integer> map = new HashMap<IEventTarget, Integer>();
|
---|
81 |
|
---|
82 | void updateTarget(IEventTarget target, IEventType type) {
|
---|
83 | Integer data = map.get(target);
|
---|
84 | if(data == null) {
|
---|
85 | data = 0;
|
---|
86 | }
|
---|
87 | data++;
|
---|
88 | map.put(target, data);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | private float calculateEvaluationMetric(Collection<IUserSession> tasks) {
|
---|
93 | int maxEditsPerTarget = 0;
|
---|
94 | IEventTarget maxTarget = null;
|
---|
95 |
|
---|
96 | for (IUserSession s : tasks) {
|
---|
97 | Collection<ITaskInstance> instances = s.getExecutedTasks();
|
---|
98 |
|
---|
99 | final Data data = new Data();
|
---|
100 |
|
---|
101 | for (ITaskInstance iTaskInstance : instances) {
|
---|
102 |
|
---|
103 | AbstractMetricVisitor visitor = new AbstractMetricVisitor(){
|
---|
104 | @Override
|
---|
105 | public void visit(IEventTaskInstance instance) {
|
---|
106 | Event event = instance.getEvent();
|
---|
107 | IEventType type = event.getType();
|
---|
108 | if (type instanceof TextInput ||
|
---|
109 | type instanceof ValueSelection) {
|
---|
110 | data.updateTarget(event.getTarget(), type);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | };
|
---|
114 |
|
---|
115 | visitor.visit(iTaskInstance);
|
---|
116 | }
|
---|
117 |
|
---|
118 | for (Entry<IEventTarget, Integer> entry : data.map.entrySet()) {
|
---|
119 | if (entry.getValue() > maxEditsPerTarget) {
|
---|
120 | maxTarget = entry.getKey();
|
---|
121 | maxEditsPerTarget = entry.getValue();
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (maxTarget != null)
|
---|
127 | System.out.printf("(STE) Highest ranking target: %s (%d) \n", maxTarget.getStringIdentifier(), maxEditsPerTarget);
|
---|
128 | else
|
---|
129 | System.out.println("(STE) No target found");
|
---|
130 |
|
---|
131 | return maxEditsPerTarget;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /*
|
---|
135 | * (non-Javadoc)
|
---|
136 | *
|
---|
137 | * @see
|
---|
138 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
139 | * .usability.EvaluationMethodCaller)
|
---|
140 | */
|
---|
141 | @Override
|
---|
142 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
143 | {
|
---|
144 | return evaluationMethodCaller.check(this);
|
---|
145 | }
|
---|
146 | }
|
---|