1 | package de.ugoe.cs.eventbench.web.commands;
|
---|
2 |
|
---|
3 | import java.io.FileNotFoundException;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.security.InvalidParameterException;
|
---|
6 | import java.text.ParseException;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
11 | import de.ugoe.cs.eventbench.web.WeblogParser;
|
---|
12 | import de.ugoe.cs.eventbench.web.data.WebEvent;
|
---|
13 | import de.ugoe.cs.util.console.Command;
|
---|
14 | import de.ugoe.cs.util.console.Console;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * <p>
|
---|
18 | * Command to load sessions from a web log.
|
---|
19 | * </p>
|
---|
20 | *
|
---|
21 | * @author Steffen Herbold
|
---|
22 | * @version 1.0
|
---|
23 | */
|
---|
24 | public class CMDloadSessionsFromClickstream implements Command {
|
---|
25 |
|
---|
26 | /*
|
---|
27 | * (non-Javadoc)
|
---|
28 | *
|
---|
29 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
30 | */
|
---|
31 | @Override
|
---|
32 | public void run(List<Object> parameters) {
|
---|
33 | if (parameters.size() < 1) {
|
---|
34 | throw new InvalidParameterException();
|
---|
35 | }
|
---|
36 | String source;
|
---|
37 | String sequencesName;
|
---|
38 | String serverUrl = null;
|
---|
39 | int timeout = -1;
|
---|
40 | int minLength = -1;
|
---|
41 | int maxLength = -1;
|
---|
42 | boolean generateFrequentUsers = false;
|
---|
43 | int frequentUserThreshold = 20;
|
---|
44 | try {
|
---|
45 | source = (String) parameters.get(0);
|
---|
46 | sequencesName = (String) parameters.get(1);
|
---|
47 | if (parameters.size() >= 3) {
|
---|
48 | serverUrl = (String) parameters.get(2);
|
---|
49 | }
|
---|
50 | if (parameters.size() >= 6) {
|
---|
51 | timeout = Integer.parseInt((String) parameters.get(3));
|
---|
52 | minLength = Integer.parseInt((String) parameters.get(4));
|
---|
53 | maxLength = Integer.parseInt((String) parameters.get(5));
|
---|
54 | }
|
---|
55 | if (parameters.size() >= 8) {
|
---|
56 | generateFrequentUsers = Boolean
|
---|
57 | .parseBoolean((String) parameters.get(6));
|
---|
58 | frequentUserThreshold = Integer.parseInt((String) parameters
|
---|
59 | .get(7));
|
---|
60 | }
|
---|
61 | } catch (Exception e) {
|
---|
62 | throw new InvalidParameterException();
|
---|
63 | }
|
---|
64 |
|
---|
65 | WeblogParser parser = new WeblogParser();
|
---|
66 | if (serverUrl != null) {
|
---|
67 | parser.setUrl(serverUrl);
|
---|
68 | }
|
---|
69 | if (timeout != -1) {
|
---|
70 | parser.setTimeout(timeout);
|
---|
71 | parser.setMinLength(minLength);
|
---|
72 | parser.setMaxLength(maxLength);
|
---|
73 | }
|
---|
74 | if (generateFrequentUsers) {
|
---|
75 | parser.setFrequentUserThreshold(frequentUserThreshold);
|
---|
76 | }
|
---|
77 | try {
|
---|
78 | parser.parseFile(source);
|
---|
79 | } catch (FileNotFoundException e) {
|
---|
80 | Console.println(e.getMessage());
|
---|
81 | } catch (IOException e) {
|
---|
82 | Console.println(e.getMessage());
|
---|
83 | } catch (ParseException e) {
|
---|
84 | Console.println("Invalid format of date stamps.");
|
---|
85 | Console.println(e.getMessage());
|
---|
86 | }
|
---|
87 |
|
---|
88 | if (GlobalDataContainer.getInstance().addData(sequencesName,
|
---|
89 | parser.getSequences())) {
|
---|
90 | Console.traceln("Old data \"" + sequencesName + "\" overwritten");
|
---|
91 | }
|
---|
92 | if (generateFrequentUsers) {
|
---|
93 | List<String> frequentUserIDs = parser.getFrequentUsers();
|
---|
94 | List<Collection<List<WebEvent>>> frequentUserSessions = parser
|
---|
95 | .getFrequentUserSequences();
|
---|
96 | for (int i = 0; i < frequentUserIDs.size(); i++) {
|
---|
97 | if (GlobalDataContainer.getInstance().addData(
|
---|
98 | sequencesName + "_" + frequentUserIDs.get(i),
|
---|
99 | frequentUserSessions.get(i))) {
|
---|
100 | Console.traceln("Old data \"" + sequencesName
|
---|
101 | + "\" overwritten");
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * (non-Javadoc)
|
---|
109 | *
|
---|
110 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
111 | */
|
---|
112 | @Override
|
---|
113 | public void help() {
|
---|
114 | Console.println("Usage: loadSessionsFromClickstream <filename> <sequencesName> {<serverUrl>} {<timeout> <minSessionLength> <maxSessionLength>} {<generateFrequentUsers> <frequentUserThreshold>}");
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|