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 | |
---|
17 | import java.text.DecimalFormat; |
---|
18 | import java.util.ArrayList; |
---|
19 | import java.util.HashMap; |
---|
20 | import java.util.LinkedList; |
---|
21 | import java.util.List; |
---|
22 | import java.util.Map; |
---|
23 | |
---|
24 | import org.apache.commons.math3.stat.descriptive.SummaryStatistics; |
---|
25 | |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
31 | |
---|
32 | /** |
---|
33 | * TODO comment |
---|
34 | * |
---|
35 | * @version $Revision: $ $Date: 16.07.2012$ |
---|
36 | * @author 2012, last modified by $Author: pharms$ |
---|
37 | */ |
---|
38 | public class CommonTaskRateRule implements UsabilityEvaluationRule { |
---|
39 | |
---|
40 | /* |
---|
41 | * (non-Javadoc) |
---|
42 | * |
---|
43 | * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree) |
---|
44 | */ |
---|
45 | @Override |
---|
46 | public UsabilityEvaluationResult evaluate(ITaskModel taskModel) { |
---|
47 | SummaryStatistics statistics = new SummaryStatistics(); |
---|
48 | int allObserved = calculateStatistics(taskModel.getUserSessions(), statistics); |
---|
49 | |
---|
50 | UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel); |
---|
51 | analyzeStatistics(statistics, allObserved, results); |
---|
52 | |
---|
53 | return results; |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * |
---|
58 | */ |
---|
59 | private void analyzeStatistics(SummaryStatistics statistics, |
---|
60 | int allObserved, |
---|
61 | UsabilityEvaluationResult results) |
---|
62 | { |
---|
63 | // the mean indicates how many different root nodes 10 subsequent actions have. |
---|
64 | // The mean should tend to 0.1 (all subsequent 10 actions are covered by the same root task). |
---|
65 | // The ratio must be similar, i.e., if the mean is 0.1 the ratio is 0, if the mean is 1.0 |
---|
66 | // the ratio is 1000 |
---|
67 | |
---|
68 | if (statistics.getN() > 0) { |
---|
69 | double mean = statistics.getMean(); |
---|
70 | int ratio = (int) (10000 * (mean - 0.1) / 9); |
---|
71 | |
---|
72 | UsabilitySmellIntensity intensity = |
---|
73 | UsabilitySmellIntensity.getIntensity(ratio, allObserved, -1); |
---|
74 | |
---|
75 | if (intensity != null) { |
---|
76 | Map<String, Object> parameters = new HashMap<String, Object>(); |
---|
77 | parameters.put("ratio", new DecimalFormat("#.##").format(mean * 10)); |
---|
78 | |
---|
79 | results.addSmell(intensity, UsabilitySmellDescription.COMMON_TASK_RATE, parameters); |
---|
80 | } |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | /** |
---|
86 | * |
---|
87 | */ |
---|
88 | private int calculateStatistics(List<IUserSession> sessions, |
---|
89 | final SummaryStatistics statistics) |
---|
90 | { |
---|
91 | final LinkedList<ITaskInstance> rootNodes = new LinkedList<>(); |
---|
92 | final List<IEventTaskInstance> leafNodes = new ArrayList<>(); |
---|
93 | |
---|
94 | // determine for always 10 subsequent actions the root tasks performed for them. |
---|
95 | // then determine, the ratio of different root tasks to 10. |
---|
96 | for (IUserSession session : sessions) { |
---|
97 | rootNodes.clear(); |
---|
98 | |
---|
99 | for (final ITaskInstance currentRoot : session) { |
---|
100 | currentRoot.accept(new DefaultTaskInstanceTraversingVisitor() { |
---|
101 | @Override |
---|
102 | public void visit(IEventTaskInstance eventTaskInstance) { |
---|
103 | rootNodes.add(currentRoot); |
---|
104 | leafNodes.add(eventTaskInstance); |
---|
105 | |
---|
106 | if (rootNodes.size() >= 10) { |
---|
107 | statistics.addValue(getTaskCoverageMeasure(rootNodes)); |
---|
108 | |
---|
109 | while (rootNodes.size() >= 10) { |
---|
110 | rootNodes.removeFirst(); |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | }); |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | return leafNodes.size(); |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | * |
---|
123 | */ |
---|
124 | private double getTaskCoverageMeasure(LinkedList<ITaskInstance> rootNodes) { |
---|
125 | int noOfDiffRoots = 0; |
---|
126 | ITaskInstance prevRoot = null; |
---|
127 | |
---|
128 | for (ITaskInstance root : rootNodes) { |
---|
129 | if (!root.equals(prevRoot)) { |
---|
130 | noOfDiffRoots++; |
---|
131 | } |
---|
132 | |
---|
133 | prevRoot = root; |
---|
134 | } |
---|
135 | |
---|
136 | return (double) noOfDiffRoots / rootNodes.size(); |
---|
137 | } |
---|
138 | |
---|
139 | } |
---|