[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 |
|
---|
| 15 | package de.ugoe.cs.autoquest.usability.rules.metrics;
|
---|
| 16 |
|
---|
| 17 | import static de.ugoe.cs.autoquest.usability.tasktree.filters.EventTypeFilter.TEXT_INPUT;
|
---|
| 18 |
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
| 21 | import com.google.common.base.Optional;
|
---|
| 22 | import com.google.common.base.Predicate;
|
---|
| 23 | import com.google.common.collect.Iterables;
|
---|
| 24 |
|
---|
| 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTree;
|
---|
| 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
[1150] | 27 | import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
|
---|
[1139] | 28 | import de.ugoe.cs.autoquest.usability.result.DefectDescriptionResolver;
|
---|
| 29 | import de.ugoe.cs.autoquest.usability.result.UsabilityDefect;
|
---|
| 30 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
| 31 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
| 32 | import de.ugoe.cs.autoquest.usability.tasktree.FilterResult;
|
---|
| 33 | import de.ugoe.cs.autoquest.usability.tasktree.IterativeDFSFilterStrategy;
|
---|
| 34 | import de.ugoe.cs.autoquest.usability.tasktree.filters.TaskTreeFilter;
|
---|
| 35 |
|
---|
| 36 | /**
|
---|
| 37 | * <p>
|
---|
| 38 | * TODO comment
|
---|
| 39 | * </p>
|
---|
| 40 | *
|
---|
| 41 | * @author Alexander Deicke
|
---|
| 42 | */
|
---|
| 43 | public class TextInputRatioMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 44 |
|
---|
| 45 | /**
|
---|
| 46 | * <p>
|
---|
| 47 | * TODO: comment
|
---|
| 48 | * </p>
|
---|
| 49 | *
|
---|
| 50 | * @param taskTree
|
---|
| 51 | */
|
---|
| 52 | public TextInputRatioMetric(ITaskTree taskTree) {
|
---|
| 53 | super(taskTree);
|
---|
| 54 | this.name = "TextInputRatio";
|
---|
| 55 | this.defect = new DefectDescriptionResolver().descriptionFor(this.getClass().getSimpleName());
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | /* (non-Javadoc)
|
---|
| 59 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 60 | */
|
---|
| 61 | @Override
|
---|
[1150] | 62 | public Optional<UsabilityDefect> calculate() {
|
---|
[1139] | 63 | FilterResult textInputEvents = extractNodesFromTaskTree();
|
---|
| 64 | float evaluationMetric = calculateEvaluationMetric(textInputEvents.nodesMatchedFilter(), textInputEvents.nodesNotMatchedFilter());
|
---|
| 65 | return this.defect.isPresent(evaluationMetric);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | private FilterResult extractNodesFromTaskTree() {
|
---|
| 69 | return new TaskTreeFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
|
---|
| 70 | .from(this.taskTree);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | private float calculateEvaluationMetric(List<ITaskTreeNode> textInputEvents, List<ITaskTreeNode> nonTextInputEvents) {
|
---|
| 74 | float numberOfTextInputEvents = textInputEvents.size();
|
---|
| 75 | float numberOfNonTextInputEvents = nrOfEventNodesNotMatchedFilter(nonTextInputEvents);
|
---|
| 76 | return numberOfTextInputEvents / (numberOfTextInputEvents + numberOfNonTextInputEvents);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | private int nrOfEventNodesNotMatchedFilter(List<ITaskTreeNode> nonTextInputEvents) {
|
---|
| 80 | return Iterables.size(Iterables.filter(nonTextInputEvents,
|
---|
| 81 | new Predicate<ITaskTreeNode>() {
|
---|
| 82 |
|
---|
| 83 | @Override
|
---|
| 84 | public boolean apply(ITaskTreeNode node) {
|
---|
| 85 | return (node.getChildren() == null) ||
|
---|
| 86 | (node.getChildren().size() == 0);
|
---|
| 87 | }
|
---|
| 88 | }));
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[1150] | 91 | /* (non-Javadoc)
|
---|
| 92 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest.usability.EvaluationMethodCaller)
|
---|
| 93 | */
|
---|
| 94 | @Override
|
---|
| 95 | public Optional<UsabilityDefect> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
| 96 | {
|
---|
| 97 | return evaluationMethodCaller.check(this);
|
---|
| 98 | }
|
---|
[1139] | 99 | }
|
---|