source: trunk/autoquest-plugin-usability2/src/main/java/de/ugoe/cs/autoquest/plugin/usability2/rules/patterns/InputMethodSwitching.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: 6.0 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.patterns;
16
17import java.util.Collection;
18import java.util.List;
19
20import com.google.common.base.Optional;
21
22import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
23import de.ugoe.cs.autoquest.eventcore.gui.MouseInteraction;
24import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
25import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection;
26import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
27import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
28import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
29import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
30import de.ugoe.cs.autoquest.usability.rules.UsabilityUsageProblem;
31import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.filter.MultiEventTypeFilter;
32import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.EventSequence;
33import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.EventSequences;
34import de.ugoe.cs.autoquest.plugin.usability2.rules.operator.wrapper.GenerateInstanceListVisitor;
35import de.ugoe.cs.autoquest.plugin.usability2.statistics.Histogramm;
36import de.ugoe.cs.autoquest.plugin.usability2.tools.TaskUtilities;
37import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
38import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
39import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance;
40import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
41import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
42import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
43
44/**
45 * <p>
46 * Test Rule to see if new pattern method may be used for problem checking
47 * </p>
48 *
49 * @author Konni Hartmann
50 */
51public class InputMethodSwitching extends UsabilityRule implements UsabilityUsageProblem {
52
53    /**
54     * <p>
55     * TODO: comment
56     * </p>
57     *
58     * @param taskTree
59     */
60    public InputMethodSwitching(ITaskModel taskModel) {
61        super(taskModel);
62        this.name = "InputMethodSwitching";
63        this.defect = new UsabilityProblemDescriptionResolver().descriptionFor("InputMethodSwitching");
64        initUsagePattern();
65    }
66
67    /**
68     * <p>
69     * TODO: comment
70     * </p>
71     *
72     */
73    private void initUsagePattern() {}
74
75    private static enum InputState {
76        unknown, mouse, keyboard
77    }
78   
79    /*
80     * (non-Javadoc)
81     *
82     * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
83     */
84    @Override
85    public Optional<UsabilityProblemDescription> check() {
86        Optional<UsabilityProblemDescription> present = Optional.absent();
87
88        float maxRatio = Float.MIN_VALUE;
89        ITask mostSwitches = null;
90       
91        System.out.println("--");
92        System.out.println("InputMethodSwitching:");
93
94        MultiEventTypeFilter keyboardInputFilter = new MultiEventTypeFilter(TextInput.class);
95        MultiEventTypeFilter mouseInputFilter = new MultiEventTypeFilter(MouseInteraction.class);
96       
97        GenerateInstanceListVisitor v = new GenerateInstanceListVisitor();
98        for (ITask task : taskModel.getTasks()) {           
99            Collection<List<IEventTaskInstance>> instanceList = v.generateInstanceList(task);
100           
101            int instances = instanceList.size();
102            int switches = 0;
103           
104            for (List<IEventTaskInstance> list : instanceList) {
105                InputState current = InputState.unknown;
106
107                for (IEventTaskInstance event : list) {
108                    if ( keyboardInputFilter.matchesType(event.getEvent().getType()) ) {
109                        switch (current)
110                        {
111                            case mouse:
112                                switches++;
113                            case unknown:
114                                current = InputState.keyboard;
115                            default:
116                                break;
117                        }
118                                               
119                    } else if (mouseInputFilter.matchesType(event.getEvent().getType())) {
120                        switch (current)
121                        {
122                            case keyboard:
123                                switches++;
124                            case unknown:
125                                current = InputState.mouse;
126                            default:
127                                break;
128                        }                       
129                    }
130                }
131            }
132           
133            float ratio = (float)switches / instances;
134            if (ratio > maxRatio) {
135                maxRatio = ratio;
136                mostSwitches = task;
137            }
138        }
139
140        System.out.printf("Most Switches in %s [%f]\n", mostSwitches.getDescription(), maxRatio);
141        System.out.println("Finished InputMethodSwitching");
142        return present;
143    }
144
145    /*
146     * (non-Javadoc)
147     *
148     * @see
149     * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
150     * .usability.EvaluationMethodCaller)
151     */
152    @Override
153    public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
154    {
155        return evaluationMethodCaller.check(this);
156    }
157}
Note: See TracBrowser for help on using the repository browser.