source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/rule/evaluator/TextInputRatioEvaluator.java @ 1040

Last change on this file since 1040 was 1040, checked in by adeicke, 11 years ago
  • Removed lombok related annotations and util class
  • Added comments and formating due to match project defaults
  • Property svn:mime-type set to text/plain
File size: 4.1 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.evaluation.rule.evaluator;
16
17import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.TEXT_INPUT;
18
19import com.google.common.base.Optional;
20import com.google.common.base.Predicate;
21import com.google.common.collect.Iterables;
22
23import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
25import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
26import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
27import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
28import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
29import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
30
31/**
32 * <p>
33 * TODO comment
34 * </p>
35 *
36 * @author Alexander Deicke
37 */
38public class TextInputRatioEvaluator extends RuleEvaluator {
39
40    public TextInputRatioEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) {
41        super(evaluatedUsabilityRule, taskTree);
42    }
43
44    @Override
45    protected FilterStatistic nodesUnderEvaluation(ITaskTree taskTree) {
46        Optional<FilterStatistic> cachedNodes = loadFromCache(TEXT_INPUT);
47        return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree,
48                                                                                 TEXT_INPUT);
49    }
50
51    @Override
52    protected FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree) {
53        return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
54            .from(taskTree);
55    }
56
57    @Override
58    protected float calculateEvaluationMetric() {
59        float textInputEvents = this.filteredNodes.nrOfNodesMatchedFilter();
60        float nonTextInputEvents = nrOfEventNodesNotMatchedFilter();
61        return textInputEvents / (textInputEvents + nonTextInputEvents);
62    }
63
64    private int nrOfEventNodesNotMatchedFilter() {
65        return Iterables.size(Iterables.filter(this.filteredNodes.nodesNotMatchedFilter(),
66                                               new Predicate<ITaskTreeNode>() {
67
68                                                   @Override
69                                                   public boolean apply(ITaskTreeNode node) {
70                                                       return (node.getChildren() == null) ||
71                                                           (node.getChildren().size() == 0);
72                                                   }
73                                               }));
74    }
75
76    @Override
77    protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric)
78    {
79        Optional<UsabilityDefectSeverityLevel> recommendationSeverityLevel = Optional.absent();
80        if (evaluationMetric > 0.9) {
81            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.HIGH);
82        }
83        else if (evaluationMetric > 0.7) {
84            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.MEDIUM);
85        }
86        else if (evaluationMetric > 0.5) {
87            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.LOW);
88        }
89        else if (evaluationMetric > 0.3) {
90            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.INFO);
91        }
92        return recommendationSeverityLevel;
93    }
94
95}
Note: See TracBrowser for help on using the repository browser.