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