[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 |
|
---|
[1217] | 17 | import static de.ugoe.cs.autoquest.usability.taskmodel.filter.types.EventTypeFilter.TEXT_INPUT;
|
---|
[1139] | 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;
|
---|
[1292] | 29 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescription;
|
---|
[1217] | 30 | import de.ugoe.cs.autoquest.usability.result.UsabilityProblemDescriptionResolver;
|
---|
[1139] | 31 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetric;
|
---|
| 32 | import de.ugoe.cs.autoquest.usability.rules.UsabilityRule;
|
---|
[1217] | 33 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.FilterResult;
|
---|
[1292] | 34 | import de.ugoe.cs.autoquest.usability.taskmodel.filter.TaskModelFilter;
|
---|
[1139] | 35 |
|
---|
| 36 | /**
|
---|
| 37 | * <p>
|
---|
[1217] | 38 | * Metric, which measures the ratio between the text input and the non text input events.
|
---|
[1139] | 39 | * </p>
|
---|
| 40 | *
|
---|
| 41 | * @author Alexander Deicke
|
---|
| 42 | */
|
---|
| 43 | public class TextInputRatioMetric extends UsabilityRule implements UsabilityMetric {
|
---|
| 44 |
|
---|
| 45 | /**
|
---|
| 46 | * <p>
|
---|
[1217] | 47 | * Constructor. Creates a new {@code TextInputRatioMetric} for a given task model.
|
---|
[1139] | 48 | * </p>
|
---|
[1217] | 49 | *
|
---|
[1139] | 50 | * @param taskTree
|
---|
| 51 | */
|
---|
[1152] | 52 | public TextInputRatioMetric(ITaskModel taskModel) {
|
---|
| 53 | super(taskModel);
|
---|
[1139] | 54 | this.name = "TextInputRatio";
|
---|
[1217] | 55 | this.defect =
|
---|
| 56 | new UsabilityProblemDescriptionResolver().descriptionFor(this.getClass()
|
---|
| 57 | .getSimpleName());
|
---|
[1139] | 58 | }
|
---|
| 59 |
|
---|
[1217] | 60 | /*
|
---|
| 61 | * (non-Javadoc)
|
---|
| 62 | *
|
---|
[1139] | 63 | * @see de.ugoe.cs.autoquest.usability.rules.UsabilityRule#check()
|
---|
| 64 | */
|
---|
| 65 | @Override
|
---|
[1217] | 66 | public Optional<UsabilityProblemDescription> calculate() {
|
---|
[1139] | 67 | FilterResult textInputEvents = extractNodesFromTaskTree();
|
---|
[1217] | 68 | float evaluationMetric =
|
---|
| 69 | calculateEvaluationMetric(textInputEvents.tasksMatchedFilter(),
|
---|
| 70 | textInputEvents.tasksNotMatchedFilter());
|
---|
[1139] | 71 | return this.defect.isPresent(evaluationMetric);
|
---|
| 72 | }
|
---|
[1217] | 73 |
|
---|
| 74 | /**
|
---|
| 75 | *
|
---|
| 76 | * <p>
|
---|
| 77 | * Filters all text input events from task model.
|
---|
| 78 | * </p>
|
---|
| 79 | *
|
---|
| 80 | * @return {@code FilterResult}
|
---|
| 81 | */
|
---|
[1139] | 82 | private FilterResult extractNodesFromTaskTree() {
|
---|
[1292] | 83 | return new TaskModelFilter().filter(taskModel, TEXT_INPUT);
|
---|
[1139] | 84 | }
|
---|
[1217] | 85 |
|
---|
| 86 | /**
|
---|
| 87 | *
|
---|
| 88 | * <p>
|
---|
| 89 | * Calculates the metric.
|
---|
| 90 | * </p>
|
---|
| 91 | *
|
---|
| 92 | * @param textInputEvents
|
---|
| 93 | * all text input events
|
---|
| 94 | * @param nonTextInputEvents
|
---|
| 95 | * all non text input events
|
---|
| 96 | * @return ratio between text input and non text input events
|
---|
| 97 | */
|
---|
| 98 | private float calculateEvaluationMetric(List<ITask> textInputEvents,
|
---|
| 99 | List<ITask> nonTextInputEvents)
|
---|
| 100 | {
|
---|
[1139] | 101 | float numberOfTextInputEvents = textInputEvents.size();
|
---|
[1152] | 102 | float numberOfNonTextInputEvents = nrOfEventTasksNotMatchedFilter(nonTextInputEvents);
|
---|
[1139] | 103 | return numberOfTextInputEvents / (numberOfTextInputEvents + numberOfNonTextInputEvents);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[1217] | 106 | /**
|
---|
| 107 | *
|
---|
| 108 | * <p>
|
---|
| 109 | * Filters all {@link IEventTask}s from non text input event.
|
---|
| 110 | * </p>
|
---|
| 111 | *
|
---|
| 112 | * @param nonTextInputEvents
|
---|
| 113 | * all non text input events
|
---|
| 114 | * @return number of {@link IEventTask}s
|
---|
| 115 | */
|
---|
[1152] | 116 | private int nrOfEventTasksNotMatchedFilter(List<ITask> nonTextInputEvents) {
|
---|
[1217] | 117 | return Iterables.size(Iterables.filter(nonTextInputEvents, new Predicate<ITask>() {
|
---|
[1139] | 118 |
|
---|
[1217] | 119 | @Override
|
---|
| 120 | public boolean apply(ITask task) {
|
---|
| 121 | return task instanceof IEventTask;
|
---|
| 122 | }
|
---|
| 123 | }));
|
---|
[1139] | 124 | }
|
---|
| 125 |
|
---|
[1217] | 126 | /*
|
---|
| 127 | * (non-Javadoc)
|
---|
| 128 | *
|
---|
| 129 | * @see
|
---|
| 130 | * de.ugoe.cs.autoquest.usability.rules.UsabilityRule#callEvaluationMetho(de.ugoe.cs.autoquest
|
---|
| 131 | * .usability.EvaluationMethodCaller)
|
---|
[1150] | 132 | */
|
---|
| 133 | @Override
|
---|
[1217] | 134 | public Optional<UsabilityProblemDescription> callEvaluationMethod(EvaluationMethodCaller evaluationMethodCaller)
|
---|
[1150] | 135 | {
|
---|
| 136 | return evaluationMethodCaller.check(this);
|
---|
| 137 | }
|
---|
[1139] | 138 | }
|
---|