[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 |
|
---|
[1152] | 25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
| 26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
| 27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
[1150] | 28 | import de.ugoe.cs.autoquest.usability.EvaluationMethodCaller;
|
---|
[1139] | 29 | import de.ugoe.cs.autoquest.usability.result.DefectDescriptionResolver;
|
---|
| 30 | import de.ugoe.cs.autoquest.usability.result.UsabilityDefect;
|
---|
| 31 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
| 32 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
| 33 | import de.ugoe.cs.autoquest.usability.tasktree.FilterResult;
|
---|
| 34 | import de.ugoe.cs.autoquest.usability.tasktree.IterativeDFSFilterStrategy;
|
---|
[1152] | 35 | import de.ugoe.cs.autoquest.usability.tasktree.filters.TaskModelFilter;
|
---|
[1139] | 36 |
|
---|
| 37 | /**
|
---|
| 38 | * <p>
|
---|
| 39 | * TODO comment
|
---|
| 40 | * </p>
|
---|
| 41 | *
|
---|
| 42 | * @author Alexander Deicke
|
---|
| 43 | */
|
---|
| 44 | public class TextInputRatioMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * <p>
|
---|
| 48 | * TODO: comment
|
---|
| 49 | * </p>
|
---|
| 50 | *
|
---|
| 51 | * @param taskTree
|
---|
| 52 | */
|
---|
[1152] | 53 | public TextInputRatioMetric(ITaskModel taskModel) {
|
---|
| 54 | super(taskModel);
|
---|
[1139] | 55 | this.name = "TextInputRatio";
|
---|
| 56 | this.defect = new DefectDescriptionResolver().descriptionFor(this.getClass().getSimpleName());
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /* (non-Javadoc)
|
---|
| 60 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 61 | */
|
---|
| 62 | @Override
|
---|
[1150] | 63 | public Optional<UsabilityDefect> calculate() {
|
---|
[1139] | 64 | FilterResult textInputEvents = extractNodesFromTaskTree();
|
---|
[1152] | 65 | float evaluationMetric = calculateEvaluationMetric(textInputEvents.tasksMatchedFilter(), textInputEvents.tasksNotMatchedFilter());
|
---|
[1139] | 66 | return this.defect.isPresent(evaluationMetric);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | private FilterResult extractNodesFromTaskTree() {
|
---|
[1152] | 70 | return new TaskModelFilter(new IterativeDFSFilterStrategy()).filterByEventType(TEXT_INPUT)
|
---|
| 71 | .from(this.taskModel);
|
---|
[1139] | 72 | }
|
---|
| 73 |
|
---|
[1152] | 74 | private float calculateEvaluationMetric(List<ITask> textInputEvents, List<ITask> nonTextInputEvents) {
|
---|
[1139] | 75 | float numberOfTextInputEvents = textInputEvents.size();
|
---|
[1152] | 76 | float numberOfNonTextInputEvents = nrOfEventTasksNotMatchedFilter(nonTextInputEvents);
|
---|
[1139] | 77 | return numberOfTextInputEvents / (numberOfTextInputEvents + numberOfNonTextInputEvents);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[1152] | 80 | private int nrOfEventTasksNotMatchedFilter(List<ITask> nonTextInputEvents) {
|
---|
[1139] | 81 | return Iterables.size(Iterables.filter(nonTextInputEvents,
|
---|
[1152] | 82 | new Predicate<ITask>() {
|
---|
[1139] | 83 |
|
---|
| 84 | @Override
|
---|
[1152] | 85 | public boolean apply(ITask task) {
|
---|
| 86 | return task instanceof IEventTask;
|
---|
[1139] | 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 | }
|
---|