- Timestamp:
- 09/07/17 16:19:49 (7 years ago)
- Location:
- trunk/autoquest-plugin-genericevents/src/main/java/de/ugoe/cs/autoquest/plugin/genericevents
- Files:
-
- 3 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-plugin-genericevents/src/main/java/de/ugoe/cs/autoquest/plugin/genericevents/GenericEventLogParser.java
r2153 r2165 15 15 package de.ugoe.cs.autoquest.plugin.genericevents; 16 16 17 import java.time.Duration; 18 import java.util.GregorianCalendar; 17 19 import java.util.Map; 20 import java.util.Set; 18 21 19 22 import org.xml.sax.SAXException; … … 39 42 public class GenericEventLogParser extends AbstractDefaultLogParser { 40 43 44 /** types of events to be ignored */ 45 private Set<String> ignoredEvents; 46 47 48 /** 49 * <p> 50 * used to provide the parser with a set of ignored event types. 51 * </p> 52 * 53 * @param ignoredEvents 54 */ 55 public GenericEventLogParser(Set<String> ignoredEvents) { 56 super(); 57 this.ignoredEvents = ignoredEvents; 58 } 59 41 60 /* (non-Javadoc) 42 61 * @see de.ugoe.cs.autoquest.plugin.html.AbstractDefaultLogParser#handleGUIElement(String, Map) … … 47 66 { 48 67 String parentId = parameters.get("parent"); 68 69 if (parentId != null) { 70 // check, if the parent is already in the tree 71 if (super.getTargetTree().find(parentId) == null) { 72 // element cannot yet be processed as parent is not existing yet 73 return false; 74 } 75 } 49 76 50 77 GenericEventTargetSpec specification = new GenericEventTargetSpec(id, parameters); … … 66 93 @Override 67 94 protected boolean handleEvent(String type, Map<String, String> parameters) throws SAXException { 95 // ignore the event based on its type if requested 96 if (ignoredEvents.contains(type)) { 97 return true; 98 } 99 68 100 String targetId = parameters.get("targetId"); 101 102 // ignore the event based on type and target id if requested 103 if (ignoredEvents.contains(type + "." + targetId)) { 104 return true; 105 } 69 106 70 107 if (targetId == null) { … … 82 119 83 120 if (timestampStr != null) { 84 event.setTimestamp(Long.parseLong(timestampStr)); 121 event.setTimestamp(determineTimestamp(timestampStr)); 122 } 123 124 for (Map.Entry<String, String> parameter : parameters.entrySet()) { 125 if (!"targetId".equals(parameter.getKey()) && 126 !"timestamp".equals(parameter.getKey())) 127 { 128 event.setParameter(parameter.getKey(), parameter.getValue()); 129 } 85 130 } 86 131 … … 92 137 } 93 138 139 /** 140 * convenience method to align different timestamp formats 141 */ 142 private long determineTimestamp(String timestampStr) { 143 long val = Long.parseLong(timestampStr); 144 145 // We expect any recording to have taken place in years with at most 4 digits. Hence, 146 // divide the val until we reach such a year 147 long max = new GregorianCalendar(10000, 1, 1).getTimeInMillis(); 148 149 while (max < val) { 150 val /= 10; 151 } 152 153 // now, it can still be the case, that the base line is wrong. I.e., the remaining value 154 // may be milliseconds, but not starting from 1970, as we expect it, but starting from 155 // year 1 of the gregorian calendar. If this is the case, the date is still in the future. 156 // Hence, we substract the milliseconds between year 1 of the gregorian calendar and 1970. 157 // (We took these magic number, as they provide correct results. It's not fully clear, 158 // why the January 1st 1970 does not work correctly but provides an offset of two days) 159 if (val > System.currentTimeMillis()) { 160 Duration duration = Duration.between(new GregorianCalendar(1, 1, 1).toInstant(), 161 new GregorianCalendar(1969, 12, 30).toInstant()); 162 163 val -= duration.toMillis(); 164 } 165 166 return val; 167 } 168 94 169 } -
trunk/autoquest-plugin-genericevents/src/main/java/de/ugoe/cs/autoquest/plugin/genericevents/commands/CMDparseDirGenericEvents.java
r2153 r2165 18 18 import java.util.Arrays; 19 19 import java.util.Collection; 20 import java.util.HashSet; 20 21 import java.util.List; 22 import java.util.Set; 21 23 import java.util.logging.Level; 22 24 … … 50 52 String path = null; 51 53 String sequencesName = null; 52 54 55 Set<String> ignoredEvents = new HashSet<>(); 56 53 57 try { 54 58 for (int i = 0; i < parameters.size(); i++) { … … 59 63 else if (sequencesName == null) { 60 64 sequencesName = param; 65 } 66 else { 67 ignoredEvents.add(param); 61 68 } 62 69 } … … 76 83 } 77 84 78 GenericEventLogParser parser = new GenericEventLogParser( );85 GenericEventLogParser parser = new GenericEventLogParser(ignoredEvents); 79 86 80 87 parseFile(folder, parser); … … 121 128 catch (Exception e) { 122 129 Console.printerrln("Could not parse " + source + ": " + e.getMessage()); 130 e.printStackTrace(); 123 131 } 124 132 } … … 132 140 @Override 133 141 public String help() { 134 return "parseDirGenericEvents <directory> [<sequencesName>] ";142 return "parseDirGenericEvents <directory> [<sequencesName>] [<ignoredEventType>*] [<ignoredEventType.ignoredEventTargetId>*]"; 135 143 } 136 144
Note: See TracChangeset
for help on using the changeset viewer.