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 |
|
---|
21 | import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
---|
22 |
|
---|
23 | import com.google.common.base.Optional;
|
---|
24 |
|
---|
25 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
26 | import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
|
---|
27 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
|
---|
28 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
|
---|
29 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
30 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
31 | import de.ugoe.cs.autoquest.plugin.usability2.rules.metrics.visitor.AbstractMetricVisitor;
|
---|
32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
|
---|
33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
|
---|
35 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * <p>
|
---|
39 | * Metric, which measures the total time spend on running each task by each user. >>>>
|
---|
40 | * </p>
|
---|
41 | *
|
---|
42 | * @author Konni Hartmann
|
---|
43 | */
|
---|
44 | public class OnTaskTimeMetric extends UsabilityRule implements UsabilityMetric {
|
---|
45 |
|
---|
46 | private static final int MINIMUM_NO_OF_INSTANCES = 40;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * <p>
|
---|
50 | * Constructor. Creates a new {@code OnTaskTimeMetric} for a given task model.
|
---|
51 | * </p>
|
---|
52 | *
|
---|
53 | * @param taskTree
|
---|
54 | */
|
---|
55 | public OnTaskTimeMetric(ITaskModel taskModel) {
|
---|
56 | super(taskModel);
|
---|
57 | this.name = "OnTaskTimeMetric";
|
---|
58 | this.defect =
|
---|
59 | new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
|
---|
60 | .getSimpleName());
|
---|
61 | }
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * (non-Javadoc)
|
---|
65 | *
|
---|
66 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
67 | */
|
---|
68 | @Override
|
---|
69 | public Optional<UsabilityProblemDescription> calculate() {
|
---|
70 | Collection<ITask> ses = taskModel.getTasks();
|
---|
71 | float evaluationMetric = calculateEvaluationMetric(ses);
|
---|
72 | return this.defect.isPresent(evaluationMetric);
|
---|
73 | }
|
---|
74 |
|
---|
75 | static class DataEntry {
|
---|
76 | long minTimestamp = Long.MAX_VALUE;
|
---|
77 | long maxTimestamp = Long.MIN_VALUE;
|
---|
78 |
|
---|
79 | void update(long timestamp) {
|
---|
80 | if (timestamp > maxTimestamp)
|
---|
81 | maxTimestamp = timestamp;
|
---|
82 | if (timestamp < minTimestamp)
|
---|
83 | minTimestamp = timestamp;
|
---|
84 | }
|
---|
85 |
|
---|
86 | long getTimeDifference() {
|
---|
87 | return maxTimestamp - minTimestamp;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | class Data {
|
---|
92 | Map<Integer, DataEntry> map = new HashMap<Integer, DataEntry>();
|
---|
93 |
|
---|
94 | int currentUser = 0;
|
---|
95 |
|
---|
96 | void update(Event event) {
|
---|
97 | DataEntry data = map.get(currentUser);
|
---|
98 | if (data == null) {
|
---|
99 | data = new DataEntry();
|
---|
100 | }
|
---|
101 | data.update(event.getTimestamp());
|
---|
102 | map.put(currentUser, data);
|
---|
103 | }
|
---|
104 |
|
---|
105 | public void setUserID(int currentUser) {
|
---|
106 | this.currentUser = currentUser;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | private float calculateEvaluationMetric(Collection<ITask> tasks) {
|
---|
111 |
|
---|
112 | ITask maxTask = null;
|
---|
113 | DescriptiveStatistics maxVariance = null;
|
---|
114 | float result = 0;
|
---|
115 |
|
---|
116 | for (ITask task : tasks) {
|
---|
117 | Collection<ITaskInstance> instances = task.getInstances();
|
---|
118 |
|
---|
119 | final Data data = new Data();
|
---|
120 | int userCounter = 0;
|
---|
121 |
|
---|
122 | for (ITaskInstance iTaskInstance : instances) {
|
---|
123 | AbstractMetricVisitor visitor = new AbstractMetricVisitor() {
|
---|
124 | @Override
|
---|
125 | public void visit(IEventTaskInstance instance) {
|
---|
126 | data.update(instance.getEvent());
|
---|
127 | }
|
---|
128 | };
|
---|
129 |
|
---|
130 | visitor.visit(iTaskInstance);
|
---|
131 | userCounter++;
|
---|
132 | data.setUserID(userCounter);
|
---|
133 | }
|
---|
134 |
|
---|
135 | DescriptiveStatistics stats = new DescriptiveStatistics();
|
---|
136 | for (DataEntry entry : data.map.values()) {
|
---|
137 | long difference = entry.getTimeDifference();
|
---|
138 | if (difference > 0)
|
---|
139 | // ignore single event tasks
|
---|
140 | stats.addValue(difference);
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (stats.getN() == 0)
|
---|
144 | continue;
|
---|
145 |
|
---|
146 | if ((maxVariance == null) ||
|
---|
147 | ((stats.getN() > MINIMUM_NO_OF_INSTANCES) && (maxVariance.getStandardDeviation() < stats.getStandardDeviation())))
|
---|
148 | {
|
---|
149 | maxTask = task;
|
---|
150 | maxVariance = stats;
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | System.out.println();
|
---|
155 | if (maxVariance != null) {
|
---|
156 | result = (float) maxVariance.getVariance();
|
---|
157 | System.out.printf("(OTT) Highest task: %s (%s)\n", maxTask.getDescription(),
|
---|
158 | maxVariance.getVariance());
|
---|
159 | System.out.println(maxVariance.toString());
|
---|
160 | System.out.println("Values:");
|
---|
161 | for (double val : maxVariance.getValues()) {
|
---|
162 | System.out.println(val);
|
---|
163 | }
|
---|
164 | }
|
---|
165 | else
|
---|
166 | System.out.println("(OTT) No target found");
|
---|
167 |
|
---|
168 | return result;
|
---|
169 | }
|
---|
170 |
|
---|
171 | /*
|
---|
172 | * (non-Javadoc)
|
---|
173 | *
|
---|
174 | * @see
|
---|
175 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
176 | * .usability.EvaluationMethodCaller)
|
---|
177 | */
|
---|
178 | @Override
|
---|
179 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
180 | {
|
---|
181 | return evaluationMethodCaller.check(this);
|
---|
182 | }
|
---|
183 | }
|
---|