source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/evaluation/rule/evaluator/NoLetterOrDigitTextInputsEvaluator.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.3 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;
18import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.aggregateEnteredTextFromTextInputs;
19import static de.ugoe.cs.autoquest.usability.util.TextInputUtil.characterIsLetterOrDigitPredicate;
20
21import com.google.common.base.CharMatcher;
22import com.google.common.base.Optional;
23import com.google.common.collect.Multiset;
24
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
26import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
27import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
28import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
29import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
30import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
31
32/**
33 * <p>
34 * TODO comment
35 * </p>
36 *
37 * @author Alexander Deicke
38 */
39public class NoLetterOrDigitTextInputsEvaluator extends RuleEvaluator {
40
41    public NoLetterOrDigitTextInputsEvaluator(UsabilityRule evaluatedUsabilityRule,
42                                              ITaskTree taskTree)
43    {
44        super(evaluatedUsabilityRule, taskTree);
45    }
46
47    @Override
48    protected FilterStatistic nodesUnderEvaluation(ITaskTree taskTree) {
49        Optional<FilterStatistic> cachedNodes = loadFromCache(TEXT_INPUT);
50        return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree,
51                                                                                 TEXT_INPUT);
52    }
53
54    @Override
55    protected FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree) {
56        return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
57            .from(taskTree);
58    }
59
60    @Override
61    protected float calculateEvaluationMetric() {
62        Multiset<String> enteredTextFragments =
63            aggregateEnteredTextFromTextInputs(this.filteredNodes.nodesMatchedFilter());
64        int allCharactersCount = 0;
65        int noLetterOrDigitCount = 0;
66        for (String textFragment : enteredTextFragments.elementSet()) {
67            int occurencesOfTextFragment = enteredTextFragments.count(textFragment);
68            allCharactersCount += CharMatcher.ANY.countIn(textFragment) * occurencesOfTextFragment;
69            noLetterOrDigitCount +=
70                CharMatcher.forPredicate(characterIsLetterOrDigitPredicate()).countIn(textFragment) *
71                    occurencesOfTextFragment;
72        }
73        return allCharactersCount != 0 ? (float) noLetterOrDigitCount / (float) allCharactersCount
74            : 0;
75    }
76
77    @Override
78    protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric)
79    {
80        Optional<UsabilityDefectSeverityLevel> recommendationSeverityLevel = Optional.absent();
81        if (evaluationMetric > 0.1) // every 10th sign
82        {
83            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.HIGH);
84        }
85        else if (evaluationMetric > 0.05) // every 20th sign
86        {
87            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.MEDIUM);
88        }
89        else if (evaluationMetric > 0.02) // every 50th sign
90        {
91            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.LOW);
92        }
93        else if (evaluationMetric > 0.01) // every 100th sign
94        {
95            recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.INFO);
96        }
97        return recommendationSeverityLevel;
98    }
99
100}
Note: See TracBrowser for help on using the repository browser.