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

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

Added text metrics.

  • Property svn:mime-type set to text/plain
File size: 3.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.tasktree.filters.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.ITaskTree;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
27import de.ugoe.cs.autoquest.usability.result.DefectDescriptionResolver;
28import de.ugoe.cs.autoquest.usability.result.UsabilityDefect;
29import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
30import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
31import de.ugoe.cs.autoquest.usability.tasktree.FilterResult;
32import de.ugoe.cs.autoquest.usability.tasktree.IterativeDFSFilterStrategy;
33import de.ugoe.cs.autoquest.usability.tasktree.filters.TaskTreeFilter;
34
35/**
36 * <p>
37 * TODO comment
38 * </p>
39 *
40 * @author Alexander Deicke
41 */
42public class TextInputRatioMetric extends UsabilityRule implements UsabilityMetric {
43
44    /**
45     * <p>
46     * TODO: comment
47     * </p>
48     *
49     * @param taskTree
50     */
51    public TextInputRatioMetric(ITaskTree taskTree) {
52        super(taskTree);
53        this.name = "TextInputRatio";
54        this.defect = new DefectDescriptionResolver().descriptionFor(this.getClass().getSimpleName());
55    }
56
57    /* (non-Javadoc)
58     * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
59     */
60    @Override
61    public Optional<UsabilityDefect> check() {
62        FilterResult textInputEvents = extractNodesFromTaskTree();
63        float evaluationMetric = calculateEvaluationMetric(textInputEvents.nodesMatchedFilter(), textInputEvents.nodesNotMatchedFilter());
64        return this.defect.isPresent(evaluationMetric);
65    }
66   
67    private FilterResult extractNodesFromTaskTree() {
68        return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
69            .from(this.taskTree);
70    }
71   
72    private float calculateEvaluationMetric(List<ITaskTreeNode> textInputEvents, List<ITaskTreeNode> nonTextInputEvents) {
73        float numberOfTextInputEvents = textInputEvents.size();
74        float numberOfNonTextInputEvents = nrOfEventNodesNotMatchedFilter(nonTextInputEvents);
75        return numberOfTextInputEvents / (numberOfTextInputEvents + numberOfNonTextInputEvents);
76    }
77
78    private int nrOfEventNodesNotMatchedFilter(List<ITaskTreeNode> nonTextInputEvents) {
79        return Iterables.size(Iterables.filter(nonTextInputEvents,
80                                               new Predicate<ITaskTreeNode>() {
81
82                                                   @Override
83                                                   public boolean apply(ITaskTreeNode node) {
84                                                       return (node.getChildren() == null) ||
85                                                           (node.getChildren().size() == 0);
86                                                   }
87                                               }));
88    }
89
90}
Note: See TracBrowser for help on using the repository browser.