source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/commands/CMDsequenceStatistics.java

Last change on this file was 241, checked in by sherbold, 13 years ago
  • some changes to command parameter orders
  • removed command printRandomSesssion
  • renamed command loadSessionsFromClickstream do loadWebSequences
  • Property svn:mime-type set to text/plain
File size: 2.3 KB
RevLine 
[113]1package de.ugoe.cs.eventbench.commands;
2
[241]3import java.security.InvalidParameterException;
[203]4import java.util.Collection;
[113]5import java.util.List;
6import java.util.Map.Entry;
7import java.util.SortedMap;
8import java.util.TreeMap;
9
[240]10import de.ugoe.cs.eventbench.CommandHelpers;
[209]11import de.ugoe.cs.eventbench.SequenceInstanceOf;
[113]12import de.ugoe.cs.eventbench.data.Event;
13import de.ugoe.cs.eventbench.data.GlobalDataContainer;
14import de.ugoe.cs.util.console.Command;
15import de.ugoe.cs.util.console.Console;
16
[171]17/**
18 * <p>
19 * Command to print basic statistical information about stored sequences, e.g.,
20 * how many there are of which lenght.
21 * </p>
22 *
23 * @author Steffen Herbold
24 * @version 1.0
25 */
[113]26public class CMDsequenceStatistics implements Command {
27
[171]28        /*
29         * (non-Javadoc)
30         *
31         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
32         */
[113]33        @SuppressWarnings("unchecked")
34        @Override
35        public void run(List<Object> parameters) {
[241]36                String sequencesName;
37                try {
[113]38                        sequencesName = (String) parameters.get(0);
[241]39                } catch (Exception e) {
40                        throw new InvalidParameterException();
[113]41                }
[171]42
[203]43                Collection<List<Event<?>>> sequences = null;
[171]44                Object dataObject = GlobalDataContainer.getInstance().getData(
45                                sequencesName);
[209]46                if (dataObject == null) {
[240]47                        CommandHelpers.objectNotFoundMessage(sequencesName);
[209]48                        return;
49                }
50                if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
[240]51                        CommandHelpers.objectNotType(sequencesName,
52                                        "Collection<List<Event<?>>>");
[209]53                        return;
54                }
[171]55
[209]56                sequences = (Collection<List<Event<?>>>) dataObject;
[241]57                Console.println("Number of Sequences: " + sequences.size());
[209]58                SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>();
59                for (List<Event<?>> sequence : sequences) {
60                        Integer currentSize = sequence.size();
61                        if (lengthMap.containsKey(currentSize)) {
62                                lengthMap.put(currentSize, lengthMap.get(currentSize) + 1);
63                        } else {
64                                lengthMap.put(currentSize, 1);
[113]65                        }
66                }
[209]67                for (Entry<Integer, Integer> entry : lengthMap.entrySet()) {
[241]68                        Console.println("Of length " + entry.getKey() + ": "
[209]69                                        + entry.getValue());
70                }
[113]71        }
72
[171]73        /*
74         * (non-Javadoc)
75         *
76         * @see de.ugoe.cs.util.console.Command#help()
77         */
[113]78        @Override
79        public void help() {
[241]80                Console.println("Usage: sequenceStatistics <sequencesName>");
[113]81        }
82
83}
Note: See TracBrowser for help on using the repository browser.