source: trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeifc/TaskTreeUtils.java @ 2161

Last change on this file since 2161 was 2161, checked in by pharms, 7 years ago
  • changes for first VR oriented usability evaluation
File size: 4.6 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.tasktrees.treeifc;
16
17import java.util.Collection;
18import java.util.HashMap;
19import java.util.HashSet;
20import java.util.LinkedList;
21import java.util.List;
22import java.util.Map;
23import java.util.Set;
24
25/**
26 * <p>
27 * TODO comment
28 * </p>
29 *
30 * @author Patrick Harms
31 */
32public class TaskTreeUtils {
33   
34    /**
35     *
36     */
37    public static boolean isChild(ITask potentialChild, ITask potentialParent) {
38        if (potentialParent instanceof IStructuringTemporalRelationship) {
39            for (ITask child : ((IStructuringTemporalRelationship) potentialParent).getChildren()) {
40                if (child.equals(potentialChild) || isChild(potentialChild, child)) {
41                    return true;
42                }
43            }
44        }
45        else if (potentialParent instanceof IMarkingTemporalRelationship) {
46            ITask child = ((IMarkingTemporalRelationship) potentialParent).getMarkedTask();
47            if (child.equals(potentialChild) || isChild(potentialChild, child)) {
48                return true;
49            }
50        }
51       
52        return false;
53    }
54
55    /**
56     *
57     */
58    public static Set<ISequence> getMostProminentTasks(ITaskModel model) {
59        return getMostProminentTasks(model, model.getTasks());
60    }
61
62    /**
63     *
64     */
65    public static Set<ISequence> getMostProminentTasks(ITaskModel        model,
66                                                       Collection<ITask> tasks)
67    {
68        List<ISequence> sequences = new LinkedList<>();
69       
70        for (ITask task : tasks) {
71            if (task instanceof ISequence) {
72                sequences.add((ISequence) task);
73            }
74        }
75       
76        return getMostProminentSequences(model, sequences);
77    }
78
79    /**
80     *
81     */
82    public static Set<ISequence> getMostProminentSequences(ITaskModel            model,
83                                                           Collection<ISequence> tasks)
84    {
85        Map<Integer, List<ISequence>> sortedSequences = new HashMap<>();
86       
87        int maxCoverage = 0;
88       
89        for (ITask task : tasks) {
90            int coveredEvents =
91                    model.getTaskInfo((ISequence) task).getMeasureValue(TaskMetric.EVENT_COVERAGE);
92
93            List<ISequence> sequencesWithSameCoverage = sortedSequences.get(coveredEvents);
94
95            if (sequencesWithSameCoverage == null) {
96                sequencesWithSameCoverage = new LinkedList<>();
97                sortedSequences.put(coveredEvents, sequencesWithSameCoverage);
98            }
99
100            sequencesWithSameCoverage.add((ISequence) task);
101
102            maxCoverage = Math.max(maxCoverage, coveredEvents);
103        }
104       
105        Set<ISequence> result = new HashSet<>();
106       
107        for (int i = maxCoverage; i > 0; i--) {
108            List<ISequence> sequencesWithSameCoverage = sortedSequences.get(i);
109           
110            if (sequencesWithSameCoverage != null) {
111                result.addAll(sequencesWithSameCoverage);
112               
113                if (result.size() * 5 >= tasks.size()) {
114                    break;
115                }
116            }
117        }
118       
119        return result;
120    }
121
122
123    /**
124     *
125     */
126    public static int getNoOfEventsCoveredBySequences(Set<ISequence> sequences) {
127        return getEventsCoveredBySequences(sequences).size();
128    }
129
130    /**
131     *
132     */
133    public static Set<IEventTaskInstance> getEventsCoveredBySequences(Set<ISequence> sequences) {
134        final Set<IEventTaskInstance> events = new HashSet<>();
135       
136        for (ISequence task : sequences) {
137            for (ITaskInstance instance : task.getInstances()) {
138                instance.accept(new DefaultTaskInstanceTraversingVisitor() {
139                    @Override
140                    public void visit(IEventTaskInstance eventTaskInstance) {
141                        events.add(eventTaskInstance);
142                    }
143                });
144            }
145        }
146       
147        return events;
148    }
149
150    /**
151     *
152     */
153    private TaskTreeUtils() { /* prevent instantiation */ }
154}
Note: See TracBrowser for help on using the repository browser.