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

Last change on this file since 1493 was 1493, checked in by pharms, 10 years ago
  • state of the HCSE 2014 Paper. An appropriate tag will follow.
File size: 5.7 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.HashMap;
18import java.util.List;
19import java.util.Map;
20
21import de.ugoe.cs.autoquest.eventcore.gui.Scroll;
22import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
23import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric;
30
31/**
32 * TODO comment
33 *
34 * @version $Revision: $ $Date: 16.07.2012$
35 * @author 2012, last modified by $Author: pharms$
36 */
37public class TaskCooccurrenceRule implements UsabilityEvaluationRule {
38
39    /*
40     * (non-Javadoc)
41     *
42     * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree)
43     */
44    @Override
45    public UsabilityEvaluationResult evaluate(ITaskModel taskModel) {
46        UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel);
47
48        checkForCooccurrences(results, taskModel);
49
50        return results;
51    }
52
53    /**
54     *
55     */
56    private void checkForCooccurrences(UsabilityEvaluationResult results, ITaskModel taskModel) {
57        for (ITask task : taskModel.getTasks()) {
58            // only sequences are important for task cooccurrences
59            if (task instanceof ISequence) {
60                ISequence sequence = (ISequence) task;
61                int index1 = 0;
62                int index2 = 1;
63                List<ITask> children = sequence.getChildren();
64               
65                while (index2 < children.size()) {
66                    ITask task1 = children.get(index1);
67                    ITask task2 = children.get(index2);
68                    ITaskInfo info1 = taskModel.getTaskInfo(task1);
69                    ITaskInfo info2 = taskModel.getTaskInfo(task2);
70                   
71                    int ratioTask1 = 1000 * info1.getMeasureValue(TaskMetric.COUNT, sequence) /
72                        info1.getMeasureValue(TaskMetric.COUNT);
73                    int ratioTask2 = 1000 * info2.getMeasureValue(TaskMetric.COUNT, sequence) /
74                            info2.getMeasureValue(TaskMetric.COUNT);
75                   
76                    createSucceededDefectIfRequired(ratioTask1, task1, task2, results, taskModel);
77                    createPrecededDefectIfRequired(ratioTask2, task1, task2, results, taskModel);
78                   
79                    index1 = index2;
80                    index2++;
81                }
82            }
83        }
84    }
85
86    /**
87     *
88     */
89    private void createSucceededDefectIfRequired(int                       ratio,
90                                                 ITask                     task1,
91                                                 ITask                     task2,
92                                                 UsabilityEvaluationResult results,
93                                                 ITaskModel                taskModel)
94    {
95        //TODO document magic numbers
96        UsabilityDefectSeverity severity = UsabilityDefectSeverity.getSeverity
97            (ratio, 900, 700, 500, 300, task1, taskModel);
98
99        if (!isScroll(task1) && !isScroll(task2) && (severity != null)) {
100            Map<String, Object> parameters = new HashMap<String, Object>();
101            parameters.put("task1", task1);
102            parameters.put("task2", task2);
103            parameters.put("ratio", (ratio / 10));
104
105            results.addDefect(severity, UsabilityDefectDescription.COOCCURENCE_SUCCEED, parameters);
106        }
107    }
108
109    /**
110     *
111     */
112    private void createPrecededDefectIfRequired(int                       ratio,
113                                                ITask                     task1,
114                                                ITask                     task2,
115                                                UsabilityEvaluationResult results,
116                                                ITaskModel                taskModel)
117    {
118        //TODO document magic numbers
119        UsabilityDefectSeverity severity = UsabilityDefectSeverity.getSeverity
120            (ratio, 900, 700, 500, 300, task2, taskModel);
121
122        if (!isScroll(task1) && !isScroll(task2) && (severity != null)) {
123            Map<String, Object> parameters = new HashMap<String, Object>();
124            parameters.put("task1", task1);
125            parameters.put("task2", task2);
126            parameters.put("ratio", (ratio / 10));
127
128            results.addDefect(severity, UsabilityDefectDescription.COOCCURENCE_PRECED, parameters);
129        }
130    }
131
132    /**
133     * <p>
134     * TODO: comment
135     * </p>
136     *
137     * @param task1
138     * @return
139     */
140    private boolean isScroll(ITask task) {
141        if (task instanceof IEventTask) {
142            return ((IEventTaskInstance) ((IEventTask) task).getInstances().iterator().next()).getEvent().getType() instanceof Scroll;
143        }
144        else if (task instanceof IIteration) {
145            return isScroll(((IIteration) task).getMarkedTask());
146        }
147       
148        return false;
149    }
150}
Note: See TracBrowser for help on using the repository browser.