source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/rules/metrics/TextInputRatioMetric.java @ 1217

Last change on this file since 1217 was 1217, checked in by adeicke, 11 years ago
  • Added proper formating and JavaDoc?.
  • Several renaming refactorings.
  • Property svn:mime-type set to text/plain
File size: 4.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.rules.metrics;
16
17import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter.TEXT_INPUT;
18
19import java.util.List;
20
21import com.google.common.base.Optional;
22import com.google.common.base.Predicate;
23import com.google.common.collect.Iterables;
24
25import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
28import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
29import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
30import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
31import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
32import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
33import de.ugoe.cs.autoquest.usability.taskmodel.filter.FilterResult;
34import de.ugoe.cs.autoquest.usability.taskmodel.filter.IterativeDFSFilterStrategy;
35import de.ugoe.cs.autoquest.usability.taskmodel.filter.types.TaskModelFilter;
36
37/**
38 * <p>
39 * Metric, which measures the ratio between the text input and the non text input events.
40 * </p>
41 *
42 * @author Alexander Deicke
43 */
44public class TextInputRatioMetric extends UsabilityRule implements UsabilityMetric {
45
46    /**
47     * <p>
48     * Constructor. Creates a new {@code TextInputRatioMetric} for a given task model.
49     * </p>
50     *
51     * @param taskTree
52     */
53    public TextInputRatioMetric(ITaskModel taskModel) {
54        super(taskModel);
55        this.name = "TextInputRatio";
56        this.defect =
57            new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
58                .getSimpleName());
59    }
60
61    /*
62     * (non-Javadoc)
63     *
64     * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
65     */
66    @Override
67    public Optional<UsabilityProblemDescription> calculate() {
68        FilterResult textInputEvents = extractNodesFromTaskTree();
69        float evaluationMetric =
70            calculateEvaluationMetric(textInputEvents.tasksMatchedFilter(),
71                                      textInputEvents.tasksNotMatchedFilter());
72        return this.defect.isPresent(evaluationMetric);
73    }
74
75    /**
76     *
77     * <p>
78     * Filters all text input events from task model.
79     * </p>
80     *
81     * @return {@code FilterResult}
82     */
83    private FilterResult extractNodesFromTaskTree() {
84        return new TaskModelFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
85            .from(this.taskModel);
86    }
87
88    /**
89     *
90     * <p>
91     * Calculates the metric.
92     * </p>
93     *
94     * @param textInputEvents
95     *            all text input events
96     * @param nonTextInputEvents
97     *            all non text input events
98     * @return ratio between text input and non text input events
99     */
100    private float calculateEvaluationMetric(List<ITask> textInputEvents,
101                                            List<ITask> nonTextInputEvents)
102    {
103        float numberOfTextInputEvents = textInputEvents.size();
104        float numberOfNonTextInputEvents = nrOfEventTasksNotMatchedFilter(nonTextInputEvents);
105        return numberOfTextInputEvents / (numberOfTextInputEvents + numberOfNonTextInputEvents);
106    }
107
108    /**
109     *
110     * <p>
111     * Filters all {@link IEventTask}s from non text input event.
112     * </p>
113     *
114     * @param nonTextInputEvents
115     *            all non text input events
116     * @return number of {@link IEventTask}s
117     */
118    private int nrOfEventTasksNotMatchedFilter(List<ITask> nonTextInputEvents) {
119        return Iterables.size(Iterables.filter(nonTextInputEvents, new Predicate<ITask>() {
120
121            @Override
122            public boolean apply(ITask task) {
123                return task instanceof IEventTask;
124            }
125        }));
126    }
127
128    /*
129     * (non-Javadoc)
130     *
131     * @see
132     * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
133     * .usability.EvaluationMethodCaller)
134     */
135    @Override
136    public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
137    {
138        return evaluationMethodCaller.check(this);
139    }
140}
Note: See TracBrowser for help on using the repository browser.