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.LinkedList; |
---|
20 | import java.util.List; |
---|
21 | import java.util.Map; |
---|
22 | |
---|
23 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; |
---|
24 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
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 | */ |
---|
38 | public class TaskRetryRule 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<IIteration, Integer> smellingTasks = getTasksWithRetries(taskModel.getTasks()); |
---|
50 | analyzeTasksWithRetries(smellingTasks, results, taskModel); |
---|
51 | |
---|
52 | return results; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * |
---|
57 | */ |
---|
58 | private void analyzeTasksWithRetries(Map<IIteration, Integer> smellingTasks, |
---|
59 | UsabilityEvaluationResult results, |
---|
60 | ITaskModel taskModel) |
---|
61 | { |
---|
62 | |
---|
63 | for (Map.Entry<IIteration, Integer> entry : smellingTasks.entrySet()) { |
---|
64 | UsabilitySmellIntensity intensity = |
---|
65 | UsabilitySmellIntensity.getIntensity(entry.getValue(), entry.getKey(), taskModel); |
---|
66 | |
---|
67 | if (intensity != null) { |
---|
68 | Map<String, Object> parameters = new HashMap<String, Object>(); |
---|
69 | |
---|
70 | int instances = 0; |
---|
71 | int numberOfRepeatedInstances = 0; |
---|
72 | int cummulativeRepetitions = 0; |
---|
73 | |
---|
74 | for (ITaskInstance instance : entry.getKey().getInstances()) { |
---|
75 | instances++; |
---|
76 | |
---|
77 | if (((IIterationInstance) instance).size() > 1) { |
---|
78 | numberOfRepeatedInstances++; |
---|
79 | cummulativeRepetitions += ((IIterationInstance) instance).size() - 1; |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | parameters.put("repeatedInstanceRatio", |
---|
84 | (((float) instances) / numberOfRepeatedInstances)); |
---|
85 | parameters.put("averageRepetitionRatio", |
---|
86 | (((float) cummulativeRepetitions) / numberOfRepeatedInstances)); |
---|
87 | parameters.put("task", entry.getKey().getMarkedTask()); |
---|
88 | |
---|
89 | results.addSmell(entry.getKey().getMarkedTask(), intensity, |
---|
90 | UsabilitySmellDescription.TASK_RETRIED, parameters); |
---|
91 | } |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | /** |
---|
96 | * |
---|
97 | */ |
---|
98 | private Map<IIteration, Integer> getTasksWithRetries(Collection<ITask> tasks) { |
---|
99 | Map<IIteration, Integer> retryRatios = new HashMap<IIteration, Integer>(); |
---|
100 | |
---|
101 | for (ITask task : tasks) { |
---|
102 | if (isTaskOfConsideration(task)) { |
---|
103 | int rate = getRetryRate((IIteration) task); |
---|
104 | |
---|
105 | if (rate > 0) { |
---|
106 | retryRatios.put((IIteration) task, rate); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | return retryRatios; |
---|
112 | } |
---|
113 | |
---|
114 | /** |
---|
115 | * check if a task must be considered. A task is relevant, if it is an iteration of a sequence |
---|
116 | * which has at least two non-inefficient actions as leaf nodes. |
---|
117 | */ |
---|
118 | private boolean isTaskOfConsideration(ITask task) { |
---|
119 | if (!(task instanceof IIteration)) { |
---|
120 | return false; |
---|
121 | } |
---|
122 | |
---|
123 | if (!(((IIteration) task).getMarkedTask() instanceof ISequence)) { |
---|
124 | return false; |
---|
125 | } |
---|
126 | |
---|
127 | ISequence childTask = (ISequence) ((IIteration) task).getMarkedTask(); |
---|
128 | |
---|
129 | if ((childTask.getInstances() != null) && (childTask.getInstances().size() > 0)) { |
---|
130 | return getSemanticActions(childTask).size() > 1; |
---|
131 | } |
---|
132 | else { |
---|
133 | return false; |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * |
---|
139 | */ |
---|
140 | private List<IEventTask> getSemanticActions(ITask task) { |
---|
141 | final List<IEventTask> semanticEventTasks = new LinkedList<>(); |
---|
142 | |
---|
143 | task.accept(new DefaultTaskTraversingVisitor() { |
---|
144 | @Override |
---|
145 | public void visit(IEventTask eventTask) { |
---|
146 | if (!ActionClassifier.isInefficient(eventTask)) { |
---|
147 | semanticEventTasks.add(eventTask); |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | }); |
---|
152 | |
---|
153 | return semanticEventTasks; |
---|
154 | } |
---|
155 | |
---|
156 | /** |
---|
157 | * |
---|
158 | */ |
---|
159 | private int getRetryRate(IIteration task) { |
---|
160 | if (task.getInstances().size() > 0) { |
---|
161 | int numberOfRepetitions = 0; |
---|
162 | for (ITaskInstance instance : task.getInstances()) { |
---|
163 | numberOfRepetitions += ((IIterationInstance) instance).size() - 1; |
---|
164 | } |
---|
165 | |
---|
166 | return numberOfRepetitions * getSemanticActions(task).size(); |
---|
167 | } |
---|
168 | else { |
---|
169 | return 0; |
---|
170 | } |
---|
171 | } |
---|
172 | } |
---|