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