Ignore:
Timestamp:
10/20/15 10:11:04 (9 years ago)
Author:
pharms
Message:
  • finalized smell detection for phd thesis
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CheckBoxMultipleSelectionRule.java

    r1918 r2042  
    1515package de.ugoe.cs.autoquest.usability; 
    1616 
     17import java.util.ArrayList; 
    1718import java.util.Collection; 
    1819import java.util.HashMap; 
    1920import java.util.HashSet; 
     21import java.util.LinkedList; 
    2022import java.util.List; 
    2123import java.util.Map; 
    2224import java.util.Set; 
    2325 
     26import de.ugoe.cs.autoquest.eventcore.IEventTarget; 
     27import de.ugoe.cs.autoquest.eventcore.gui.MouseClick; 
     28import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection; 
    2429import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox; 
    2530import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 
    26 import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; 
     31import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView; 
     32import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor; 
    2733import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 
    2834import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 
    29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
    30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 
    3135import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    3236import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    3337import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
    34 import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric; 
     38import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
    3539 
    3640/** 
     
    6872                                   UsabilityEvaluationResult results) 
    6973    { 
     74        System.out.println("\n\n########################################\n"); 
     75        final List<List<IEventTaskInstance>> actionInstancesInSameView = new LinkedList<>(); 
     76         
     77        for (IUserSession session : taskModel.getUserSessions()) { 
     78            for (ITaskInstance instance : session) { 
     79                final LinkedList<IEventTaskInstance> currentList = new LinkedList<>(); 
     80                 
     81                instance.accept(new DefaultTaskInstanceTraversingVisitor() { 
     82                    @Override 
     83                    public void visit(IEventTaskInstance eventTaskInstance) { 
     84                        if (eventTaskInstance.getEvent().getTarget() instanceof IGUIElement) { 
     85                            IEventTarget target = eventTaskInstance.getEvent().getTarget(); 
     86                            IGUIView currentView = ((IGUIElement) target).getView(); 
     87                             
     88                            IGUIView previousView = null; 
     89                            if (currentList.size() > 0) { 
     90                                target = currentList.getLast().getEvent().getTarget(); 
     91                                previousView = ((IGUIElement) target).getView(); 
     92                            } 
     93                             
     94                            if ((previousView == currentView) || 
     95                                ((previousView != null) && (previousView.equals(currentView)))) 
     96                            { 
     97                                currentList.add(eventTaskInstance); 
     98                            } 
     99                            else { 
     100                                if (currentList.size() > 0) { 
     101                                    actionInstancesInSameView.add(new ArrayList<>(currentList)); 
     102                                } 
     103                                currentList.clear(); 
     104                                currentList.add(eventTaskInstance); 
     105                            } 
     106                        } 
     107                    } 
     108                }); 
     109                 
     110                if (currentList.size() > 0) { 
     111                    actionInstancesInSameView.add(new ArrayList<>(currentList)); 
     112                } 
     113            } 
     114        } 
     115 
     116         
    70117        Map<IGUIElement, List<IGUIElement>> checkBoxGroups = statistics.getCheckBoxGroups(); 
    71118         
    72         CHECK_NEXT_GROUP: 
    73         for (List<IGUIElement> group : checkBoxGroups.values()) { 
    74             Set<ITask> tasksUsingGroup = new HashSet<>(); 
    75              
    76             for (IGUIElement checkBox : group) { 
    77                 Set<ITask> tasksUsingCheckBox = getTasksUsingCheckBox(checkBox, taskModel); 
     119        for (Map.Entry<IGUIElement, List<IGUIElement>> group : checkBoxGroups.entrySet()) { 
     120            IGUIView currentView = group.getKey().getView(); 
     121            int noOfEvents = 0; 
     122            int noOfGroupUsages = 0; 
     123            int noOfSingleCheckBoxUsages = 0; 
     124             
     125            for (List<IEventTaskInstance> actionInstanceList : actionInstancesInSameView) { 
     126                IEventTarget target = actionInstanceList.get(0).getEvent().getTarget(); 
     127                IGUIView viewOfList = ((IGUIElement) target).getView(); 
    78128                 
    79                 for (ITask taskUsingCheckBox : tasksUsingCheckBox) { 
    80                     if (tasksUsingGroup.contains(taskUsingCheckBox)) { 
    81                         continue CHECK_NEXT_GROUP; 
    82                     } 
    83                     else { 
    84                         tasksUsingGroup.add(taskUsingCheckBox); 
     129                if ((viewOfList == currentView) || 
     130                    ((viewOfList != null) && (viewOfList.equals(currentView)))) 
     131                { 
     132                    noOfGroupUsages++; 
     133                    boolean[] checkBoxUsages = new boolean[group.getValue().size()]; 
     134                     
     135                    for (IEventTaskInstance actionInstance : actionInstanceList) { 
     136                        int index = 0; 
     137                        for (IGUIElement checkBox : group.getValue()) { 
     138                            if ((("JFC".equals(actionInstance.getEvent().getTarget().getPlatform())) && 
     139                                 (actionInstance.getEvent().getType() instanceof MouseClick) && 
     140                                 (actionInstance.getEvent().getTarget().equals(checkBox))) || 
     141                                ((actionInstance.getEvent().getType() instanceof ValueSelection<?>) && 
     142                                 (actionInstance.getEvent().getTarget().equals(checkBox)))) 
     143                            { 
     144                                checkBoxUsages[index] = !checkBoxUsages[index]; 
     145                                noOfEvents++; 
     146                            } 
     147                            index++; 
     148                        } 
     149                    } 
     150                     
     151                    int noOfCheckedBoxes = 0; 
     152                     
     153                    for (int i = 0; i < checkBoxUsages.length; i++) { 
     154                        if (checkBoxUsages[i]) { 
     155                            noOfCheckedBoxes++; 
     156                        } 
     157                    } 
     158                     
     159                    if (noOfCheckedBoxes == 1) { 
     160                        noOfSingleCheckBoxUsages++; 
    85161                    } 
    86162                } 
    87163            } 
    88164             
    89             if (tasksUsingGroup.size() > 0) { 
    90                 int eventCoverage = 0; 
    91                 int allRecordedEvents = 0; 
    92                  
    93                 for (ITask task : tasksUsingGroup) { 
    94                     if (task instanceof IEventTask) { 
    95                         eventCoverage += 
    96                             taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 
    97                     } 
    98                 } 
    99                  
    100                 for (ITask task : taskModel.getTasks()) { 
    101                     if (task instanceof IEventTask) { 
    102                         allRecordedEvents += 
    103                             taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); 
    104                     } 
    105                 } 
    106                  
    107                  
    108                 UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity 
    109                     ((int) (1000 * eventCoverage / allRecordedEvents), eventCoverage, -1); 
    110                      
    111                 if (intensity != null) { 
    112                     Map<String, Object> parameters = new HashMap<String, Object>(); 
    113                     parameters.put("radioButtons", group); 
    114  
    115                     results.addSmell 
    116                         (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, 
    117                          parameters); 
    118                 } 
    119             } 
    120         } 
    121     } 
    122  
    123     /** 
    124      *  
    125      */ 
    126     private Set<ITask> getTasksUsingCheckBox(final IGUIElement checkBox, ITaskModel taskModel) { 
    127         final Set<ITask> tasksUsingCheckBox = new HashSet<ITask>(); 
    128          
    129         for (ITask candidate : taskModel.getTasks()) { 
    130             candidate.accept(new DefaultTaskTraversingVisitor() { 
    131                 @Override 
    132                 public void visit(IEventTask eventTask) { 
    133                     if (!eventTask.getInstances().isEmpty()) { 
    134                         IEventTaskInstance instance = 
    135                             (IEventTaskInstance) eventTask.getInstances().iterator().next(); 
    136                          
    137                         if (checkBox.equals(instance.getEvent().getTarget())) { 
    138                             tasksUsingCheckBox.add(eventTask); 
    139                         } 
    140                     } 
    141                 } 
    142                  
    143                 @Override 
    144                 public void visit(IStructuringTemporalRelationship relationship) { 
    145                     if (tasksUsingCheckBox.contains(relationship)) { 
    146                         return; 
    147                     } 
    148                     else { 
    149                         for (ITask child : relationship.getChildren()) { 
    150                             if (tasksUsingCheckBox.contains(child)) { 
    151                                 tasksUsingCheckBox.add(relationship); 
    152                                 return; 
    153                             } 
    154                         } 
    155                          
    156                         super.visit(relationship); 
    157                          
    158                         for (ITask child : relationship.getChildren()) { 
    159                             if (tasksUsingCheckBox.contains(child)) { 
    160                                 tasksUsingCheckBox.add(relationship); 
    161                                 break; 
    162                             } 
    163                         } 
    164                     } 
    165                 } 
    166  
    167                 @Override 
    168                 public void visit(IMarkingTemporalRelationship relationship) { 
    169                     if (tasksUsingCheckBox.contains(relationship)) { 
    170                         return; 
    171                     } 
    172                     else { 
    173                         if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) { 
    174                             tasksUsingCheckBox.add(relationship); 
    175                             return; 
    176                         } 
    177                          
    178                         super.visit(relationship); 
    179                          
    180                         if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) { 
    181                             tasksUsingCheckBox.add(relationship); 
    182                             return; 
    183                         } 
    184                     } 
    185                 } 
    186             }); 
    187         } 
    188          
    189         return tasksUsingCheckBox; 
     165            // get a value that is 1 if for one group usage there is on average one check box usage 
     166            // get a value of 0 if for one group usage there is on average two check box usages 
     167             
     168            int ratio = noOfGroupUsages > 0 ? 1000 * noOfSingleCheckBoxUsages / noOfGroupUsages : 0; 
     169             
     170            System.out.println(currentView + "  " + ratio + "  " + noOfGroupUsages + "  " + 
     171                               noOfSingleCheckBoxUsages); 
     172             
     173            UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity 
     174                (ratio, noOfEvents, -1); 
     175                     
     176            if (intensity != null) { 
     177                Map<String, Object> parameters = new HashMap<String, Object>(); 
     178                parameters.put("allUsages", noOfGroupUsages); 
     179                parameters.put("singleUsages", noOfSingleCheckBoxUsages); 
     180                parameters.put("ratio", 100 * noOfSingleCheckBoxUsages / noOfGroupUsages); 
     181                parameters.put("radioButtons", group.getValue()); 
     182 
     183                results.addSmell 
     184                    (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, parameters); 
     185            } 
     186        } 
    190187    } 
    191188 
Note: See TracChangeset for help on using the changeset viewer.