source: trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usability/CMDusabilityAutoTagger.java

Last change on this file was 2260, checked in by pharms, 5 years ago

Update to java 11

  • Property svn:mime-type set to text/plain
File size: 7.4 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.commands.usability;
16
17import java.util.ArrayList;
18import java.util.HashSet;
19import java.util.LinkedList;
20import java.util.List;
21import java.util.Set;
22
23import de.ugoe.cs.autoquest.CommandHelpers;
24import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
27import de.ugoe.cs.autoquest.usability.UsabilityEvaluationResult;
28import de.ugoe.cs.autoquest.usability.UsabilitySmell;
29import de.ugoe.cs.autoquest.usability.UsabilitySmell.ManualLabel;
30import de.ugoe.cs.util.console.Command;
31import de.ugoe.cs.util.console.GlobalDataContainer;
32
33/**
34 * <p>
35 * TODO comment
36 * </p>
37 *
38 * @author Patrick Harms
39 * @version 1.0
40 */
41public class CMDusabilityAutoTagger implements Command {
42
43    /*
44     * (non-Javadoc)
45     *
46     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
47     */
48    @Override
49    public void run(List<Object> parameters) {
50        List<String> usabilityResultNames = new ArrayList<>(parameters.size());
51        try {
52            for (Object parameter : parameters) {
53                usabilityResultNames.add((String) parameter);
54            }
55        }
56        catch (Exception e) {
57            throw new IllegalArgumentException();
58        }
59
60        List<UsabilityEvaluationResult> usabilityResults = new ArrayList<>(usabilityResultNames.size());
61       
62        for (String usabilityResultName : usabilityResultNames) {
63            Object dataObject = GlobalDataContainer.getInstance().getData(usabilityResultName);
64            if (dataObject == null) {
65                CommandHelpers.objectNotFoundMessage(usabilityResultName);
66                return;
67            }
68            if (!(dataObject instanceof UsabilityEvaluationResult)) {
69                CommandHelpers.objectNotType(usabilityResultName, "UsabilityEvaluationResult");
70                return;
71            }
72           
73            usabilityResults.add((UsabilityEvaluationResult) dataObject);
74        }
75       
76        for (UsabilityEvaluationResult result : usabilityResults) {
77            for (UsabilitySmell smell : result.getAllSmells()) {
78                if (smell.getSmellingTask() != null) {
79                    smell.setManualLabel(ManualLabel.TRUE_POSITIVE);
80                   
81                    final Set<String> usedObjectNames = new HashSet<>();
82                   
83                    smell.getSmellingTask().accept(new DefaultTaskTraversingVisitor() {
84                       @Override
85                        public void visit(IEventTask eventTask) {
86                           usedObjectNames.add(((IEventTaskInstance) eventTask.getInstances().iterator().next()).getEvent().getTarget().toString());
87                        }
88                    });
89                   
90                    for (String tag : new LinkedList<String>(smell.getTags())) {
91                        smell.removeTag(tag);
92                    }
93                   
94                    if (usedObjectNames.remove("Cup")) {
95                        if (!smell.getTags().contains("Cup")) {
96                            smell.addTag("Cup");
97                        }
98                    }
99                    if (usedObjectNames.remove("StrongCoffee")) {
100                        if (!smell.getTags().contains("Strong Coffee")) {
101                            smell.addTag("Strong Coffee");
102                        }
103                        if (!smell.getTags().contains("Right Button")) {
104                            smell.addTag("Right Button");
105                        }
106                    }
107                    if (usedObjectNames.remove("LightCoffee")) {
108                        if (!smell.getTags().contains("Light Coffee")) {
109                            smell.addTag("Light Coffee");
110                        }
111                        if (!smell.getTags().contains("Right Button")) {
112                            smell.addTag("Right Button");
113                        }
114                    }
115                    if (usedObjectNames.remove("TwoLightCoffees")) {
116                        if (!smell.getTags().contains("Two Light Coffees")) {
117                            smell.addTag("Two Light Coffees");
118                        }
119                        if (!smell.getTags().contains("Right Button")) {
120                            smell.addTag("Right Button");
121                        }
122                    }
123                    if (usedObjectNames.remove("ButtonCopy")) {
124                        if (!smell.getTags().contains("Copy Button")) {
125                            smell.addTag("Copy Button");
126                        }
127                        if (!smell.getTags().contains("Right Button")) {
128                            smell.addTag("Right Button");
129                        }
130                    }
131                    if (usedObjectNames.remove("PrinterTop")) {
132                        if (!smell.getTags().contains("Printer Top")) {
133                            smell.addTag("Printer Top");
134                        }
135                    }
136                    if (usedObjectNames.remove("Paper")) {
137                        if (!smell.getTags().contains("Paper")) {
138                            smell.addTag("Paper");
139                        }
140                    }
141                    if (usedObjectNames.remove("Paper(Clone)1")) {
142                        if (!smell.getTags().contains("Paper")) {
143                            smell.addTag("Paper");
144                        }
145                    }
146                    if (usedObjectNames.remove("Paper(Clone)2")) {
147                        if (!smell.getTags().contains("Paper")) {
148                            smell.addTag("Paper");
149                        }
150                    }
151                    if (usedObjectNames.remove("Buzzer")) {
152                        if (!smell.getTags().contains("Reset")) {
153                            smell.addTag("Reset");
154                        }
155                    }
156                    if (usedObjectNames.remove("Camera (eye)")) {
157                        // ignore
158                    }
159                    if (usedObjectNames.remove("CenterEyeAnchor")) {
160                        // ignore
161                    }
162                   
163                    if (usedObjectNames.size() > 0) {
164                        if (!smell.getTags().contains("Wrong Button")) {
165                            smell.addTag("Wrong Button");
166                        }
167                    }
168                }
169            }
170        }
171    }
172
173    /*
174     * (non-Javadoc)
175     *
176     * @see de.ugoe.cs.util.console.Command#help()
177     */
178    @Override
179    public String help() {
180        return "eventStatistics [<sequencesName>]*";
181    }
182
183}
Note: See TracBrowser for help on using the repository browser.