[1326] | 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.plugin.usability2.commands;
|
---|
| 16 |
|
---|
| 17 | import java.util.Collection;
|
---|
| 18 | import java.util.List;
|
---|
| 19 |
|
---|
| 20 | import com.google.common.base.Optional;
|
---|
| 21 |
|
---|
| 22 | import de.ugoe.cs.autoquest.CommandHelpers;
|
---|
| 23 | import de.ugoe.cs.autoquest.SequenceInstanceOf;
|
---|
| 24 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 25 | import de.ugoe.cs.autoquest.usability.UsabilityEvaluator;
|
---|
| 26 | import de.ugoe.cs.autoquest.usability.rules.PatternRuleset;
|
---|
| 27 | import de.ugoe.cs.autoquest.usability.rules.UsabilityMetricsRuleset;
|
---|
| 28 | import de.ugoe.cs.autoquest.usability.rules.UsabilityResult;
|
---|
| 29 | import de.ugoe.cs.autoquest.plugin.usability2.rules.CombinedRuleset;
|
---|
| 30 | import de.ugoe.cs.autoquest.plugin.usability2.rules.metrics.RedundantScrollingMetric;
|
---|
| 31 | import de.ugoe.cs.autoquest.plugin.usability2.rules.metrics.SameTargetEditingMetric;
|
---|
| 32 | import de.ugoe.cs.autoquest.plugin.usability2.rules.patterns.PatternProblem;
|
---|
| 33 | import de.ugoe.cs.autoquest.plugin.usability2.rules.patterns.SessionPatternProblem;
|
---|
| 34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 35 | import de.ugoe.cs.util.console.Command;
|
---|
| 36 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * <p>
|
---|
| 40 | * Command to perform a automatic usability evaluation for a given task model.
|
---|
| 41 | * </p>
|
---|
| 42 | *
|
---|
| 43 | * @author Alexander Deicke
|
---|
| 44 | */
|
---|
| 45 | public class CMDperformUsabilityEvaluation implements Command {
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * <p>
|
---|
| 49 | * index for name of task model under which it could be retrieved from
|
---|
| 50 | * {@link GlobalDataContainer}
|
---|
| 51 | * </p>
|
---|
| 52 | */
|
---|
| 53 | private final int taskModelParamaterIndex = 0;
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * <p>
|
---|
| 57 | * index for name under which evaluation result should be stored in {@link GlobalDataContainer}
|
---|
| 58 | * </p>
|
---|
| 59 | */
|
---|
| 60 | private final int evaluationResultParameterIndex = 1;
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * <p>
|
---|
| 64 | * default name for evaluation result, which is used to store it in {@link GlobalDataContainer}
|
---|
| 65 | * </p>
|
---|
| 66 | */
|
---|
| 67 | private final String defaultEvaluationResultParameterName = "usabilityEvaluationResult";
|
---|
| 68 |
|
---|
| 69 | /*
|
---|
| 70 | * (non-Javadoc)
|
---|
| 71 | *
|
---|
| 72 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 73 | */
|
---|
| 74 | @Override
|
---|
| 75 | public void run(List<Object> parameters) {
|
---|
| 76 | String nameOfTaskModel = getTaskModelParameter(parameters);
|
---|
| 77 | Optional<ITaskModel> taskModel = getTaskModelFromDataContainer(nameOfTaskModel);
|
---|
| 78 |
|
---|
| 79 | Optional<Collection<List<Event>>> sequences = getSequencesFromDataContainer("sequences");
|
---|
| 80 |
|
---|
| 81 | if (taskModel.isPresent()) {
|
---|
| 82 | // UsabilityRuleset ruleset = new PatternRuleset(taskModel.get());
|
---|
| 83 | CombinedRuleset ruleset =
|
---|
| 84 | new CombinedRuleset(new PatternRuleset(taskModel.get()),
|
---|
| 85 | new UsabilityMetricsRuleset(taskModel.get()));
|
---|
| 86 | ruleset.add(new RedundantScrollingMetric(taskModel.get()));
|
---|
| 87 | ruleset.add(new SameTargetEditingMetric(taskModel.get()));
|
---|
| 88 | ruleset.add(new PatternProblem(taskModel.get()));
|
---|
| 89 | ruleset.add(new SessionPatternProblem(taskModel.get(), sequences.get()));
|
---|
| 90 | UsabilityResult result = UsabilityEvaluator.evaluate(taskModel.get()).using(ruleset);
|
---|
| 91 | String evaluationResultParameterName = getEvaluationResultParameter(parameters);
|
---|
| 92 | storeUsabilityResultInDataContainer(evaluationResultParameterName, result);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | /**
|
---|
| 97 | * <p>
|
---|
| 98 | * Gets name of task model from list of parameters.
|
---|
| 99 | * </p>
|
---|
| 100 | *
|
---|
| 101 | * @param parameters
|
---|
| 102 | * parameters for the command
|
---|
| 103 | * @return name of task model
|
---|
| 104 | */
|
---|
| 105 | private String getTaskModelParameter(List<Object> parameters) {
|
---|
| 106 | try {
|
---|
| 107 | return (String) parameters.get(taskModelParamaterIndex);
|
---|
| 108 | }
|
---|
| 109 | catch (Exception e) {
|
---|
| 110 | throw new IllegalArgumentException("must provide a task model name");
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * <p>
|
---|
| 116 | * Gets name under which evaluation result should be stored in {@link GlobalDataContainer} from
|
---|
| 117 | * list of parameters. If not present, the default value {@code usabilityEvaluationResult} is
|
---|
| 118 | * used!
|
---|
| 119 | * </p>
|
---|
| 120 | *
|
---|
| 121 | * @param parameters
|
---|
| 122 | * parameters for the command
|
---|
| 123 | * @return name under which evaluation result should be stored
|
---|
| 124 | */
|
---|
| 125 | private String getEvaluationResultParameter(List<Object> parameters) {
|
---|
| 126 | if (parameters.size() == 2) {
|
---|
| 127 | return (String) parameters.get(evaluationResultParameterIndex);
|
---|
| 128 | }
|
---|
| 129 | return defaultEvaluationResultParameterName;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /**
|
---|
| 133 | * <p>
|
---|
| 134 | * Retrieves task model from {@link GlobalDataContainer}.
|
---|
| 135 | * </p>
|
---|
| 136 | *
|
---|
| 137 | * @param nameOfTaskModel
|
---|
| 138 | * name of task model, under which it is stored in {@link GlobalDataContainer}
|
---|
| 139 | * @return if present, task model
|
---|
| 140 | */
|
---|
| 141 | private Optional<ITaskModel> getTaskModelFromDataContainer(String nameOfTaskModel) {
|
---|
| 142 | Object dataObject = GlobalDataContainer.getInstance().getData(nameOfTaskModel);
|
---|
| 143 | if (dataObject != null) {
|
---|
| 144 | if (dataObject instanceof ITaskModel) {
|
---|
| 145 | ITaskModel taskModel = (ITaskModel) dataObject;
|
---|
| 146 | return Optional.of(taskModel);
|
---|
| 147 | }
|
---|
| 148 | else {
|
---|
| 149 | CommandHelpers.objectNotType(nameOfTaskModel, "ITaskModel");
|
---|
| 150 | return Optional.absent();
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | CommandHelpers.objectNotFoundMessage(nameOfTaskModel);
|
---|
| 154 | return Optional.absent();
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | /**
|
---|
| 158 | * <p>
|
---|
| 159 | * Retrieves task model from {@link GlobalDataContainer}.
|
---|
| 160 | * </p>
|
---|
| 161 | *
|
---|
| 162 | * @param nameOfTaskModel
|
---|
| 163 | * name of task model, under which it is stored in {@link GlobalDataContainer}
|
---|
| 164 | * @return if present, task model
|
---|
| 165 | */
|
---|
| 166 | private Optional<Collection<List<Event>>> getSequencesFromDataContainer(String nameOfTaskModel) {
|
---|
| 167 | Object dataObject = GlobalDataContainer.getInstance().getData(nameOfTaskModel);
|
---|
| 168 | if (dataObject != null) {
|
---|
| 169 | if (SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
|
---|
| 170 | @SuppressWarnings("unchecked")
|
---|
| 171 | Collection<List<Event>> sequences = (Collection<List<Event>>) dataObject;
|
---|
| 172 | return Optional.of(sequences);
|
---|
| 173 | }
|
---|
| 174 | else {
|
---|
| 175 | CommandHelpers.objectNotType(nameOfTaskModel, "Sequences");
|
---|
| 176 | return Optional.absent();
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | CommandHelpers.objectNotFoundMessage(nameOfTaskModel);
|
---|
| 180 | return Optional.absent();
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | /**
|
---|
| 185 | * <p>
|
---|
| 186 | * Stores usability evaluation in {@link GlobalDataContainer}.
|
---|
| 187 | * </p>
|
---|
| 188 | *
|
---|
| 189 | * @param evaluationResultParameterName
|
---|
| 190 | * name under which usability result should be stored in {@link GlobalDataContainer}
|
---|
| 191 | *
|
---|
| 192 | */
|
---|
| 193 | private void storeUsabilityResultInDataContainer(String evaluationResultParameterName,
|
---|
| 194 | UsabilityResult result)
|
---|
| 195 | {
|
---|
| 196 | if (GlobalDataContainer.getInstance().addData(evaluationResultParameterName, result)) {
|
---|
| 197 | CommandHelpers.dataOverwritten(evaluationResultParameterName);
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | /*
|
---|
| 202 | * (non-Javadoc)
|
---|
| 203 | *
|
---|
| 204 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 205 | */
|
---|
| 206 | @Override
|
---|
| 207 | public String help() {
|
---|
| 208 | return "performUsabilityEvaluation <taskModel> {evaluationResult}";
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | }
|
---|