1 | package de.ugoe.cs.autoquest.usability.evaluation.rule.evaluator;
|
---|
2 |
|
---|
3 | import static de.ugoe.cs.autoquest.usability.tasktree.filter.EventTypeFilter.TEXT_INPUT;
|
---|
4 |
|
---|
5 | import com.google.common.base.Optional;
|
---|
6 | import com.google.common.base.Predicate;
|
---|
7 | import com.google.common.collect.Iterables;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
10 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
11 | import de.ugoe.cs.autoquest.usability.evaluation.result.UsabilityDefectSeverityLevel;
|
---|
12 | import de.ugoe.cs.autoquest.usability.evaluation.rule.set.UsabilityRule;
|
---|
13 | import de.ugoe.cs.autoquest.usability.tasktree.filter.FilterStatistic;
|
---|
14 | import de.ugoe.cs.autoquest.usability.tasktree.filter.IterativeDFSFilterStrategy;
|
---|
15 | import de.ugoe.cs.autoquest.usability.tasktree.filter.TaskTreeFilter;
|
---|
16 |
|
---|
17 | public class TextInputRatioEvaluator extends RuleEvaluator {
|
---|
18 |
|
---|
19 | public TextInputRatioEvaluator(UsabilityRule evaluatedUsabilityRule, ITaskTree taskTree) {
|
---|
20 | super(evaluatedUsabilityRule, taskTree);
|
---|
21 | }
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | protected FilterStatistic nodesUnderEvaluation(ITaskTree taskTree) {
|
---|
25 | Optional<FilterStatistic> cachedNodes = loadFromCache(TEXT_INPUT);
|
---|
26 | return cachedNodes.isPresent() ? cachedNodes.get() : cacheAndReturnNodes(taskTree, TEXT_INPUT);
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | protected FilterStatistic extractNodesFromTaskTree(ITaskTree taskTree) {
|
---|
31 | return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT).from(taskTree);
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Override
|
---|
35 | protected float calculateEvaluationMetric() {
|
---|
36 | float textInputEvents = this.filteredNodes.nrOfNodesMatchedFilter();
|
---|
37 | float nonTextInputEvents = nrOfEventNodesNotMatchedFilter();
|
---|
38 | return textInputEvents / (textInputEvents + nonTextInputEvents);
|
---|
39 | }
|
---|
40 |
|
---|
41 | private int nrOfEventNodesNotMatchedFilter() {
|
---|
42 | return Iterables.size(
|
---|
43 | Iterables.filter(this.filteredNodes.nodesNotMatchedFilter(), new Predicate<ITaskTreeNode>() {
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public boolean apply(ITaskTreeNode node) {
|
---|
47 | return (node.getChildren() == null) || (node.getChildren().size() == 0);
|
---|
48 | }
|
---|
49 | })
|
---|
50 | );
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | protected Optional<UsabilityDefectSeverityLevel> determineSeverityLevel(float evaluationMetric) {
|
---|
55 | Optional<UsabilityDefectSeverityLevel> recommendationSeverityLevel = Optional.absent();
|
---|
56 | if (evaluationMetric > 0.9) {
|
---|
57 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.HIGH);
|
---|
58 | }
|
---|
59 | else if (evaluationMetric > 0.7) {
|
---|
60 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.MEDIUM);
|
---|
61 | }
|
---|
62 | else if (evaluationMetric > 0.5) {
|
---|
63 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.LOW);
|
---|
64 | }
|
---|
65 | else if (evaluationMetric > 0.3) {
|
---|
66 | recommendationSeverityLevel = Optional.of(UsabilityDefectSeverityLevel.INFO);
|
---|
67 | }
|
---|
68 | return recommendationSeverityLevel;
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|