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
RevLine 
[1139]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
[1217]17import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter.TEXT_INPUT;
[1139]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
[1152]25import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
[1150]28import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
[1292]29import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
[1217]30import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
[1139]31import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
32import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
[1217]33import de.ugoe.cs.autoquest.usability.taskmodel.filter.FilterResult;
[1292]34import de.ugoe.cs.autoquest.usability.taskmodel.filter.TaskModelFilter;
[1139]35
36/**
37 * <p>
[1217]38 * Metric, which measures the ratio between the text input and the non text input events.
[1139]39 * </p>
40 *
41 * @author Alexander Deicke
42 */
43public class TextInputRatioMetric extends UsabilityRule implements UsabilityMetric {
44
45    /**
46     * <p>
[1217]47     * Constructor. Creates a new {@code TextInputRatioMetric} for a given task model.
[1139]48     * </p>
[1217]49     *
[1139]50     * @param taskTree
51     */
[1152]52    public TextInputRatioMetric(ITaskModel taskModel) {
53        super(taskModel);
[1139]54        this.name = "TextInputRatio";
[1217]55        this.defect =
56            new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
57                .getSimpleName());
[1139]58    }
59
[1217]60    /*
61     * (non-Javadoc)
62     *
[1139]63     * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
64     */
65    @Override
[1217]66    public Optional<UsabilityProblemDescription> calculate() {
[1139]67        FilterResult textInputEvents = extractNodesFromTaskTree();
[1217]68        float evaluationMetric =
69            calculateEvaluationMetric(textInputEvents.tasksMatchedFilter(),
70                                      textInputEvents.tasksNotMatchedFilter());
[1139]71        return this.defect.isPresent(evaluationMetric);
72    }
[1217]73
74    /**
75     *
76     * <p>
77     * Filters all text input events from task model.
78     * </p>
79     *
80     * @return {@code FilterResult}
81     */
[1139]82    private FilterResult extractNodesFromTaskTree() {
[1292]83        return new TaskModelFilter().filter(taskModel, TEXT_INPUT);
[1139]84    }
[1217]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    {
[1139]101        float numberOfTextInputEvents = textInputEvents.size();
[1152]102        float numberOfNonTextInputEvents = nrOfEventTasksNotMatchedFilter(nonTextInputEvents);
[1139]103        return numberOfTextInputEvents / (numberOfTextInputEvents + numberOfNonTextInputEvents);
104    }
105
[1217]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     */
[1152]116    private int nrOfEventTasksNotMatchedFilter(List<ITask> nonTextInputEvents) {
[1217]117        return Iterables.size(Iterables.filter(nonTextInputEvents, new Predicate<ITask>() {
[1139]118
[1217]119            @Override
120            public boolean apply(ITask task) {
121                return task instanceof IEventTask;
122            }
123        }));
[1139]124    }
125
[1217]126    /*
127     * (non-Javadoc)
128     *
129     * @see
130     * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
131     * .usability.EvaluationMethodCaller)
[1150]132     */
133    @Override
[1217]134    public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
[1150]135    {
136        return evaluationMethodCaller.check(this);
137    }
[1139]138}
Note: See TracBrowser for help on using the repository browser.