aboutsummaryrefslogtreecommitdiffstats
path: root/resources/tools/presentation/generator_tables.py
diff options
context:
space:
mode:
Diffstat (limited to 'resources/tools/presentation/generator_tables.py')
-rw-r--r--resources/tools/presentation/generator_tables.py101
1 files changed, 60 insertions, 41 deletions
diff --git a/resources/tools/presentation/generator_tables.py b/resources/tools/presentation/generator_tables.py
index 4299efdb82..af7d23f608 100644
--- a/resources/tools/presentation/generator_tables.py
+++ b/resources/tools/presentation/generator_tables.py
@@ -1581,6 +1581,7 @@ def table_comparison(table, input_data):
tbl_lst.append(row)
comparisons = table.get(u"comparisons", None)
+ rcas = list()
if comparisons and isinstance(comparisons, list):
for idx, comp in enumerate(comparisons):
try:
@@ -1590,13 +1591,33 @@ def table_comparison(table, input_data):
logging.warning(u"Comparison: No references defined! Skipping.")
comparisons.pop(idx)
continue
- if not (0 < col_ref <= len(cols) and
- 0 < col_cmp <= len(cols)) or \
- col_ref == col_cmp:
+ if not (0 < col_ref <= len(cols) and 0 < col_cmp <= len(cols) or
+ col_ref == col_cmp):
logging.warning(f"Wrong values of reference={col_ref} "
f"and/or compare={col_cmp}. Skipping.")
comparisons.pop(idx)
continue
+ rca_file_name = comp.get(u"rca-file", None)
+ if rca_file_name:
+ try:
+ with open(rca_file_name, u"r") as file_handler:
+ rcas.append(
+ {
+ u"title": f"RCA{idx + 1}",
+ u"data": load(file_handler, Loader=FullLoader)
+ }
+ )
+ except (YAMLError, IOError) as err:
+ logging.warning(
+ f"The RCA file {rca_file_name} does not exist or "
+ f"it is corrupted!"
+ )
+ logging.debug(repr(err))
+ rcas.append(None)
+ else:
+ rcas.append(None)
+ else:
+ comparisons = None
tbl_cmp_lst = list()
if comparisons:
@@ -1619,11 +1640,10 @@ def table_comparison(table, input_data):
)
if delta is None:
break
- else:
- new_row.append({
- u"mean": delta * 1e6,
- u"stdev": d_stdev * 1e6
- })
+ new_row.append({
+ u"mean": delta * 1e6,
+ u"stdev": d_stdev * 1e6
+ })
else:
break
else:
@@ -1635,25 +1655,6 @@ def table_comparison(table, input_data):
except TypeError as err:
logging.warning(f"Empty data element in table\n{tbl_cmp_lst}\n{err}")
- rcas = list()
- rca_in = table.get(u"rca", None)
- if rca_in and isinstance(rca_in, list):
- for idx, itm in enumerate(rca_in):
- try:
- with open(itm.get(u"data", u""), u"r") as rca_file:
- rcas.append(
- {
- u"title": itm.get(u"title", f"RCA{idx}"),
- u"data": load(rca_file, Loader=FullLoader)
- }
- )
- except (YAMLError, IOError) as err:
- logging.warning(
- f"The RCA file {itm.get(u'data', u'')} does not exist or "
- f"it is corrupted!"
- )
- logging.debug(repr(err))
-
tbl_for_csv = list()
for line in tbl_cmp_lst:
row = [line[0], ]
@@ -1667,6 +1668,8 @@ def table_comparison(table, input_data):
row.append(round(float(itm[u'mean']) / 1e6, 3))
row.append(round(float(itm[u'stdev']) / 1e6, 3))
for rca in rcas:
+ if rca is None:
+ continue
rca_nr = rca[u"data"].get(row[0], u"-")
row.append(f"[{rca_nr}]" if rca_nr != u"-" else u"-")
tbl_for_csv.append(row)
@@ -1682,7 +1685,9 @@ def table_comparison(table, input_data):
header_csv.append(
f"Stdev({comp.get(u'title', u'')})"
)
- header_csv.extend([rca[u"title"] for rca in rcas])
+ for rca in rcas:
+ if rca:
+ header_csv.append(rca[u"title"])
legend_lst = table.get(u"legend", None)
if legend_lst is None:
@@ -1691,10 +1696,11 @@ def table_comparison(table, input_data):
legend = u"\n" + u"\n".join(legend_lst) + u"\n"
footnote = u""
- if rcas:
- footnote += u"\nRCA:\n"
+ if rcas and any(rcas):
+ footnote += u"\nRoot Cause Analysis:\n"
for rca in rcas:
- footnote += rca[u"data"].get(u"footnote", u"")
+ if rca:
+ footnote += f"{rca[u'data'].get(u'footnote', u'')}\n"
csv_file_name = f"{table[u'output-file']}-csv.csv"
with open(csv_file_name, u"wt", encoding='utf-8') as file_handler:
@@ -1740,6 +1746,10 @@ def table_comparison(table, input_data):
tbl_tmp.append(row)
+ header = [u"Test Case", ]
+ header.extend([col[u"title"] for col in cols])
+ header.extend([comp.get(u"title", u"") for comp in comparisons])
+
tbl_final = list()
for line in tbl_tmp:
row = [line[0], ]
@@ -1750,18 +1760,27 @@ def table_comparison(table, input_data):
itm_lst = itm.rsplit(u"\u00B1", 1)
itm_lst[-1] = \
f"{u' ' * (max_lens[idx] - len(itm_lst[-1]))}{itm_lst[-1]}"
- row.append(u"\u00B1".join(itm_lst))
- for rca in rcas:
- rca_nr = rca[u"data"].get(row[0], u"-")
- row.append(f"[{rca_nr}]" if rca_nr != u"-" else u"-")
-
+ itm_str = u"\u00B1".join(itm_lst)
+
+ if idx >= len(cols):
+ # Diffs
+ rca = rcas[idx - len(cols)]
+ if rca:
+ # Add rcas to diffs
+ rca_nr = rca[u"data"].get(row[0], None)
+ if rca_nr:
+ hdr_len = len(header[idx + 1]) - 1
+ if hdr_len < 19:
+ hdr_len = 19
+ rca_nr = f"[{rca_nr}]"
+ itm_str = (
+ f"{u' ' * (4 - len(rca_nr))}{rca_nr}"
+ f"{u' ' * (hdr_len - 4 - len(itm_str))}"
+ f"{itm_str}"
+ )
+ row.append(itm_str)
tbl_final.append(row)
- header = [u"Test Case", ]
- header.extend([col[u"title"] for col in cols])
- header.extend([comp.get(u"title", u"") for comp in comparisons])
- header.extend([rca[u"title"] for rca in rcas])
-
# Generate csv tables:
csv_file_name = f"{table[u'output-file']}.csv"
logging.info(f" Writing the file {csv_file_name}")