[434] | 1 | package de.ugoe.cs.quest.ui.commands;
|
---|
[1] | 2 |
|
---|
| 3 | import java.security.InvalidParameterException;
|
---|
[203] | 4 | import java.util.Collection;
|
---|
[1] | 5 | import java.util.LinkedList;
|
---|
| 6 | import java.util.List;
|
---|
| 7 |
|
---|
[432] | 8 | import de.ugoe.cs.quest.CommandHelpers;
|
---|
| 9 | import de.ugoe.cs.quest.ReplayGenerator;
|
---|
[547] | 10 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
[434] | 11 | import de.ugoe.cs.quest.ui.GlobalDataContainer;
|
---|
[433] | 12 | import de.ugoe.cs.quest.usageprofiles.IStochasticProcess;
|
---|
[1] | 13 | import de.ugoe.cs.util.console.Command;
|
---|
| 14 | import de.ugoe.cs.util.console.Console;
|
---|
| 15 |
|
---|
[171] | 16 | /**
|
---|
| 17 | * <p>
|
---|
| 18 | * Command to create a replay file with randomly generated sessions.
|
---|
| 19 | * </p>
|
---|
| 20 | *
|
---|
| 21 | * @author Steffen Herbold
|
---|
| 22 | * @version 1.0
|
---|
| 23 | */
|
---|
[1] | 24 | public class CMDgenerateRandomReplay implements Command {
|
---|
| 25 |
|
---|
[171] | 26 | /*
|
---|
| 27 | * (non-Javadoc)
|
---|
| 28 | *
|
---|
| 29 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
| 30 | */
|
---|
[1] | 31 | @Override
|
---|
| 32 | public void help() {
|
---|
| 33 | Console.println("Usage: generateRandomReplay <modelName> <filename> {<numSessions>}");
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[171] | 36 | /*
|
---|
| 37 | * (non-Javadoc)
|
---|
| 38 | *
|
---|
| 39 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
| 40 | */
|
---|
[1] | 41 | @Override
|
---|
| 42 | public void run(List<Object> parameters) {
|
---|
| 43 | String modelname;
|
---|
| 44 | String filename;
|
---|
| 45 | int numSessions = 1;
|
---|
| 46 | try {
|
---|
| 47 | modelname = (String) parameters.get(0);
|
---|
| 48 | filename = (String) parameters.get(1);
|
---|
[171] | 49 | if (parameters.size() < 3) {
|
---|
[1] | 50 | numSessions = Integer.parseInt((String) parameters.get(2));
|
---|
| 51 | }
|
---|
[171] | 52 | } catch (Exception e) {
|
---|
[1] | 53 | throw new InvalidParameterException();
|
---|
| 54 | }
|
---|
[171] | 55 |
|
---|
| 56 | IStochasticProcess model = null;
|
---|
| 57 | Object dataObject = GlobalDataContainer.getInstance()
|
---|
| 58 | .getData(modelname);
|
---|
| 59 | if (dataObject == null) {
|
---|
[240] | 60 | CommandHelpers.objectNotFoundMessage(modelname);
|
---|
[209] | 61 | return;
|
---|
| 62 | }
|
---|
| 63 | if (!(dataObject instanceof IStochasticProcess)) {
|
---|
[240] | 64 | CommandHelpers.objectNotType(modelname, "IStochasticProcess");
|
---|
[209] | 65 | return;
|
---|
| 66 | }
|
---|
| 67 | model = (IStochasticProcess) dataObject;
|
---|
[547] | 68 | Collection<List<Event>> sequences = new LinkedList<List<Event>>();
|
---|
[209] | 69 | try {
|
---|
| 70 | for (int i = 0; i < numSessions; i++) {
|
---|
| 71 | sequences
|
---|
[547] | 72 | .add((List<Event>) model.randomSequence());
|
---|
[1] | 73 | }
|
---|
[209] | 74 | } catch (ClassCastException e) {
|
---|
[244] | 75 | Console.printerrln("Modeled events don't support replay.");
|
---|
[1] | 76 | }
|
---|
[209] | 77 | ReplayGenerator generator = new ReplayGenerator();
|
---|
| 78 | generator.createLogfileMultipleSessions(sequences, filename);
|
---|
[1] | 79 | }
|
---|
| 80 |
|
---|
| 81 | }
|
---|