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

Last change on this file since 2162 was 2162, checked in by pharms, 7 years ago
  • changes for first VR oriented usability evaluation
File size: 6.9 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.LinkedList;
19import java.util.List;
20import java.util.Map;
21import java.util.regex.Matcher;
22import java.util.regex.Pattern;
23
24import de.ugoe.cs.autoquest.eventcore.Event;
25import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
28import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence;
29import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
30import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
31import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
32
33/**
34 * TODO comment
35 *
36 * @version $Revision: $ $Date: 16.07.2012$
37 * @author 2012, last modified by $Author: pharms$
38 */
39public class TargetDistanceRule implements UsabilityEvaluationRule {
40   
41    /** pattern for parsing target position parameter values */
42    private Pattern targetPositionPattern = Pattern.compile
43            ("\\(\\s*(-?\\d*(\\.\\d*)?),\\s*(-?\\d*(\\.\\d*)?),\\s*(-?\\d*(\\.\\d*)?)\\s*\\)");
44
45    /*
46     * (non-Javadoc)
47     *
48     * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree)
49     */
50    @Override
51    public UsabilityEvaluationResult evaluate(ITaskModel taskModel) {
52        UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel);
53
54        checkForTargetDistances(results, taskModel);
55
56        return results;
57    }
58
59    /**
60     *
61     */
62    private void checkForTargetDistances(UsabilityEvaluationResult results, ITaskModel taskModel) {
63        for (ITask task : taskModel.getTasks()) {
64            if (task instanceof ISequence) {
65
66                int cummulativeNoOfHops = 0;
67                int cummulativeDistance = 0;
68
69                for (ITaskInstance instance : task.getInstances()) {
70                    int[] stats = getTargetDistance(instance);
71                    cummulativeNoOfHops += stats[0] - 1;
72                    cummulativeDistance += stats[1];
73                }
74
75                createHighTargetDisanceIfRequired
76                    (cummulativeNoOfHops, cummulativeDistance, task, results, taskModel);
77            }
78        }
79    }
80
81    /**
82     *
83     */
84    private int[] getTargetDistance(ITaskInstance instance) {
85        List<Event> events = new LinkedList<Event>();
86        getEvents(instance, events);
87        int noOfEvents = events.size();
88        int distance = 0;
89       
90        while (events.size() > 1) {
91            distance += getDistance(events.get(0), events.get(1));
92            events.remove(0);
93        }
94       
95        return new int[] { noOfEvents, distance };
96    }
97
98    /**
99     *
100     */
101    private int getDistance(Event event1, Event event2) {
102        String location1 = event1.getParameter("targetPosition");
103        String location2 = event2.getParameter("targetPosition");
104       
105        if ((location1 != null) && (location2 != null)) {
106            Matcher matcher1 = targetPositionPattern.matcher(location1);
107            Matcher matcher2 = targetPositionPattern.matcher(location2);
108            if (matcher1.matches() && matcher2.matches()) {
109                try {
110                    double x =
111                        Double.parseDouble(matcher2.group(1)) - Float.parseFloat(matcher1.group(1));
112                   
113                    double y =
114                        Double.parseDouble(matcher2.group(3)) - Float.parseFloat(matcher1.group(3));
115                   
116                    double z =
117                        Double.parseDouble(matcher2.group(5)) - Float.parseFloat(matcher1.group(5));
118                   
119                    return (int) (100 * Math.sqrt(x*x + y*y + z*z));
120                }
121                catch (NumberFormatException e) {
122                    // ignore and just continue with other variants.
123                }
124            }
125        }
126       
127        if ((event1.getTarget() instanceof IGUIElement) &&
128            (event2.getTarget() instanceof IGUIElement))
129        {
130            IGUIElement target1 = (IGUIElement) event1.getTarget();
131            IGUIElement target2 = (IGUIElement) event2.getTarget();
132            return (int) (1000 * target1.getDistanceTo(target2));
133        }
134       
135        if (event1.getTarget().equals(event2.getTarget())) {
136            return 0;
137        }
138       
139        return 1000;
140    }
141
142    /**
143     *
144     */
145    private void getEvents(ITaskInstance instance, final List<Event> events) {
146        instance.accept(new DefaultTaskInstanceTraversingVisitor() {
147            @Override
148            public void visit(IEventTaskInstance eventTaskInstance) {
149                if (!(ActionClassifier.isInefficient(eventTaskInstance.getEvent()))) {
150                    events.add(eventTaskInstance.getEvent());
151                }
152            }
153        });
154    }
155
156    /**
157     *
158     */
159    private void createHighTargetDisanceIfRequired(int                       cummulativeNoOfHops,
160                                                   int                       cummulativeDistance,
161                                                   ITask                     task,
162                                                   UsabilityEvaluationResult results,
163                                                   ITaskModel                taskModel)
164    {
165        if ((cummulativeDistance > 0) && (cummulativeNoOfHops > 0)) {
166            int ratio = cummulativeDistance / cummulativeNoOfHops;
167
168            // for HTML: 800 means not even on the same server
169            // for HTML: 600 means not on the same page
170            // for HTML: 501 means in average not on the same page
171            UsabilitySmellIntensity severity =
172                UsabilitySmellIntensity.getIntensity(ratio, task, taskModel);
173
174            if (severity != null) {
175                double averageNoOfGUIElements =
176                    ((double) cummulativeNoOfHops / task.getInstances().size()) + 1;
177               
178                Map<String, Object> parameters = new HashMap<String, Object>();
179                parameters.put("task", task);
180                parameters.put("noOfGUIElements", averageNoOfGUIElements);
181                parameters.put("distance", ((double) ratio / 1000));
182
183                results.addSmell
184                    (task, severity, UsabilitySmellDescription.HIGH_TARGET_DISTANCE, parameters);
185            }
186        }
187    }
188
189}
Note: See TracBrowser for help on using the repository browser.