source: trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CommonTaskRateRule.java @ 1941

Last change on this file since 1941 was 1918, checked in by pharms, 9 years ago
  • extension with further smell detections
  • may not fully work. But Hudson is more happy because compile errors should be gone
File size: 4.6 KB
Line 
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
15package de.ugoe.cs.autoquest.usability;
16
17import java.text.DecimalFormat;
18import java.util.ArrayList;
19import java.util.HashMap;
20import java.util.LinkedList;
21import java.util.List;
22import java.util.Map;
23
24import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
25
26import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
30import 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 */
38public 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 should tend to 0.1 (all subsequent 10 actions are covered by the same task).
64        // The ratio must be similar, i.e., if the mean is 0.1 the ratio is 0, if the mean is 1.0
65        // the ratio is 1000
66       
67        if (statistics.getN() > 0) {
68            double mean = statistics.getMean();
69            int ratio = (int) (10000 * (mean - 0.1) / 9);
70
71            UsabilitySmellIntensity intensity =
72                UsabilitySmellIntensity.getIntensity(ratio, allObserved, -1);
73
74            if (intensity != null) {
75                Map<String, Object> parameters = new HashMap<String, Object>();
76                parameters.put("ratio", new DecimalFormat("#.##").format(mean * 10));
77
78                results.addSmell(intensity, UsabilitySmellDescription.COMMON_TASK_RATE, parameters);
79            }
80        }
81    }
82
83
84    /**
85     *
86     */
87    private int calculateStatistics(List<IUserSession>      sessions,
88                                    final SummaryStatistics statistics)
89    {
90        final LinkedList<ITaskInstance> rootNodes = new LinkedList<>();
91        final List<IEventTaskInstance> leafNodes = new ArrayList<>();
92       
93        for (IUserSession session : sessions) {
94            rootNodes.clear();
95           
96            for (final ITaskInstance currentRoot : session) {
97                currentRoot.accept(new DefaultTaskInstanceTraversingVisitor() {
98                    @Override
99                    public void visit(IEventTaskInstance eventTaskInstance) {
100                        rootNodes.add(currentRoot);
101                        leafNodes.add(eventTaskInstance);
102
103                        if (rootNodes.size() >= 10) {
104                            statistics.addValue(getTaskCoverageMeasure(rootNodes));
105                           
106                            while (rootNodes.size() >= 10) {
107                                rootNodes.removeFirst();
108                            }
109                        }
110                    }
111                });
112            }
113        }
114       
115        return leafNodes.size();
116    }
117
118    /**
119     *
120     */
121    private double getTaskCoverageMeasure(LinkedList<ITaskInstance> rootNodes) {
122        int noOfDiffRoots = 0;
123        ITaskInstance prevRoot = null;
124       
125        for (ITaskInstance root : rootNodes) {
126            if (!root.equals(prevRoot)) {
127                noOfDiffRoots++;
128            }
129           
130            prevRoot = root;
131        }
132       
133        return (double) noOfDiffRoots / rootNodes.size();
134    }
135
136}
Note: See TracBrowser for help on using the repository browser.