source: trunk/autoquest-plugin-usability2/src/main/java/de/ugoe/cs/autoquest/plugin/usability2/commands/CMDperformTaskTimeAnalysis.java @ 1326

Last change on this file since 1326 was 1326, checked in by khartmann, 10 years ago

Moved alexanders code into a new plugin project.
First commit of my experimental code (needs a lot of cleanup).

File size: 5.9 KB
Line 
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
15package de.ugoe.cs.autoquest.plugin.usability2.commands;
16
17import java.util.List;
18
19import com.google.common.base.Optional;
20
21import de.ugoe.cs.autoquest.CommandHelpers;
22import de.ugoe.cs.autoquest.usability.UsabilityEvaluator;
23import de.ugoe.cs.autoquest.usability.rules.UsabilityResult;
24import de.ugoe.cs.autoquest.plugin.usability2.rules.CombinedRuleset;
25import de.ugoe.cs.autoquest.plugin.usability2.rules.metrics.OnTaskTimeMetric;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
27import de.ugoe.cs.util.console.Command;
28import de.ugoe.cs.util.console.GlobalDataContainer;
29
30/**
31 * <p>
32 * Command to perform a automatic evaluation for on task times for a given task model.
33 * </p>
34 *
35 * @author Alexander Deicke
36 */
37public class CMDperformTaskTimeAnalysis implements Command {
38
39    /**
40     * <p>
41     * index for name of task model under which it could be retrieved from
42     * {@link GlobalDataContainer}
43     * </p>
44     */
45    private final int taskModelParamaterIndex = 0;
46
47    /**
48     * <p>
49     * index for name under which evaluation result should be stored in {@link GlobalDataContainer}
50     * </p>
51     */
52    private final int evaluationResultParameterIndex = 1;
53
54    /**
55     * <p>
56     * default name for evaluation result, which is used to store it in {@link GlobalDataContainer}
57     * </p>
58     */
59    private final String defaultEvaluationResultParameterName = "usabilityEvaluationResult";
60
61    /*
62     * (non-Javadoc)
63     *
64     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
65     */
66    @Override
67    public void run(List<Object> parameters) {
68        String nameOfTaskModel = getTaskModelParameter(parameters);
69        Optional<ITaskModel> taskModel = getTaskModelFromDataContainer(nameOfTaskModel);
70       
71        if (taskModel.isPresent()) {
72            // UsabilityRuleset ruleset = new PatternRuleset(taskModel.get());
73            CombinedRuleset ruleset = new CombinedRuleset();
74            ruleset.add(new OnTaskTimeMetric(taskModel.get()));
75            UsabilityResult result = UsabilityEvaluator.evaluate(taskModel.get()).using(ruleset);
76            String evaluationResultParameterName = getEvaluationResultParameter(parameters);
77            storeUsabilityResultInDataContainer(evaluationResultParameterName, result);
78        }
79    }
80
81    /**
82     * <p>
83     * Gets name of task model from list of parameters.
84     * </p>
85     *
86     * @param parameters
87     *            parameters for the command
88     * @return name of task model
89     */
90    private String getTaskModelParameter(List<Object> parameters) {
91        try {
92            return (String) parameters.get(taskModelParamaterIndex);
93        }
94        catch (Exception e) {
95            throw new IllegalArgumentException("must provide a task model name");
96        }
97    }
98
99    /**
100     * <p>
101     * Gets name under which evaluation result should be stored in {@link GlobalDataContainer} from
102     * list of parameters. If not present, the default value {@code usabilityEvaluationResult} is
103     * used!
104     * </p>
105     *
106     * @param parameters
107     *            parameters for the command
108     * @return name under which evaluation result should be stored
109     */
110    private String getEvaluationResultParameter(List<Object> parameters) {
111        if (parameters.size() == 2) {
112            return (String) parameters.get(evaluationResultParameterIndex);
113        }
114        return defaultEvaluationResultParameterName;
115    }
116
117    /**
118     * <p>
119     * Retrieves task model from {@link GlobalDataContainer}.
120     * </p>
121     *
122     * @param nameOfTaskModel
123     *            name of task model, under which it is stored in {@link GlobalDataContainer}
124     * @return if present, task model
125     */
126    private Optional<ITaskModel> getTaskModelFromDataContainer(String nameOfTaskModel) {
127        Object dataObject = GlobalDataContainer.getInstance().getData(nameOfTaskModel);
128        if (dataObject != null) {
129            if (dataObject instanceof ITaskModel) {
130                ITaskModel taskModel = (ITaskModel) dataObject;
131                return Optional.of(taskModel);
132            }
133            else {
134                CommandHelpers.objectNotType(nameOfTaskModel, "ITaskModel");
135                return Optional.absent();
136            }
137        }
138        CommandHelpers.objectNotFoundMessage(nameOfTaskModel);
139        return Optional.absent();
140    }
141
142    /**
143     * <p>
144     * Stores usability evaluation in {@link GlobalDataContainer}.
145     * </p>
146     *
147     * @param evaluationResultParameterName
148     *            name under which usability result should be stored in {@link GlobalDataContainer}
149     *
150     */
151    private void storeUsabilityResultInDataContainer(String evaluationResultParameterName,
152                                                     UsabilityResult result)
153    {
154        if (GlobalDataContainer.getInstance().addData(evaluationResultParameterName, result)) {
155            CommandHelpers.dataOverwritten(evaluationResultParameterName);
156        }
157    }
158
159    /*
160     * (non-Javadoc)
161     *
162     * @see de.ugoe.cs.util.console.Command#help()
163     */
164    @Override
165    public String help() {
166        return "performTaskTimeAnalysis <taskModel> {evaluationResult}";
167    }
168
169}
Note: See TracBrowser for help on using the repository browser.