changeset 1227:940aa00f4790

flow - dropping probs
author Devel 1
date Thu, 25 Jun 2020 14:41:16 +0200
parents 20b9a2c14db3
children ea1994acc93c
files stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerCommand.java stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequences.java stress-tester/src/main/resources/flow_analyzer.py
diffstat 4 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerCommand.java	Thu Jun 25 14:10:53 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/FlowAnalyzerCommand.java	Thu Jun 25 14:41:16 2020 +0200
@@ -20,10 +20,10 @@
     public static final String DEFAULT_PYTHON_CMD = IS_WINDOWS ? "python" : "python3";
     public static final String DEFAULT_SCRIPT_PATH = "flow_analyzer.py";
     public static final String RESOURCE = "/flow_analyzer.py";
-    public static final float DEFAULT_PMIN = 0.05f;
+    public static final float DEFAULT_PMIN = 0.005f;
     public static final int DEFAULT_LMIN = 3;
     public static final int DEFAULT_LMAX = 7;
-    public static final boolean DEFAULT_USE_FOLD = false;
+    public static final boolean DEFAULT_FOLD = false;
 
     String pythonCmd = DEFAULT_PYTHON_CMD;
     String scriptPath = DEFAULT_SCRIPT_PATH;
@@ -31,7 +31,7 @@
     float pmin = DEFAULT_PMIN;
     int lmin = DEFAULT_LMIN;
     int lmax = DEFAULT_LMAX;
-    boolean useFold = DEFAULT_USE_FOLD;
+    boolean fold = DEFAULT_FOLD;
     List<String> cleanRules;
 
     void run() throws IOException, InterruptedException {
@@ -44,7 +44,7 @@
                 pythonCmd, scriptPath, dataPath, "-pmin", Float.toString(pmin),
                 "-lmin", Integer.toString(lmin), "-lmax", Integer.toString(lmax)
         ));
-        if (useFold) {
+        if (fold) {
             commandLine.add("--fold");
         }
         if (cleanRules != null) {
--- a/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java	Thu Jun 25 14:10:53 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequencePayloadAnalyzer.java	Thu Jun 25 14:41:16 2020 +0200
@@ -31,7 +31,6 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.LinkedHashMap;
 
 import static com.passus.config.schema.ConfigurationSchemaBuilder.listDef;
 import static com.passus.config.schema.ConfigurationSchemaBuilder.mapDef;
@@ -72,7 +71,7 @@
         command.pmin = config.getFloat("pmin", FlowAnalyzerCommand.DEFAULT_PMIN);
         command.lmin = config.getInteger("lmin", FlowAnalyzerCommand.DEFAULT_LMIN);
         command.lmax = config.getInteger("lmax", FlowAnalyzerCommand.DEFAULT_LMAX);
-        command.useFold = config.getBoolean("useFold", FlowAnalyzerCommand.DEFAULT_USE_FOLD);
+        command.fold = config.getBoolean("fold", FlowAnalyzerCommand.DEFAULT_FOLD);
         command.cleanRules = config.getList("cleanRules");
     }
 
@@ -167,10 +166,10 @@
         }
     }
 
-    static LinkedHashMap<ArrayList<String>, Double> readSequences(File file, Gson gson) throws IOException {
+    static ArrayList<ArrayList<String>> readSequences(File file, Gson gson) throws IOException {
         try (FileInputStream fis = new FileInputStream(file);
                 InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8)) {
-            return gson.fromJson(isr, LinkedHashMap.class);
+            return gson.fromJson(isr, ArrayList.class);
         }
     }
 
@@ -243,7 +242,7 @@
                     tupleDef("userIdSource", STRING_DEF).setRequired(false),
                     tupleDef("dataPath", STRING_DEF).setRequired(false),
                     tupleDef("cleanRules", listDef()).setRequired(false),
-                    tupleDef("useFold", BOOLEAN_DEF).setRequired(false),
+                    tupleDef("fold", BOOLEAN_DEF).setRequired(false),
                     tupleDef("pmin", FLOAT_GREATER_EQUAL_ZERO_DEF).setRequired(false),
                     tupleDef("lmin", INT_GREATER_THAN_ZERO_DEF).setRequired(false),
                     tupleDef("lmax", INT_GREATER_THAN_ZERO_DEF).setRequired(false)
--- a/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequences.java	Thu Jun 25 14:10:53 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/scanner/HttpUrlSequences.java	Thu Jun 25 14:41:16 2020 +0200
@@ -3,7 +3,6 @@
 import com.passus.commons.metric.Metric;
 import com.passus.st.client.GenericMetric;
 import java.util.ArrayList;
-import java.util.LinkedHashMap;
 
 public class HttpUrlSequences extends GenericMetric {
 
@@ -28,7 +27,7 @@
 
     }
 
-    void addSequences(String name, LinkedHashMap<ArrayList<String>, Double> lSeq) {
+    void addSequences(String name, ArrayList<ArrayList<String>> lSeq) {
         attrs.put(name, lSeq);
     }
 }
--- a/stress-tester/src/main/resources/flow_analyzer.py	Thu Jun 25 14:10:53 2020 +0200
+++ b/stress-tester/src/main/resources/flow_analyzer.py	Thu Jun 25 14:41:16 2020 +0200
@@ -647,9 +647,18 @@
 
     for length in range(args.lmin, args.lmax + 1):
         if args.fold:
-            seq = analyzer.analyze_markov_fold(targetLength=length, foldLoops=True)
+            suffix = '_fold'
+            res = analyzer.analyze_markov_fold(targetLength=length, foldLoops=True)
+            seqs = [(s, prob) for s, prob in res if prob >= args.pmin]
+            folds = analyzer.markovLoopsMapped
+            out = expand(seqs, folds)
         else:
-            seq = analyzer.analyze_markov(targetLength=length)
-        name = "seq_L{}.json".format(length)
-        with open(name, "w") as f:
-            json.dump(seq, f)
+            suffix = ''
+            res = analyzer.analyze_markov(targetLength=length)
+            seqs = [(s, prob) for s, prob in res if prob >= args.pmin]
+            out = [s for s, prob in res if prob >= args.pmin]
+
+        with open("seq_L{}{}_prob.json".format(length, suffix), "w") as f:
+            json.dump(seqs, f)
+        with open("seq_L{}{}.json".format(length, suffix), "w") as f:
+            json.dump(out, f)