| 1 | package de.ugoe.cs.eventbench.commands;
|
|---|
| 2 |
|
|---|
| 3 | import java.security.InvalidParameterException;
|
|---|
| 4 | import java.util.Collection;
|
|---|
| 5 | import java.util.List;
|
|---|
| 6 |
|
|---|
| 7 | import de.ugoe.cs.eventbench.SequenceInstanceOf;
|
|---|
| 8 | import de.ugoe.cs.eventbench.coverage.CoverageCalculatorObserved;
|
|---|
| 9 | import de.ugoe.cs.eventbench.coverage.CoverageCalculatorProcess;
|
|---|
| 10 | import de.ugoe.cs.eventbench.data.Event;
|
|---|
| 11 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
|---|
| 12 | import de.ugoe.cs.eventbench.models.IStochasticProcess;
|
|---|
| 13 | import de.ugoe.cs.util.console.Command;
|
|---|
| 14 | import de.ugoe.cs.util.console.Console;
|
|---|
| 15 |
|
|---|
| 16 | /**
|
|---|
| 17 | * <p>
|
|---|
| 18 | * Command to calculate the coverage of a test suite.
|
|---|
| 19 | * </p>
|
|---|
| 20 | *
|
|---|
| 21 | * @author Steffen Herbold
|
|---|
| 22 | * @version 1.0
|
|---|
| 23 | */
|
|---|
| 24 | public class CMDcalcCoverage implements Command {
|
|---|
| 25 |
|
|---|
| 26 | /*
|
|---|
| 27 | * (non-Javadoc)
|
|---|
| 28 | *
|
|---|
| 29 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
|---|
| 30 | */
|
|---|
| 31 | @SuppressWarnings("unchecked")
|
|---|
| 32 | @Override
|
|---|
| 33 | public void run(List<Object> parameters) {
|
|---|
| 34 | String modelname;
|
|---|
| 35 | String[] sequenceNames;
|
|---|
| 36 | int minLength;
|
|---|
| 37 | int maxLength;
|
|---|
| 38 | String observedName = "sequences";
|
|---|
| 39 | try {
|
|---|
| 40 | modelname = (String) parameters.get(0);
|
|---|
| 41 | sequenceNames = (String[]) parameters.get(1);
|
|---|
| 42 | minLength = Integer.parseInt((String) parameters.get(2));
|
|---|
| 43 | maxLength = Integer.parseInt((String) parameters.get(3));
|
|---|
| 44 | if (parameters.size() == 5) {
|
|---|
| 45 | observedName = (String) parameters.get(1);
|
|---|
| 46 | }
|
|---|
| 47 | } catch (Exception e) {
|
|---|
| 48 | throw new InvalidParameterException();
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | IStochasticProcess process = null;
|
|---|
| 52 | Collection<List<? extends Event<?>>> observedSequences = null;
|
|---|
| 53 | Collection<List<? extends Event<?>>> sequences = null;
|
|---|
| 54 | Object dataObjectProcess = GlobalDataContainer.getInstance().getData(
|
|---|
| 55 | modelname);
|
|---|
| 56 | Object dataObjectObserved = GlobalDataContainer.getInstance().getData(
|
|---|
| 57 | observedName);
|
|---|
| 58 | if (dataObjectProcess == null) {
|
|---|
| 59 | Console.printerrln("Model " + modelname + " not found in storage.");
|
|---|
| 60 | return;
|
|---|
| 61 | }
|
|---|
| 62 | if (!(dataObjectProcess instanceof IStochasticProcess)) {
|
|---|
| 63 | Console.printerrln("Object " + modelname
|
|---|
| 64 | + " not of type IStochasticProcess!");
|
|---|
| 65 | return;
|
|---|
| 66 | }
|
|---|
| 67 | if (dataObjectObserved == null) {
|
|---|
| 68 | Console.printerrln("Observed sequences not found in storage.");
|
|---|
| 69 | return;
|
|---|
| 70 | }
|
|---|
| 71 | if (!SequenceInstanceOf.isCollectionOfSequences(dataObjectObserved)) {
|
|---|
| 72 | Console.printerrln("Object " + observedName
|
|---|
| 73 | + " of type Collection<List<Event<?>>>!");
|
|---|
| 74 | return;
|
|---|
| 75 | }
|
|---|
| 76 | process = (IStochasticProcess) dataObjectProcess;
|
|---|
| 77 | observedSequences = (Collection<List<? extends Event<?>>>) dataObjectObserved;
|
|---|
| 78 |
|
|---|
| 79 | Console.print("seqName");
|
|---|
| 80 | for (int length = minLength; length <= maxLength; length++) {
|
|---|
| 81 | Console.print(";numObs_" + length);
|
|---|
| 82 | Console.print(";numCov_" + length);
|
|---|
| 83 | Console.print(";numNew_" + length);
|
|---|
| 84 | Console.print(";numPos_" + length);
|
|---|
| 85 | Console.print(";all_" + length);
|
|---|
| 86 | Console.print(";pos_" + length);
|
|---|
| 87 | Console.print(";poswei_" + length);
|
|---|
| 88 | Console.print(";obs_" + length);
|
|---|
| 89 | Console.print(";obswei_" + length);
|
|---|
| 90 | Console.print(";new_" + length);
|
|---|
| 91 | Console.print(";newpos_" + length);
|
|---|
| 92 | Console.print(";newposwei_" + length);
|
|---|
| 93 | }
|
|---|
| 94 | Console.println("");
|
|---|
| 95 | for (String sequenceName : sequenceNames) {
|
|---|
| 96 | Object dataObjectSequences = GlobalDataContainer.getInstance()
|
|---|
| 97 | .getData(sequenceName);
|
|---|
| 98 | if (dataObjectSequences == null) {
|
|---|
| 99 | Console.println("Sequences " + sequenceName
|
|---|
| 100 | + " not found in storage.");
|
|---|
| 101 | return;
|
|---|
| 102 | } else if (!SequenceInstanceOf
|
|---|
| 103 | .isCollectionOfSequences(dataObjectSequences)) {
|
|---|
| 104 | Console.printerrln("Object " + sequenceName
|
|---|
| 105 | + "not of type Collection<List<Event<?>!");
|
|---|
| 106 | return;
|
|---|
| 107 | }
|
|---|
| 108 | sequences = (Collection<List<? extends Event<?>>>) dataObjectSequences;
|
|---|
| 109 | Console.print(sequenceName);
|
|---|
| 110 | for (int length = minLength; length <= maxLength; length++) {
|
|---|
| 111 | CoverageCalculatorProcess covCalcProc = new CoverageCalculatorProcess(
|
|---|
| 112 | process, sequences, length);
|
|---|
| 113 | CoverageCalculatorObserved covCalcObs = new CoverageCalculatorObserved(
|
|---|
| 114 | observedSequences, sequences, length);
|
|---|
| 115 | Console.print(";" + covCalcObs.getNumObserved());
|
|---|
| 116 | Console.print(";" + covCalcObs.getNumCovered());
|
|---|
| 117 | Console.print(";" + covCalcObs.getNumNew());
|
|---|
| 118 | Console.print(";" + covCalcProc.getNumPossible());
|
|---|
| 119 | Console.print(";" + covCalcProc.getCoverageAllNoWeight());
|
|---|
| 120 | Console.print(";" + covCalcProc.getCoveragePossibleNoWeight());
|
|---|
| 121 | Console.print(";" + covCalcProc.getCoveragePossibleWeight());
|
|---|
| 122 | Console.print(";" + covCalcObs.getCoverageObserved());
|
|---|
| 123 | Console.print(";"
|
|---|
| 124 | + covCalcObs.getCoverageObservedWeigth(process));
|
|---|
| 125 | Console.print(";" + covCalcObs.getNewPercentage());
|
|---|
| 126 | Console.print(";" + covCalcObs.getCoveragePossibleNew(process));
|
|---|
| 127 | Console.print(";"
|
|---|
| 128 | + covCalcObs.getCoveragePossibleNewWeight(process));
|
|---|
| 129 | }
|
|---|
| 130 | Console.println("");
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | /*
|
|---|
| 135 | * (non-Javadoc)
|
|---|
| 136 | *
|
|---|
| 137 | * @see de.ugoe.cs.util.console.Command#help()
|
|---|
| 138 | */
|
|---|
| 139 | @Override
|
|---|
| 140 | public void help() {
|
|---|
| 141 | Console.println("Usage: calcCoverage <modelname> [sequenceNames] <minCovLength> <maxCovLength>");
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | }
|
|---|