[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; |
---|
| 19 | import java.util.Map; |
---|
| 20 | |
---|
[1493] | 21 | import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; |
---|
| 22 | |
---|
| 23 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
[1335] | 24 | import de.ugoe.cs.autoquest.eventcore.gui.Scroll; |
---|
[1493] | 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; |
---|
[1335] | 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
[1949] | 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
[1335] | 28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 30 | import 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 | */ |
---|
[1493] | 38 | public class RequiredInefficientActionsRule implements UsabilityEvaluationRule { |
---|
[1335] | 39 | |
---|
| 40 | /* |
---|
| 41 | * (non-Javadoc) |
---|
| 42 | * |
---|
| 43 | * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree) |
---|
| 44 | */ |
---|
| 45 | @Override |
---|
| 46 | public UsabilityEvaluationResult evaluate(ITaskModel taskModel) { |
---|
[1493] | 47 | UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel); |
---|
[1335] | 48 | |
---|
[1949] | 49 | Map<ISequence, double[]> smellingTasks = |
---|
| 50 | getInefficientActionStatistics(taskModel.getTasks()); |
---|
| 51 | |
---|
[1493] | 52 | analyzeTasksWithInefficientActions(smellingTasks, results, taskModel); |
---|
[1335] | 53 | |
---|
| 54 | return results; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * |
---|
| 59 | */ |
---|
[1949] | 60 | private void analyzeTasksWithInefficientActions(Map<ISequence, double[]> smellingTasks, |
---|
[1493] | 61 | UsabilityEvaluationResult results, |
---|
| 62 | ITaskModel taskModel) |
---|
[1335] | 63 | { |
---|
| 64 | |
---|
[1949] | 65 | for (Map.Entry<ISequence, double[]> entry : smellingTasks.entrySet()) { |
---|
[1493] | 66 | DescriptiveStatistics stats = new DescriptiveStatistics(entry.getValue()); |
---|
| 67 | |
---|
| 68 | int ratio = (int) (1000 * stats.getMean()); |
---|
[1335] | 69 | |
---|
[1918] | 70 | UsabilitySmellIntensity severity = |
---|
| 71 | UsabilitySmellIntensity.getIntensity(ratio, entry.getKey(), taskModel); |
---|
[1335] | 72 | |
---|
| 73 | if (severity != null) { |
---|
[1493] | 74 | Map<String, Object> parameters = new HashMap<String, Object>(); |
---|
| 75 | parameters.put("task", entry.getKey()); |
---|
| 76 | parameters.put("ratio", (ratio / 10)); |
---|
[1335] | 77 | |
---|
[1918] | 78 | results.addSmell(entry.getKey(), severity, |
---|
| 79 | UsabilitySmellDescription.INEFFICIENT_ACTIONS, parameters); |
---|
[1335] | 80 | } |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | /** |
---|
| 85 | * |
---|
| 86 | */ |
---|
[1949] | 87 | private Map<ISequence, double[]> getInefficientActionStatistics(Collection<ITask> tasks) { |
---|
| 88 | Map<ISequence, double[]> inefficientActionRatios = new HashMap<ISequence, double[]>(); |
---|
[1335] | 89 | |
---|
| 90 | for (ITask task : tasks) { |
---|
[1949] | 91 | if (task instanceof ISequence) { |
---|
| 92 | double[] ratios = getRatiosOfInefficientActionsInInstances((ISequence) task); |
---|
[1493] | 93 | |
---|
| 94 | for (int i = 0; i < ratios.length; i++) { |
---|
| 95 | if (ratios[i] > 0) { |
---|
| 96 | // there is at least on inefficient action |
---|
[1949] | 97 | inefficientActionRatios.put((ISequence) task, ratios); |
---|
[1493] | 98 | break; |
---|
| 99 | } |
---|
[1335] | 100 | } |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
[1493] | 104 | return inefficientActionRatios; |
---|
[1335] | 105 | } |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * |
---|
| 109 | */ |
---|
[1949] | 110 | private double[] getRatiosOfInefficientActionsInInstances(ISequence sequence) { |
---|
| 111 | Collection<ITaskInstance> instances = sequence.getInstances(); |
---|
[1335] | 112 | |
---|
[1493] | 113 | double[] ratios = new double[instances.size()]; |
---|
| 114 | int index = 0; |
---|
[1335] | 115 | for (ITaskInstance instance : instances) { |
---|
[1493] | 116 | ratios[index++] = getRatioOfInefficientActionsInInstance(instance); |
---|
[1335] | 117 | } |
---|
| 118 | |
---|
[1493] | 119 | return ratios; |
---|
[1335] | 120 | } |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | * |
---|
| 124 | */ |
---|
[1493] | 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]++; |
---|
[1335] | 138 | } |
---|
| 139 | |
---|
[1493] | 140 | }); |
---|
[1335] | 141 | |
---|
[1493] | 142 | return (double) count[0] / count[1]; |
---|
[1335] | 143 | } |
---|
| 144 | |
---|
| 145 | /** |
---|
[1493] | 146 | * |
---|
[1335] | 147 | */ |
---|
[1493] | 148 | private boolean isInefficientAction(Event event) { |
---|
| 149 | return (event.getType() instanceof Scroll); |
---|
[1335] | 150 | } |
---|
| 151 | |
---|
| 152 | } |
---|