Changeset 54 for trunk/EventBenchConsole/src
- Timestamp:
- 06/09/11 16:26:49 (13 years ago)
- Location:
- trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/web
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/web/commands/CMDloadSessionsFromClickstream.java
r53 r54 1 1 package de.ugoe.cs.eventbench.web.commands; 2 2 3 import java.io.File ;4 import java.io. FileReader;3 import java.io.FileNotFoundException; 4 import java.io.IOException; 5 5 import java.security.InvalidParameterException; 6 import java.text.SimpleDateFormat; 7 import java.util.ArrayList; 8 import java.util.HashMap; 9 import java.util.LinkedList; 6 import java.text.ParseException; 10 7 import java.util.List; 11 import java.util.Map;12 8 13 import de.ugoe.cs.eventbench.web.data.WebEvent; 9 import de.ugoe.cs.eventbench.data.GlobalDataContainer; 10 import de.ugoe.cs.eventbench.web.WeblogParser; 14 11 import de.ugoe.cs.util.console.Command; 15 12 import de.ugoe.cs.util.console.Console; … … 25 22 String source = (String) parameters.get(0); 26 23 27 // TODO needs to be variable 28 long timeout = 3600000; // 1 hour session-timeout 29 30 try { // TODO dummy try/catch block 31 File f = new File(source); 32 FileReader reader = new FileReader(f); 33 char[] buffer = new char[(int) f.length()]; 34 reader.read(buffer); 35 reader.close(); 36 String[] lines = (new String(buffer)).split("\n"); 37 38 Map<String, List<Integer>> cookieSessionMap = new HashMap<String, List<Integer>>(); 39 int lastId = -1; 40 41 List<List<WebEvent>> sessions = new ArrayList<List<WebEvent>>(); 42 43 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 44 45 for( String line : lines ) { 46 String[] values = line.trim().split(" "); 47 48 // use cookie as session identifier 49 int cookieStart = values[0].lastIndexOf('.'); 50 String cookie = values[0].substring(cookieStart+1); 51 String dateString = values[1].substring(1)+" "+values[2].substring(0, values[2].length()-1); 52 long timestamp = dateFormat.parse(dateString).getTime(); 53 String uri = values[3]; 54 String ref = values[4]; 55 List<String> postedVars = new ArrayList<String>(); 56 for( int i=5 ; i<values.length ; i++ ) { 57 postedVars.add(values[i]); 58 } 59 60 61 WebEvent event = new WebEvent(uri, timestamp, postedVars); 62 63 64 // find session and add event 65 List<Integer> sessionIds = cookieSessionMap.get(cookie); 66 if( sessionIds==null ) { 67 sessionIds = new ArrayList<Integer>(); 68 // start new session 69 sessionIds.add(++lastId); 70 cookieSessionMap.put(cookie, sessionIds); 71 sessions.add(new LinkedList<WebEvent>()); 72 } 73 Integer lastSessionIndex = sessionIds.get(sessionIds.size()-1); 74 List<WebEvent> lastSession = sessions.get(lastSessionIndex); 75 long lastEventTime = timestamp; 76 if( !lastSession.isEmpty() ) { 77 lastEventTime = lastSession.get(lastSession.size()-1).getTimestamp(); 78 } 79 if( timestamp-lastEventTime>timeout ) { 80 sessionIds.add(++lastId); 81 List<WebEvent> newSession = new LinkedList<WebEvent>(); 82 newSession.add(event); 83 sessions.add(newSession); 84 } else { 85 lastSession.add(event); 86 } 87 } 88 Console.traceln(sessions.toString()); 89 } catch(Exception e) { 90 e.printStackTrace(); 24 WeblogParser parser = new WeblogParser(); 25 try { 26 parser.parseFile(source); 27 } catch (FileNotFoundException e) { 28 Console.println(e.getMessage()); 29 } catch (IOException e) { 30 Console.println(e.getMessage()); 31 } catch (ParseException e) { 32 Console.println("Invalid format of date stamps."); 33 Console.println(e.getMessage()); 91 34 } 92 35 36 GlobalDataContainer.getInstance().addData("sequences", parser.getSequences()); 93 37 } 94 38
Note: See TracChangeset
for help on using the changeset viewer.