From 02954a7a14351f67306212208b05a7a352784816 Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Thu, 30 Apr 2020 11:44:30 -0700 Subject: [PATCH] kpi: Add group graphs. And customized units on graphs. --- gui/kpi.java | 215 ++++++++++++++++++++++++++++++++++---- gui/testbed_template.html | 12 ++- 2 files changed, 204 insertions(+), 23 deletions(-) diff --git a/gui/kpi.java b/gui/kpi.java index bb4295ce..86374434 100644 --- a/gui/kpi.java +++ b/gui/kpi.java @@ -36,6 +36,9 @@ public class kpi { public static int TEST_ID_IDX = 7; public static int SHORT_DESC_IDX = 8; public static int NUMERIC_SCORE_IDX = 10; + public static int NOTES_IDX = 11; + public static int UNITS_IDX = 12; + public static int GRAPH_GROUP_IDX = 13; public static String TESTBED_TEMPLATE = "testbed_template.html"; public static String AP_AUTO_BASIC_CX = "ap_auto_basic_cx"; @@ -170,12 +173,12 @@ public class kpi { } for (int z = 0; z groupsh = new Hashtable(); + Vector groupsn = new Vector(); + for (HistRow csv : hist.csv) { + String ck = csv.getName(); + String title = csv.getTitle(); + String units = csv.getUnits(); + String g = csv.getGraphGroup(); + + if (!(g.equals("NA") || units.equals(""))) { + Vector gv = groupsh.get(g); + if (gv == null) { + gv = new Vector(); + groupsh.put(g, gv); + groupsn.add(g); + } + gv.add(csv); + } + + if (units.equals("NA") || units.equals("")) { + units = "Data"; + } try { String cf = dir + File.separator + hk + "::" + ck + ".csv"; FileWriter f = new FileWriter(cf); - f.write(csv.toString()); + f.write(csv.csv.toString()); f.close(); + csv.setFname(cf); ShellExec exec = new ShellExec(true, true); - int rv = exec.execute("gnuplot", null, true, "-e", "filename='" + cf + "'", + int rv = exec.execute("gnuplot", null, true, + "-e", "set ylabel \"" + units + "\"", + "-e", "filename='" + cf + "'", "-e", "set title '" + title + "'", "default.plot"); if (rv != 0) { @@ -236,6 +259,97 @@ public class kpi { ee.printStackTrace(); } } + + // Graph groups + for (String g : groupsn) { + Vector datasets = groupsh.get(g); + if (datasets.size() < 2) { + continue; // group of 1 doesn't count + } + + HistRow csv0 = datasets.elementAt(0); + String title = g; + String units = csv0.getUnits(); + + if (units.equals("NA") || units.equals("")) { + units = "Data"; + } + + System.out.println("title: " + title + " units: " + units); + try { + StringBuffer plot = new StringBuffer("plot "); + StringBuffer mplot = new StringBuffer("plot "); + boolean first = true; + for (HistRow csv: datasets) { + if (!first) { + plot.append(", "); + mplot.append(", "); + } + plot.append("\'" + csv.getFname() + "\' using 1:2 with lines title \'" + csv.getName().replace("_", " ") + "\'"); + mplot.append("\'" + csv.getFname() + "\' using 1:2 notitle"); + first = false; + } + + BufferedReader br = new BufferedReader(new FileReader("default_group.plot")); + FileWriter f = new FileWriter("tmp.plot"); + String line; + while ((line = br.readLine()) != null) { + f.write(line); + f.write(System.lineSeparator()); + } + f.write(plot.toString()); + f.write(System.lineSeparator()); + f.close(); + br.close(); + + //System.out.println("group plot: " + plot); + ShellExec exec = new ShellExec(true, true); + int rv = exec.execute("gnuplot", null, true, + "-e", "set ylabel '" + units + "'", + "-e", "set title '" + title + "'", + "tmp.plot"); + if (rv != 0) { + System.out.println("gnuplot for group: " + title + " rv: " + rv); + System.out.println(exec.getOutput()); + System.out.println(exec.getError()); + } + + File png = new File("plot.png"); + String npng = hk + "::" + g + ".png"; + png.renameTo(new File(dir + File.separator + npng)); + + br = new BufferedReader(new FileReader("mini_group.plot")); + f = new FileWriter("tmp.plot"); + while ((line = br.readLine()) != null) { + f.write(line); + f.write(System.lineSeparator()); + } + f.write(mplot.toString()); + f.write(System.lineSeparator()); + f.close(); + br.close(); + + exec = new ShellExec(true, true); + rv = exec.execute("gnuplot", null, true, + "tmp.plot"); + if (rv != 0) { + System.out.println("mini gnuplot for group: " + title + " rv: " + rv); + System.out.println(exec.getOutput()); + System.out.println(exec.getError()); + } + + png = new File("plot.png"); + String npngt = hk + "::" + g + "-thumb.png"; + png.renameTo(new File(dir + File.separator + npngt)); + + groups.append("" + hk + "" + title + "\n"); + + } + catch (Exception ee) { + ee.printStackTrace(); + } + } + } String test_bed = "Test Bed"; @@ -273,6 +387,7 @@ public class kpi { String line; while ((line = br.readLine()) != null) { line = line.replace("___TITLE___", test_bed + " Report History"); + line = line.replace("___GROUP_GRAPHS___", groups.toString()); line = line.replace("___DATA_GRAPHS___", plots.toString()); line = line.replace("___TEST_RUNS___", runs_rows.toString()); bw.write(line); @@ -295,12 +410,50 @@ public class kpi { } } +class HistRow { + String fname; + String name; + String title = ""; + String units = ""; + String graph_group = ""; + StringBuffer csv = new StringBuffer(); + + public HistRow(Row r) { + name = r.getShortDescKey(); + title = r.getShortDesc(); + units = r.getUnits(); + graph_group = r.getGraphGroup(); + } + + String getFname() { + return fname; + } + + void setFname(String s) { + fname = s; + } + + String getName() { + return name; + } + + String getTitle() { + return title; + } + + String getUnits() { + return units; + } + + String getGraphGroup() { + return graph_group; + } +} + class History { String name; - Vector csv = new Vector(); - Vector csv_names = new Vector(); - Hashtable csvh = new Hashtable(); // lookup by name - Hashtable titles = new Hashtable(); // lookup by name + Vector csv = new Vector(); + Hashtable csvh = new Hashtable(); // lookup by name public History(String n) { name = n; @@ -310,16 +463,14 @@ class History { return name; } - StringBuffer findCsv(String n) { + HistRow findRow(String n) { //System.out.println("findCsv, n: " + n); return csvh.get(n); } - void addCsv(StringBuffer b, String n, String title) { - csv.add(b); - csv_names.add(n); - csvh.put(n, b); - titles.put(n, title); + void addRow(HistRow r) { + csv.add(r); + csvh.put(r.getName(), r); } } @@ -327,6 +478,28 @@ class Row { Vector rdata = new Vector(); String short_desc_key = null; + String getNotes() { + return rdata.elementAt(kpi.NOTES_IDX); + } + + String getUnits() { + try { + return rdata.elementAt(kpi.UNITS_IDX); + } + catch (Exception e) { + return ""; + } + } + + String getGraphGroup() { + try { + return rdata.elementAt(kpi.GRAPH_GROUP_IDX); + } + catch (Exception e) { + return ""; + } + } + String getScore() { return rdata.elementAt(kpi.NUMERIC_SCORE_IDX); } diff --git a/gui/testbed_template.html b/gui/testbed_template.html index 6a37c689..78ddac08 100644 --- a/gui/testbed_template.html +++ b/gui/testbed_template.html @@ -24,10 +24,10 @@
-

Historical graphs for each Data Set.

+

Historical graphs for each Data Set Group.

- ___DATA_GRAPHS___ + ___GROUP_GRAPHS___
Test-IdDescriptionPlot Thumbnail

@@ -36,6 +36,14 @@ Test RunDateDUT HardwareDUT SofwareDUT Model ___TEST_RUNS___ +

+ +

Historical graphs for each Data Set.

+ + + ___DATA_GRAPHS___ +
Test-IdDescriptionPlot Thumbnail
+

Generated by Candela Technologies LANforge network testing tool.