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

Last change on this file since 1949 was 1949, checked in by pharms, 9 years ago
  • changed smell detection to focus on sequences only
File size: 5.0 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.util.Collection;
18import java.util.HashMap;
19import java.util.Map;
20
21import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
22
23import de.ugoe.cs.autoquest.eventcore.Event;
24import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
31
32/**
33 * TODO comment
34 *
35 * @version $Revision: $ $Date: 16.07.2012$
36 * @author 2012, last modified by $Author: pharms$
37 */
38public class RequiredInefficientActionsRule 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        UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel);
48
49        Map<ISequence, double[]> smellingTasks =
50            getInefficientActionStatistics(taskModel.getTasks());
51       
52        analyzeTasksWithInefficientActions(smellingTasks, results, taskModel);
53
54        return results;
55    }
56
57    /**
58     *
59     */
60    private void analyzeTasksWithInefficientActions(Map<ISequence, double[]>  smellingTasks,
61                                                    UsabilityEvaluationResult results,
62                                                    ITaskModel                taskModel)
63    {
64
65        for (Map.Entry<ISequence, double[]> entry : smellingTasks.entrySet()) {
66            DescriptiveStatistics stats = new DescriptiveStatistics(entry.getValue());
67           
68            int ratio = (int) (1000 * stats.getMean());
69
70            UsabilitySmellIntensity severity =
71                UsabilitySmellIntensity.getIntensity(ratio, entry.getKey(), taskModel);
72
73            if (severity != null) {
74                Map<String, Object> parameters = new HashMap<String, Object>();
75                parameters.put("task", entry.getKey());
76                parameters.put("ratio", (ratio / 10));
77
78                results.addSmell(entry.getKey(), severity,
79                                 UsabilitySmellDescription.INEFFICIENT_ACTIONS, parameters);
80            }
81        }
82    }
83
84    /**
85     *
86     */
87    private Map<ISequence, double[]> getInefficientActionStatistics(Collection<ITask> tasks) {
88        Map<ISequence, double[]> inefficientActionRatios = new HashMap<ISequence, double[]>();
89       
90        for (ITask task : tasks) {
91            if (task instanceof ISequence)  {
92                double[] ratios = getRatiosOfInefficientActionsInInstances((ISequence) task);
93               
94                for (int i = 0; i < ratios.length; i++) {
95                    if (ratios[i] > 0) {
96                        // there is at least on inefficient action
97                        inefficientActionRatios.put((ISequence) task, ratios);
98                        break;
99                    }
100                }
101            }
102        }
103       
104        return inefficientActionRatios;
105    }
106
107    /**
108     *
109     */
110    private double[] getRatiosOfInefficientActionsInInstances(ISequence sequence) {
111        Collection<ITaskInstance> instances = sequence.getInstances();
112       
113        double[] ratios = new double[instances.size()];
114        int index = 0;
115        for (ITaskInstance instance : instances) {
116            ratios[index++] = getRatioOfInefficientActionsInInstance(instance);
117        }
118       
119        return ratios;
120    }
121
122    /**
123     *
124     */
125    private double getRatioOfInefficientActionsInInstance(ITaskInstance instance) {
126        final int[] count = new int[2];
127        count[0] = 0;
128        count[1] = 0;
129       
130        instance.accept(new DefaultTaskInstanceTraversingVisitor() {
131            @Override
132            public void visit(IEventTaskInstance eventTaskInstance) {
133                if (isInefficientAction(eventTaskInstance.getEvent())) {
134                    count[0]++;
135                }
136               
137                count[1]++;
138            }
139           
140        });
141       
142        return (double) count[0] / count[1];
143    }
144
145    /**
146     *
147     */
148    private boolean isInefficientAction(Event event) {
149        return (event.getType() instanceof Scroll);
150    }
151
152}
Note: See TracBrowser for help on using the repository browser.