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

Last change on this file since 302 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
Line 
1package de.ugoe.cs.eventbench.commands;
2
3import java.security.InvalidParameterException;
4import java.util.Collection;
5import java.util.List;
6import java.util.Map.Entry;
7import java.util.SortedMap;
8import java.util.TreeMap;
9
10import de.ugoe.cs.eventbench.CommandHelpers;
11import de.ugoe.cs.eventbench.SequenceInstanceOf;
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
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 */
26public class CMDsequenceStatistics implements Command {
27
28        /*
29         * (non-Javadoc)
30         *
31         * @see de.ugoe.cs.util.console.Command#run(java.util.List)
32         */
33        @SuppressWarnings("unchecked")
34        @Override
35        public void run(List<Object> parameters) {
36                String sequencesName;
37                try {
38                        sequencesName = (String) parameters.get(0);
39                } catch (Exception e) {
40                        throw new InvalidParameterException();
41                }
42
43                Collection<List<Event<?>>> sequences = null;
44                Object dataObject = GlobalDataContainer.getInstance().getData(
45                                sequencesName);
46                if (dataObject == null) {
47                        CommandHelpers.objectNotFoundMessage(sequencesName);
48                        return;
49                }
50                if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
51                        CommandHelpers.objectNotType(sequencesName,
52                                        "Collection<List<Event<?>>>");
53                        return;
54                }
55
56                sequences = (Collection<List<Event<?>>>) dataObject;
57                Console.println("Number of Sequences: " + sequences.size());
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);
65                        }
66                }
67                for (Entry<Integer, Integer> entry : lengthMap.entrySet()) {
68                        Console.println("Of length " + entry.getKey() + ": "
69                                        + entry.getValue());
70                }
71        }
72
73        /*
74         * (non-Javadoc)
75         *
76         * @see de.ugoe.cs.util.console.Command#help()
77         */
78        @Override
79        public void help() {
80                Console.println("Usage: sequenceStatistics <sequencesName>");
81        }
82
83}
Note: See TracBrowser for help on using the repository browser.