[1335] | 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.util.Collection; |
---|
| 18 | import java.util.HashMap; |
---|
[2162] | 19 | import java.util.LinkedList; |
---|
| 20 | import java.util.List; |
---|
[1335] | 21 | import java.util.Map; |
---|
| 22 | |
---|
[1493] | 23 | import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
---|
| 24 | |
---|
| 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; |
---|
[2162] | 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; |
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
[1335] | 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
[1949] | 29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
[1335] | 30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * TODO comment |
---|
| 36 | * |
---|
| 37 | * @version $Revision: $ $Date: 16.07.2012$ |
---|
| 38 | * @author 2012, last modified by $Author: pharms$ |
---|
| 39 | */ |
---|
[1493] | 40 | public class RequiredInefficientActionsRule implements UsabilityEvaluationRule { |
---|
[1335] | 41 | |
---|
| 42 | /* |
---|
| 43 | * (non-Javadoc) |
---|
| 44 | * |
---|
| 45 | * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree) |
---|
| 46 | */ |
---|
| 47 | @Override |
---|
| 48 | public UsabilityEvaluationResult evaluate(ITaskModel taskModel) { |
---|
[1493] | 49 | UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel); |
---|
[1335] | 50 | |
---|
[1949] | 51 | Map<ISequence, double[]> smellingTasks = |
---|
| 52 | getInefficientActionStatistics(taskModel.getTasks()); |
---|
| 53 | |
---|
[1493] | 54 | analyzeTasksWithInefficientActions(smellingTasks, results, taskModel); |
---|
[1335] | 55 | |
---|
| 56 | return results; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * |
---|
| 61 | */ |
---|
[1949] | 62 | private void analyzeTasksWithInefficientActions(Map<ISequence, double[]> smellingTasks, |
---|
[1493] | 63 | UsabilityEvaluationResult results, |
---|
| 64 | ITaskModel taskModel) |
---|
[1335] | 65 | { |
---|
| 66 | |
---|
[1949] | 67 | for (Map.Entry<ISequence, double[]> entry : smellingTasks.entrySet()) { |
---|
[1493] | 68 | DescriptiveStatistics stats = new DescriptiveStatistics(entry.getValue()); |
---|
| 69 | |
---|
| 70 | int ratio = (int) (1000 * stats.getMean()); |
---|
[1335] | 71 | |
---|
[1918] | 72 | UsabilitySmellIntensity severity = |
---|
| 73 | UsabilitySmellIntensity.getIntensity(ratio, entry.getKey(), taskModel); |
---|
[1335] | 74 | |
---|
| 75 | if (severity != null) { |
---|
[1493] | 76 | Map<String, Object> parameters = new HashMap<String, Object>(); |
---|
| 77 | parameters.put("task", entry.getKey()); |
---|
| 78 | parameters.put("ratio", (ratio / 10)); |
---|
[1335] | 79 | |
---|
[1918] | 80 | results.addSmell(entry.getKey(), severity, |
---|
| 81 | UsabilitySmellDescription.INEFFICIENT_ACTIONS, parameters); |
---|
[1335] | 82 | } |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | /** |
---|
| 87 | * |
---|
| 88 | */ |
---|
[1949] | 89 | private Map<ISequence, double[]> getInefficientActionStatistics(Collection<ITask> tasks) { |
---|
| 90 | Map<ISequence, double[]> inefficientActionRatios = new HashMap<ISequence, double[]>(); |
---|
[1335] | 91 | |
---|
| 92 | for (ITask task : tasks) { |
---|
[1949] | 93 | if (task instanceof ISequence) { |
---|
[2162] | 94 | if (countEfficientActions((ISequence) task) > 1) { |
---|
| 95 | double[] ratios = getRatiosOfInefficientActionsInInstances((ISequence) task); |
---|
| 96 | |
---|
| 97 | for (int i = 0; i < ratios.length; i++) { |
---|
| 98 | if (ratios[i] > 0) { |
---|
| 99 | // there is at least on inefficient action |
---|
| 100 | inefficientActionRatios.put((ISequence) task, ratios); |
---|
| 101 | break; |
---|
| 102 | } |
---|
[1493] | 103 | } |
---|
[1335] | 104 | } |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
[1493] | 108 | return inefficientActionRatios; |
---|
[1335] | 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
[2162] | 112 | * |
---|
| 113 | */ |
---|
| 114 | private int countEfficientActions(ISequence task) { |
---|
| 115 | final List<IEventTask> efficientActions = new LinkedList<>(); |
---|
| 116 | |
---|
| 117 | task.accept(new DefaultTaskTraversingVisitor() { |
---|
| 118 | @Override |
---|
| 119 | public void visit(IEventTask eventTask) { |
---|
| 120 | if (!ActionClassifier.isInefficient(eventTask)) { |
---|
| 121 | efficientActions.add(eventTask); |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | }); |
---|
| 125 | |
---|
| 126 | return efficientActions.size(); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
[1335] | 130 | * |
---|
| 131 | */ |
---|
[1949] | 132 | private double[] getRatiosOfInefficientActionsInInstances(ISequence sequence) { |
---|
| 133 | Collection<ITaskInstance> instances = sequence.getInstances(); |
---|
[1335] | 134 | |
---|
[1493] | 135 | double[] ratios = new double[instances.size()]; |
---|
| 136 | int index = 0; |
---|
[1335] | 137 | for (ITaskInstance instance : instances) { |
---|
[1493] | 138 | ratios[index++] = getRatioOfInefficientActionsInInstance(instance); |
---|
[1335] | 139 | } |
---|
| 140 | |
---|
[1493] | 141 | return ratios; |
---|
[1335] | 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * |
---|
| 146 | */ |
---|
[1493] | 147 | private double getRatioOfInefficientActionsInInstance(ITaskInstance instance) { |
---|
| 148 | final int[] count = new int[2]; |
---|
| 149 | count[0] = 0; |
---|
| 150 | count[1] = 0; |
---|
| 151 | |
---|
| 152 | instance.accept(new DefaultTaskInstanceTraversingVisitor() { |
---|
| 153 | @Override |
---|
| 154 | public void visit(IEventTaskInstance eventTaskInstance) { |
---|
[2162] | 155 | if (ActionClassifier.isInefficient(eventTaskInstance.getEvent())) { |
---|
[1493] | 156 | count[0]++; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | count[1]++; |
---|
[1335] | 160 | } |
---|
| 161 | |
---|
[1493] | 162 | }); |
---|
[1335] | 163 | |
---|
[1493] | 164 | return (double) count[0] / count[1]; |
---|
[1335] | 165 | } |
---|
| 166 | |
---|
| 167 | } |
---|