Changeset 1637
- Timestamp:
- 07/31/14 17:18:14 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/sequences/CMDsequenceStatistics.java
r927 r1637 15 15 package de.ugoe.cs.autoquest.commands.sequences; 16 16 17 import java.text.SimpleDateFormat; 17 18 import java.util.Collection; 19 import java.util.Date; 18 20 import java.util.List; 19 21 import java.util.Map.Entry; … … 30 32 /** 31 33 * <p> 32 * Command to print basic statistical information about stored sequences, e.g., 33 * how many there areof which length.34 * Command to print basic statistical information about stored sequences, e.g., how many there are 35 * of which length. 34 36 * </p> 35 37 * … … 39 41 public class CMDsequenceStatistics implements Command { 40 42 41 /* 42 * (non-Javadoc) 43 * 44 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 45 */ 46 @SuppressWarnings("unchecked") 47 @Override 48 public void run(List<Object> parameters) { 49 String sequencesName; 50 try { 51 sequencesName = (String) parameters.get(0); 52 } catch (Exception e) { 53 throw new IllegalArgumentException(); 54 } 43 /* 44 * (non-Javadoc) 45 * 46 * @see de.ugoe.cs.util.console.Command#run(java.util.List) 47 */ 48 @SuppressWarnings("unchecked") 49 @Override 50 public void run(List<Object> parameters) { 51 String sequencesName; 52 try { 53 sequencesName = (String) parameters.get(0); 54 } 55 catch (Exception e) { 56 throw new IllegalArgumentException(); 57 } 55 58 56 Collection<List<Event>> sequences = null; 57 Object dataObject = GlobalDataContainer.getInstance().getData( 58 sequencesName); 59 if (dataObject == null) { 60 CommandHelpers.objectNotFoundMessage(sequencesName); 61 return; 62 } 63 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 64 CommandHelpers.objectNotType(sequencesName, 65 "Collection<List<Event<?>>>"); 66 return; 67 } 59 Collection<List<Event>> sequences = null; 60 Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName); 61 if (dataObject == null) { 62 CommandHelpers.objectNotFoundMessage(sequencesName); 63 return; 64 } 65 if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) { 66 CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>"); 67 return; 68 } 68 69 69 sequences = (Collection<List<Event>>) dataObject; 70 Console.println("Number of Sequences: " + sequences.size()); 71 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>(); 72 for (List<Event> sequence : sequences) { 73 Integer currentSize = sequence.size(); 74 if (lengthMap.containsKey(currentSize)) { 75 lengthMap.put(currentSize, lengthMap.get(currentSize) + 1); 76 } else { 77 lengthMap.put(currentSize, 1); 78 } 79 } 80 for (Entry<Integer, Integer> entry : lengthMap.entrySet()) { 81 Console.println("Of length " + entry.getKey() + ": " 82 + entry.getValue()); 83 } 84 } 70 sequences = (Collection<List<Event>>) dataObject; 71 Console.println("Number of Sequences: " + sequences.size()); 85 72 86 /* 87 * (non-Javadoc) 88 * 89 * @see de.ugoe.cs.util.console.Command#help() 90 */ 91 @Override 92 public String help() { 93 return "sequenceStatistics <sequencesName>"; 94 } 73 long smallestTimeStamp = Long.MAX_VALUE; 74 long largestTimeStamp = 0; 75 int noOfEvents = 0; 76 77 SortedMap<Integer, Integer> lengthMap = new TreeMap<Integer, Integer>(); 78 for (List<Event> sequence : sequences) { 79 Integer currentSize = sequence.size(); 80 noOfEvents += currentSize; 81 82 if (lengthMap.containsKey(currentSize)) { 83 lengthMap.put(currentSize, lengthMap.get(currentSize) + 1); 84 } 85 else { 86 lengthMap.put(currentSize, 1); 87 } 88 89 for (Event event : sequence) { 90 if (event.getTimestamp() > 0) { 91 smallestTimeStamp = Math.min(smallestTimeStamp, event.getTimestamp()); 92 largestTimeStamp = Math.max(largestTimeStamp, event.getTimestamp()); 93 } 94 } 95 } 96 97 Console.println("Number of Events: " + noOfEvents); 98 Console.println("First Event Recorded At: " + 99 SimpleDateFormat.getDateTimeInstance().format(new Date(smallestTimeStamp))); 100 Console.println("Last Event Recorded At: " + 101 SimpleDateFormat.getDateTimeInstance().format(new Date(largestTimeStamp))); 102 103 for (Entry<Integer, Integer> entry : lengthMap.entrySet()) { 104 Console.println("Sequences of Length " + entry.getKey() + ": " + entry.getValue()); 105 } 106 } 107 108 /* 109 * (non-Javadoc) 110 * 111 * @see de.ugoe.cs.util.console.Command#help() 112 */ 113 @Override 114 public String help() { 115 return "sequenceStatistics <sequencesName>"; 116 } 95 117 96 118 }
Note: See TracChangeset
for help on using the changeset viewer.