Report: Comparison tables
[csit.git] / resources / tools / presentation / generator_tables.py
index afc154a..59affa3 100644 (file)
@@ -483,7 +483,8 @@ def _tpc_sort_table(table):
     return table
 
 
-def _tpc_generate_html_table(header, data, output_file_name):
+def _tpc_generate_html_table(header, data, output_file_name, legend=u"",
+                             footnote=u""):
     """Generate html table from input data with simple sorting possibility.
 
     :param header: Table header.
@@ -493,9 +494,13 @@ def _tpc_generate_html_table(header, data, output_file_name):
         header.
     :param output_file_name: The name (relative or full path) where the
         generated html table is written.
+    :param legend: The legend to display below the table.
+    :param footnote: The footnote to display below the table (and legend).
     :type header: list
     :type data: list of lists
     :type output_file_name: str
+    :type legend: str
+    :type footnote: str
     """
 
     try:
@@ -585,6 +590,26 @@ def _tpc_generate_html_table(header, data, output_file_name):
 
     ploff.plot(fig, show_link=False, auto_open=False, filename=output_file_name)
 
+    # Add legend and footnote:
+    if not (legend or footnote):
+        return
+
+    with open(output_file_name, u"rt") as html_file:
+        html_text = html_file.read()
+    if html_text:
+        try:
+            idx = html_text.rindex(u"</div>")
+        except ValueError:
+            return
+        footnote = (legend + footnote).replace(u'\n', u'<br>')
+        html_text = (
+            html_text[:idx] +
+            f"<div>{footnote}</div>" +
+            html_text[idx:]
+        )
+        with open(output_file_name, u"wt") as html_file:
+            html_file.write(html_text)
+
 
 def table_perf_comparison(table, input_data):
     """Generate the table(s) with algorithm: table_perf_comparison
@@ -635,11 +660,11 @@ def table_perf_comparison(table, input_data):
                 f"{item[u'title']} Avg({table[u'include-tests']}): "
                 f"Mean value of {table[u'include-tests']} [Mpps] computed from "
                 f"a series of runs of the listed tests executed against "
-                f"rls{item[u'title']}.\n"
+                f"{item[u'title']}.\n"
                 f"{item[u'title']} Stdev({table[u'include-tests']}): "
                 f"Standard deviation value of {table[u'include-tests']} [Mpps] "
                 f"computed from a series of runs of the listed tests executed "
-                f"against rls{item[u'title']}.\n"
+                f"against {item[u'title']}.\n"
             )
         header.extend(
             [
@@ -662,22 +687,22 @@ def table_perf_comparison(table, input_data):
             f"Avg({table[u'include-tests']}): "
             f"Mean value of {table[u'include-tests']} [Mpps] computed from a "
             f"series of runs of the listed tests executed against "
-            f"rls{table[u'reference'][u'title']}.\n"
+            f"{table[u'reference'][u'title']}.\n"
             f"{table[u'reference'][u'title']} "
             f"Stdev({table[u'include-tests']}): "
             f"Standard deviation value of {table[u'include-tests']} [Mpps] "
             f"computed from a series of runs of the listed tests executed "
-            f"against rls{table[u'reference'][u'title']}.\n"
+            f"against {table[u'reference'][u'title']}.\n"
             f"{table[u'compare'][u'title']} "
             f"Avg({table[u'include-tests']}): "
             f"Mean value of {table[u'include-tests']} [Mpps] computed from a "
             f"series of runs of the listed tests executed against "
-            f"rls{table[u'compare'][u'title']}.\n"
+            f"{table[u'compare'][u'title']}.\n"
             f"{table[u'compare'][u'title']} "
             f"Stdev({table[u'include-tests']}): "
             f"Standard deviation value of {table[u'include-tests']} [Mpps] "
             f"computed from a series of runs of the listed tests executed "
-            f"against rls{table[u'compare'][u'title']}.\n"
+            f"against {table[u'compare'][u'title']}.\n"
             f"Diff({table[u'reference'][u'title']},"
             f"{table[u'compare'][u'title']}): "
             f"Percentage change calculated for mean values.\n"
@@ -924,17 +949,23 @@ def table_perf_comparison(table, input_data):
     txt_file_name = f"{table[u'output-file']}.txt"
     convert_csv_to_pretty_txt(csv_file, txt_file_name, delimiter=u";")
 
+    footnote = u""
     with open(txt_file_name, u'a') as txt_file:
         txt_file.write(legend)
         if rca_data:
             footnote = rca_data.get(u"footnote", u"")
             if footnote:
-                txt_file.write(u"\n")
                 txt_file.write(footnote)
         txt_file.write(u":END")
 
     # Generate html table:
-    _tpc_generate_html_table(header, tbl_lst, f"{table[u'output-file']}.html")
+    _tpc_generate_html_table(
+        header,
+        tbl_lst,
+        f"{table[u'output-file']}.html",
+        legend=legend,
+        footnote=footnote
+    )
 
 
 def table_perf_comparison_nic(table, input_data):
@@ -986,11 +1017,11 @@ def table_perf_comparison_nic(table, input_data):
                 f"{item[u'title']} Avg({table[u'include-tests']}): "
                 f"Mean value of {table[u'include-tests']} [Mpps] computed from "
                 f"a series of runs of the listed tests executed against "
-                f"rls{item[u'title']}.\n"
+                f"{item[u'title']}.\n"
                 f"{item[u'title']} Stdev({table[u'include-tests']}): "
                 f"Standard deviation value of {table[u'include-tests']} [Mpps] "
                 f"computed from a series of runs of the listed tests executed "
-                f"against rls{item[u'title']}.\n"
+                f"against {item[u'title']}.\n"
             )
         header.extend(
             [
@@ -1013,22 +1044,22 @@ def table_perf_comparison_nic(table, input_data):
             f"Avg({table[u'include-tests']}): "
             f"Mean value of {table[u'include-tests']} [Mpps] computed from a "
             f"series of runs of the listed tests executed against "
-            f"rls{table[u'reference'][u'title']}.\n"
+            f"{table[u'reference'][u'title']}.\n"
             f"{table[u'reference'][u'title']} "
             f"Stdev({table[u'include-tests']}): "
             f"Standard deviation value of {table[u'include-tests']} [Mpps] "
             f"computed from a series of runs of the listed tests executed "
-            f"against rls{table[u'reference'][u'title']}.\n"
+            f"against {table[u'reference'][u'title']}.\n"
             f"{table[u'compare'][u'title']} "
             f"Avg({table[u'include-tests']}): "
             f"Mean value of {table[u'include-tests']} [Mpps] computed from a "
             f"series of runs of the listed tests executed against "
-            f"rls{table[u'compare'][u'title']}.\n"
+            f"{table[u'compare'][u'title']}.\n"
             f"{table[u'compare'][u'title']} "
             f"Stdev({table[u'include-tests']}): "
             f"Standard deviation value of {table[u'include-tests']} [Mpps] "
             f"computed from a series of runs of the listed tests executed "
-            f"against rls{table[u'compare'][u'title']}.\n"
+            f"against {table[u'compare'][u'title']}.\n"
             f"Diff({table[u'reference'][u'title']},"
             f"{table[u'compare'][u'title']}): "
             f"Percentage change calculated for mean values.\n"
@@ -1281,17 +1312,23 @@ def table_perf_comparison_nic(table, input_data):
     txt_file_name = f"{table[u'output-file']}.txt"
     convert_csv_to_pretty_txt(csv_file, txt_file_name, delimiter=u";")
 
+    footnote = u""
     with open(txt_file_name, u'a') as txt_file:
         txt_file.write(legend)
         if rca_data:
             footnote = rca_data.get(u"footnote", u"")
             if footnote:
-                txt_file.write(u"\n")
                 txt_file.write(footnote)
         txt_file.write(u":END")
 
     # Generate html table:
-    _tpc_generate_html_table(header, tbl_lst, f"{table[u'output-file']}.html")
+    _tpc_generate_html_table(
+        header,
+        tbl_lst,
+        f"{table[u'output-file']}.html",
+        legend=legend,
+        footnote=footnote
+    )
 
 
 def table_nics_comparison(table, input_data):
@@ -1456,11 +1493,16 @@ def table_nics_comparison(table, input_data):
                               f"{table[u'output-file']}.txt",
                               delimiter=u";")
 
-    with open(table[u'output-file'], u'a') as txt_file:
+    with open(f"{table[u'output-file']}.txt", u'a') as txt_file:
         txt_file.write(legend)
 
     # Generate html table:
-    _tpc_generate_html_table(header, tbl_lst, f"{table[u'output-file']}.html")
+    _tpc_generate_html_table(
+        header,
+        tbl_lst,
+        f"{table[u'output-file']}.html",
+        legend=legend
+    )
 
 
 def table_soak_vs_ndr(table, input_data):
@@ -1635,7 +1677,12 @@ def table_soak_vs_ndr(table, input_data):
         txt_file.write(legend)
 
     # Generate html table:
-    _tpc_generate_html_table(header, tbl_lst, f"{table[u'output-file']}.html")
+    _tpc_generate_html_table(
+        header,
+        tbl_lst,
+        f"{table[u'output-file']}.html",
+        legend=legend
+    )
 
 
 def table_perf_trending_dash(table, input_data):
@@ -1731,7 +1778,7 @@ def table_perf_trending_dash(table, input_data):
                 continue
             tbl_lst.append(
                 [tbl_dict[tst_name][u"name"],
-                 round(last_avg / 1000000, 2),
+                 round(last_avg / 1e6, 2),
                  rel_change_last,
                  rel_change_long,
                  classification_lst[-win_size:].count(u"regression"),