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

Last change on this file since 1292 was 1292, checked in by adeicke, 11 years ago

Refactored filter mechanism.

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