PAL: Add processing of PPS and CPS tests
[csit.git] / resources / tools / presentation / generator_cpta.py
index 511800a..47e934e 100644 (file)
@@ -92,20 +92,31 @@ THEME_OVERRIDES = u"""/* override table width restrictions */
 }
 """
 
-COLORS = [
-    u"SkyBlue", u"Olive", u"Purple", u"Coral", u"Indigo", u"Pink",
-    u"Chocolate", u"Brown", u"Magenta", u"Cyan", u"Orange", u"Black",
-    u"Violet", u"Blue", u"Yellow", u"BurlyWood", u"CadetBlue", u"Crimson",
-    u"DarkBlue", u"DarkCyan", u"DarkGreen", u"Green", u"GoldenRod",
-    u"LightGreen", u"LightSeaGreen", u"LightSkyBlue", u"Maroon",
-    u"MediumSeaGreen", u"SeaGreen", u"LightSlateGrey",
-    u"SkyBlue", u"Olive", u"Purple", u"Coral", u"Indigo", u"Pink",
-    u"Chocolate", u"Brown", u"Magenta", u"Cyan", u"Orange", u"Black",
-    u"Violet", u"Blue", u"Yellow", u"BurlyWood", u"CadetBlue", u"Crimson",
-    u"DarkBlue", u"DarkCyan", u"DarkGreen", u"Green", u"GoldenRod",
-    u"LightGreen", u"LightSeaGreen", u"LightSkyBlue", u"Maroon",
-    u"MediumSeaGreen", u"SeaGreen", u"LightSlateGrey"
-]
+COLORS = (
+    u"#1A1110",
+    u"#DA2647",
+    u"#214FC6",
+    u"#01786F",
+    u"#BD8260",
+    u"#FFD12A",
+    u"#A6E7FF",
+    u"#738276",
+    u"#C95A49",
+    u"#FC5A8D",
+    u"#CEC8EF",
+    u"#391285",
+    u"#6F2DA8",
+    u"#FF878D",
+    u"#45A27D",
+    u"#FFD0B9",
+    u"#FD5240",
+    u"#DB91EF",
+    u"#44D7A8",
+    u"#4F86F7",
+    u"#84DE02",
+    u"#FFCFF1",
+    u"#614051"
+)
 
 
 def generate_cpta(spec, data):
@@ -146,7 +157,7 @@ def generate_cpta(spec, data):
 
 
 def _generate_trending_traces(in_data, job_name, build_info,
-                              show_trend_line=True, name=u"", color=u""):
+                              name=u"", color=u"", incl_tests=u"MRR"):
     """Generate the trending traces:
      - samples,
      - outliers, regress, progress
@@ -155,19 +166,22 @@ def _generate_trending_traces(in_data, job_name, build_info,
     :param in_data: Full data set.
     :param job_name: The name of job which generated the data.
     :param build_info: Information about the builds.
-    :param show_trend_line: Show moving median (trending plot).
     :param name: Name of the plot
     :param color: Name of the color for the plot.
+    :param incl_tests: Included tests, accepted values: MRR, NDR, PDR
     :type in_data: OrderedDict
     :type job_name: str
     :type build_info: dict
-    :type show_trend_line: bool
     :type name: str
     :type color: str
+    :type incl_tests: str
     :returns: Generated traces (list) and the evaluated result.
     :rtype: tuple(traces, result)
     """
 
+    if incl_tests not in (u"MRR", u"NDR", u"PDR"):
+        return list(), None
+
     data_x = list(in_data.keys())
     data_y_pps = list()
     data_y_mpps = list()
@@ -183,29 +197,37 @@ def _generate_trending_traces(in_data, job_name, build_info,
         str_key = str(key)
         date = build_info[job_name][str_key][0]
         hover_str = (u"date: {date}<br>"
-                     u"value [Mpps]: {value:.3f}<br>"
-                     u"stdev [Mpps]: {stdev:.3f}<br>"
+                     u"{property} [Mpps]: {value:.3f}<br>"
+                     u"<stdev>"
                      u"{sut}-ref: {build}<br>"
-                     u"csit-ref: mrr-{period}-build-{build_nr}<br>"
+                     u"csit-ref: {test}-{period}-build-{build_nr}<br>"
                      u"testbed: {testbed}")
+        if incl_tests == u"MRR":
+            hover_str = hover_str.replace(
+                u"<stdev>", f"stdev [Mpps]: {data_y_stdev[index]:.3f}<br>"
+            )
+        else:
+            hover_str = hover_str.replace(u"<stdev>", u"")
         if u"dpdk" in job_name:
             hover_text.append(hover_str.format(
                 date=date,
+                property=u"average" if incl_tests == u"MRR" else u"throughput",
                 value=data_y_mpps[index],
-                stdev=data_y_stdev[index],
                 sut=u"dpdk",
                 build=build_info[job_name][str_key][1].rsplit(u'~', 1)[0],
+                test=incl_tests.lower(),
                 period=u"weekly",
                 build_nr=str_key,
                 testbed=build_info[job_name][str_key][2]))
         elif u"vpp" in job_name:
             hover_text.append(hover_str.format(
                 date=date,
+                property=u"average" if incl_tests == u"MRR" else u"throughput",
                 value=data_y_mpps[index],
-                stdev=data_y_stdev[index],
                 sut=u"vpp",
                 build=build_info[job_name][str_key][1].rsplit(u'~', 1)[0],
-                period=u"daily",
+                test=incl_tests.lower(),
+                period=u"daily" if incl_tests == u"MRR" else u"weekly",
                 build_nr=str_key,
                 testbed=build_info[job_name][str_key][2]))
 
@@ -216,8 +238,9 @@ def _generate_trending_traces(in_data, job_name, build_info,
     for key, value in zip(xaxis, data_y_pps):
         data_pd[key] = value
 
-    anomaly_classification, avgs_pps = classify_anomalies(data_pd)
+    anomaly_classification, avgs_pps, stdevs_pps = classify_anomalies(data_pd)
     avgs_mpps = [avg_pps / 1e6 for avg_pps in avgs_pps]
+    stdevs_mpps = [stdev_pps / 1e6 for stdev_pps in stdevs_pps]
 
     anomalies = OrderedDict()
     anomalies_colors = list()
@@ -258,23 +281,30 @@ def _generate_trending_traces(in_data, job_name, build_info,
     )
     traces = [trace_samples, ]
 
-    if show_trend_line:
-        trace_trend = plgo.Scatter(
-            x=xaxis,
-            y=avgs_mpps,
-            mode=u"lines",
-            line={
-                u"shape": u"linear",
-                u"width": 1,
-                u"color": color,
-            },
-            showlegend=False,
-            legendgroup=name,
-            name=f"{name}",
-            text=[f"trend [Mpps]: {avg:.3f}" for avg in avgs_mpps],
-            hoverinfo=u"text+name"
+    trend_hover_text = list()
+    for idx in range(len(data_x)):
+        trend_hover_str = (
+            f"trend [Mpps]: {avgs_mpps[idx]:.3f}<br>"
+            f"stdev [Mpps]: {stdevs_mpps[idx]:.3f}"
         )
-        traces.append(trace_trend)
+        trend_hover_text.append(trend_hover_str)
+
+    trace_trend = plgo.Scatter(
+        x=xaxis,
+        y=avgs_mpps,
+        mode=u"lines",
+        line={
+            u"shape": u"linear",
+            u"width": 1,
+            u"color": color,
+        },
+        showlegend=False,
+        legendgroup=name,
+        name=f"{name}",
+        text=trend_hover_text,
+        hoverinfo=u"text+name"
+    )
+    traces.append(trace_trend)
 
     trace_anomalies = plgo.Scatter(
         x=list(anomalies.keys()),
@@ -347,6 +377,8 @@ def _generate_all_charts(spec, input_data):
 
         logging.info(f"  Generating the chart {graph.get(u'title', u'')} ...")
 
+        incl_tests = graph.get(u"include-tests", u"MRR")
+
         job_name = list(graph[u"data"].keys())[0]
 
         csv_tbl = list()
@@ -354,20 +386,20 @@ def _generate_all_charts(spec, input_data):
 
         # Transform the data
         logging.info(
-             f"    Creating the data set for the {graph.get(u'type', u'')} "
-             f"{graph.get(u'title', u'')}."
+            f"    Creating the data set for the {graph.get(u'type', u'')} "
+            f"{graph.get(u'title', u'')}."
         )
 
         if graph.get(u"include", None):
             data = input_data.filter_tests_by_name(
                 graph,
-                params=[u"type", u"result", u"tags"],
+                params=[u"type", u"result", u"throughput", u"tags"],
                 continue_on_error=True
             )
         else:
             data = input_data.filter_data(
                 graph,
-                params=[u"type", u"result", u"tags"],
+                params=[u"type", u"result", u"throughput", u"tags"],
                 continue_on_error=True)
 
         if data is None or data.empty:
@@ -384,9 +416,20 @@ def _generate_all_charts(spec, input_data):
                     if chart_data.get(test_name, None) is None:
                         chart_data[test_name] = OrderedDict()
                     try:
+                        if incl_tests == u"MRR":
+                            rate = test[u"result"][u"receive-rate"]
+                            stdev = test[u"result"][u"receive-stdev"]
+                        elif incl_tests == u"NDR":
+                            rate = test[u"throughput"][u"NDR"][u"LOWER"]
+                            stdev = float(u"nan")
+                        elif incl_tests == u"PDR":
+                            rate = test[u"throughput"][u"PDR"][u"LOWER"]
+                            stdev = float(u"nan")
+                        else:
+                            continue
                         chart_data[test_name][int(index)] = {
-                            u"receive-rate": test[u"result"][u"receive-rate"],
-                            u"receive-stdev": test[u"result"][u"receive-stdev"]
+                            u"receive-rate": rate,
+                            u"receive-stdev": stdev
                         }
                         chart_tags[test_name] = test.get(u"tags", None)
                     except (KeyError, TypeError):
@@ -427,7 +470,9 @@ def _generate_all_charts(spec, input_data):
                                 build_info=build_info,
                                 name=u'-'.join(tst_name.split(u'.')[-1].
                                                split(u'-')[2:-1]),
-                                color=COLORS[index])
+                                color=COLORS[index],
+                                incl_tests=incl_tests
+                            )
                         except IndexError:
                             logging.error(f"Out of colors: index: "
                                           f"{index}, test: {tst_name}")
@@ -451,7 +496,9 @@ def _generate_all_charts(spec, input_data):
                         build_info=build_info,
                         name=u'-'.join(
                             tst_name.split(u'.')[-1].split(u'-')[2:-1]),
-                        color=COLORS[index])
+                        color=COLORS[index],
+                        incl_tests=incl_tests
+                    )
                 except IndexError:
                     logging.error(
                         f"Out of colors: index: {index}, test: {tst_name}"