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