source: trunk/autoquest-plugin-usability2/src/main/java/de/ugoe/cs/autoquest/plugin/usability2/rules/metrics/SameTargetEditingMetric.java @ 1326

Last change on this file since 1326 was 1326, checked in by khartmann, 10 years ago

Moved alexanders code into a new plugin project.
First commit of my experimental code (needs a lot of cleanup).

File size: 5.3 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.plugin.usability2.rules.metrics;
16
17import java.util.Collection;
18import java.util.HashMap;
19import java.util.Map;
20import java.util.Map.Entry;
21
22import com.google.common.base.Optional;
23
24import de.ugoe.cs.autoquest.eventcore.Event;
25import de.ugoe.cs.autoquest.eventcore.IEventTarget;
26import de.ugoe.cs.autoquest.eventcore.IEventType;
27import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
28import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection;
29import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
30import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
31import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
32import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
33import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
34import de.ugoe.cs.autoquest.plugin.usability2.rules.metrics.visitor.AbstractMetricVisitor;
35import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
36import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
37import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
38import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
39
40/**
41 * <p>
42 * Metric, which measures directed scrolling compared to back-and-forth type of scrolling. This is
43 * done by calculating the absolute distance scrolled compared to the relative >>>
44 * </p>
45 *
46 * @author Konni Hartmann
47 */
48public class SameTargetEditingMetric extends UsabilityRule implements UsabilityMetric {
49
50    /**
51     * <p>
52     * Constructor. Creates a new {@code TextInputRatioMetric} for a given task model.
53     * </p>
54     *
55     * @param taskTree
56     */
57    public SameTargetEditingMetric(ITaskModel taskModel) {
58        super(taskModel);
59        this.name = "SameTargetEditingMetric";
60        this.defect =
61            new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
62                .getSimpleName());
63    }
64
65
66    /*
67     * (non-Javadoc)
68     *
69     * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
70     */
71    @Override
72    public Optional<UsabilityProblemDescription> calculate() {
73        Collection<IUserSession> ses = taskModel.getUserSessions();
74        float evaluationMetric =
75            calculateEvaluationMetric(ses);
76        return this.defect.isPresent(evaluationMetric);
77    }
78       
79    class Data {
80        Map<IEventTarget, Integer> map = new HashMap<IEventTarget, Integer>();
81       
82        void updateTarget(IEventTarget target, IEventType type) {
83            Integer data = map.get(target);
84            if(data == null) {
85                data = 0;
86            }
87            data++;
88            map.put(target, data);
89        }
90    }
91 
92    private float calculateEvaluationMetric(Collection<IUserSession> tasks) {
93        int maxEditsPerTarget = 0;
94        IEventTarget maxTarget = null;
95       
96        for (IUserSession s : tasks) {
97            Collection<ITaskInstance> instances = s.getExecutedTasks();
98           
99            final Data data = new Data();
100
101            for (ITaskInstance iTaskInstance : instances) {
102
103                AbstractMetricVisitor visitor = new AbstractMetricVisitor(){
104                    @Override
105                    public void visit(IEventTaskInstance instance) {
106                        Event event = instance.getEvent();
107                        IEventType type = event.getType();
108                        if (type instanceof TextInput ||
109                            type instanceof ValueSelection) {
110                            data.updateTarget(event.getTarget(), type);
111                        }
112                    }
113                };
114               
115                visitor.visit(iTaskInstance);
116            }
117
118            for (Entry<IEventTarget, Integer> entry : data.map.entrySet()) {
119                if (entry.getValue() > maxEditsPerTarget) {
120                    maxTarget = entry.getKey();
121                    maxEditsPerTarget = entry.getValue();
122                }
123            }
124        }
125
126        if (maxTarget != null)
127            System.out.printf("(STE) Highest ranking target: %s (%d) \n", maxTarget.getStringIdentifier(), maxEditsPerTarget);
128        else
129            System.out.println("(STE) No target found");
130       
131        return maxEditsPerTarget;
132    }
133
134    /*
135     * (non-Javadoc)
136     *
137     * @see
138     * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
139     * .usability.EvaluationMethodCaller)
140     */
141    @Override
142    public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
143    {
144        return evaluationMethodCaller.check(this);
145    }
146}
Note: See TracBrowser for help on using the repository browser.