Ignore:
Timestamp:
07/30/15 14:34:02 (9 years ago)
Author:
pharms
Message:
  • extended task tree statistics to also get average session length and CSV formated output
File:
1 edited

Legend:

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

    r1886 r2032  
    1515package de.ugoe.cs.autoquest.commands.usability; 
    1616 
     17import java.text.DecimalFormat; 
    1718import java.util.HashSet; 
     19import java.util.LinkedList; 
    1820import java.util.List; 
    1921import java.util.Set; 
     22 
     23import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; 
    2024 
    2125import de.ugoe.cs.autoquest.CommandHelpers; 
     
    3034import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; 
    3135import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; 
    32 import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric; 
     36import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 
     37import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskTreeUtils; 
    3338import de.ugoe.cs.util.console.Command; 
    3439import de.ugoe.cs.util.console.Console; 
     
    8287        ITaskModel taskModel = (ITaskModel) dataObject; 
    8388 
    84         int taskCount = 0; 
    85         int allTasks = taskModel.getTasks().size(); 
    86         Set<IEventTaskInstance> coveredEvents = new HashSet<IEventTaskInstance>(); 
    8789        int allEvents = 0; 
    8890         
     
    9294        int noOfSelections = 0; 
    9395        int noOfOptionals = 0; 
     96        Set<IEventTaskInstance> coveredEvents = new HashSet<IEventTaskInstance>(); 
    9497         
    9598        for (ITask task : taskModel.getTasks()) { 
    96             int covQuant = 
    97                 taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE_QUANTILE); 
    98              
    99             if (covQuant >= 950) { 
    100                 taskCount++; 
    101                 getCoveredEvents(task, coveredEvents); 
    102             } 
    103              
    10499            if (task instanceof IEventTask) { 
    105100                noOfEventTasks++; 
     
    108103            else if (task instanceof ISequence) { 
    109104                noOfSequences++; 
     105                getCoveredEvents(task, coveredEvents); 
    110106            } 
    111107            else if (task instanceof IIteration) { 
     
    120116        } 
    121117         
    122         Console.println(noOfEventTasks + " eventTasks, " + noOfSequences + " sequences, " + 
    123                         noOfIterations + " iterations, " + noOfSelections + " selections, " + 
    124                         noOfOptionals + " optionals"); 
    125         Console.println(taskCount + " of " + allTasks + " tasks (" + (taskCount * 100 / allTasks) + 
    126                         "%) covered " + coveredEvents.size() + " of " + allEvents + 
    127                         " recorded events (" + (coveredEvents.size() * 100 / allEvents) + "%)"); 
     118        DescriptiveStatistics stats = new DescriptiveStatistics(); 
     119         
     120        for (IUserSession session : taskModel.getUserSessions()) { 
     121            if (session.size() > 0) { 
     122                final List<IEventTaskInstance> events = new LinkedList<>(); 
     123                 
     124                for (ITaskInstance instance : session) { 
     125                    instance.accept(new DefaultTaskInstanceTraversingVisitor() { 
     126                        @Override 
     127                        public void visit(IEventTaskInstance eventTaskInstance) { 
     128                            events.add(eventTaskInstance); 
     129                        } 
     130                    }); 
     131                } 
     132                 
     133                stats.addValue(events.size()); 
     134            } 
     135        } 
     136         
     137        Console.println(stats.getN() + " sessions"); 
     138        Console.println("average session length " + stats.getMean() + " (std dev " + 
     139                        stats.getStandardDeviation() + ")"); 
     140        Console.println(allEvents + " events"); 
     141         
     142        Console.println(noOfEventTasks + " eventTasks"); 
     143        Console.println(noOfSequences + " sequences"); 
     144        Console.println(noOfIterations + " iterations"); 
     145        Console.println(noOfSelections + " selections"); 
     146        Console.println(noOfOptionals + " optionals"); 
     147         
     148        Set<ISequence> mostProminent = 
     149            TaskTreeUtils.getMostProminentTasks(taskModel, taskModel.getTasks()); 
     150         
     151        Set<IEventTaskInstance> mpCoveredEvents = new HashSet<IEventTaskInstance>(); 
     152        
     153        for (ITask task : mostProminent) { 
     154            getCoveredEvents(task, mpCoveredEvents); 
     155        } 
     156         
     157        Console.println(noOfSequences + " sequences cover " + 
     158                        coveredEvents.size() + " of " + allEvents + " recorded events (" + 
     159                        formatPercent(coveredEvents.size(), allEvents) + ")"); 
     160         
     161        Console.println(mostProminent.size() + " of " + noOfSequences + " sequences (" + 
     162                        formatPercent(mostProminent.size(), noOfSequences) + ") cover " + 
     163                        mpCoveredEvents.size() + " of " + allEvents + " recorded events (" + 
     164                        formatPercent(mpCoveredEvents.size(), allEvents) + ")"); 
     165         
     166        Console.println("CSV: " + tasktreeName + ";" + noOfEventTasks + ";" + noOfSequences + ";" + 
     167                        noOfIterations + ";" + noOfSelections + ";" + noOfOptionals + ";" + 
     168                        allEvents + ";" + coveredEvents.size() + ";" + 
     169                        formatPercent(coveredEvents.size(), allEvents) + ";" + 
     170                        mostProminent.size() + ";" + 
     171                        formatPercent(mostProminent.size(), noOfSequences) + ";" + 
     172                        mpCoveredEvents.size() + ";" + 
     173                        formatPercent(mpCoveredEvents.size(), allEvents)); 
     174    } 
     175 
     176    /** 
     177     * convenience method to format a percentage 
     178     */ 
     179    private String formatPercent(int ratio, int full) { 
     180        return new DecimalFormat("#,##0.0%").format(((double) ratio) / full); 
    128181    } 
    129182 
Note: See TracChangeset for help on using the changeset viewer.