- # Generate tables:
- # All tests in csv:
- tbl_names = ["{0}-ndr-1t1c-full{1}".format(table["output-file"],
- table["output-file-ext"]),
- "{0}-ndr-2t2c-full{1}".format(table["output-file"],
- table["output-file-ext"]),
- "{0}-ndr-4t4c-full{1}".format(table["output-file"],
- table["output-file-ext"]),
- "{0}-pdr-1t1c-full{1}".format(table["output-file"],
- table["output-file-ext"]),
- "{0}-pdr-2t2c-full{1}".format(table["output-file"],
- table["output-file-ext"]),
- "{0}-pdr-4t4c-full{1}".format(table["output-file"],
- table["output-file-ext"])
- ]
- for file_name in tbl_names:
- logging.info(" Writing file: '{}'".format(file_name))
- with open(file_name, "w") as file_handler:
- file_handler.write(header_str)
- for test in tbl_lst:
- if (file_name.split("-")[-3] in test[0] and # NDR vs PDR
- file_name.split("-")[-2] in test[0]): # cores
- test[0] = "-".join(test[0].split("-")[:-1])
- file_handler.write(",".join([str(item) for item in test]) +
- "\n")
-
- # All tests in txt:
- tbl_names_txt = ["{0}-ndr-1t1c-full.txt".format(table["output-file"]),
- "{0}-ndr-2t2c-full.txt".format(table["output-file"]),
- "{0}-ndr-4t4c-full.txt".format(table["output-file"]),
- "{0}-pdr-1t1c-full.txt".format(table["output-file"]),
- "{0}-pdr-2t2c-full.txt".format(table["output-file"]),
- "{0}-pdr-4t4c-full.txt".format(table["output-file"])
- ]
-
- for i, txt_name in enumerate(tbl_names_txt):
- txt_table = None
- logging.info(" Writing file: '{}'".format(txt_name))
- with open(tbl_names[i], 'rb') as csv_file:
- csv_content = csv.reader(csv_file, delimiter=',', quotechar='"')
- for row in csv_content:
- if txt_table is None:
- txt_table = prettytable.PrettyTable(row)
+ try:
+ with open(table[u"input-file"], u'rt') as csv_file:
+ csv_lst = list(csv.reader(csv_file, delimiter=u',', quotechar=u'"'))
+ except KeyError:
+ logging.warning(u"The input file is not defined.")
+ return
+ except csv.Error as err:
+ logging.warning(
+ f"Not possible to process the file {table[u'input-file']}.\n"
+ f"{repr(err)}"
+ )
+ return
+
+ # Table:
+ failed_tests = ET.Element(u"table", attrib=dict(width=u"100%", border=u'0'))
+
+ # Table header:
+ trow = ET.SubElement(failed_tests, u"tr", attrib=dict(bgcolor=u"#7eade7"))
+ for idx, item in enumerate(csv_lst[0]):
+ alignment = u"left" if idx == 0 else u"center"
+ thead = ET.SubElement(trow, u"th", attrib=dict(align=alignment))
+ thead.text = item
+
+ # Rows:
+ colors = (u"#e9f1fb", u"#d4e4f7")
+ for r_idx, row in enumerate(csv_lst[1:]):
+ background = colors[r_idx % 2]
+ trow = ET.SubElement(
+ failed_tests, u"tr", attrib=dict(bgcolor=background)
+ )
+
+ # Columns:
+ for c_idx, item in enumerate(row):
+ tdata = ET.SubElement(
+ trow,
+ u"td",
+ attrib=dict(align=u"left" if c_idx == 0 else u"center")
+ )
+ # Name:
+ if c_idx == 0 and table.get(u"add-links", True):
+ ref = ET.SubElement(
+ tdata,
+ u"a",
+ attrib=dict(
+ href=f"{lnk_dir}"
+ f"{_generate_url(table.get(u'testbed', ''), item)}"
+ f"{lnk_sufix}"
+ )
+ )
+ ref.text = item
+ else:
+ tdata.text = item
+ try:
+ with open(table[u"output-file"], u'w') as html_file:
+ logging.info(f" Writing file: {table[u'output-file']}")
+ html_file.write(u".. raw:: html\n\n\t")
+ html_file.write(str(ET.tostring(failed_tests, encoding=u"unicode")))
+ html_file.write(u"\n\t<p><br><br></p>\n")
+ except KeyError:
+ logging.warning(u"The output file is not defined.")
+ return
+
+
+def table_comparison(table, input_data):
+ """Generate the table(s) with algorithm: table_comparison
+ specified in the specification file.
+
+ :param table: Table to generate.
+ :param input_data: Data to process.
+ :type table: pandas.Series
+ :type input_data: InputData
+ """
+ logging.info(f" Generating the table {table.get(u'title', u'')} ...")
+
+ # Transform the data
+ logging.info(
+ f" Creating the data set for the {table.get(u'type', u'')} "
+ f"{table.get(u'title', u'')}."
+ )
+
+ columns = table.get(u"columns", None)
+ if not columns:
+ logging.error(
+ f"No columns specified for {table.get(u'title', u'')}. Skipping."
+ )
+ return
+
+ cols = list()
+ for idx, col in enumerate(columns):
+ if col.get(u"data-set", None) is None:
+ logging.warning(f"No data for column {col.get(u'title', u'')}")
+ continue
+ tag = col.get(u"tag", None)
+ data = input_data.filter_data(
+ table,
+ params=[u"throughput", u"result", u"name", u"parent", u"tags"],
+ data=col[u"data-set"],
+ continue_on_error=True
+ )
+ col_data = {
+ u"title": col.get(u"title", f"Column{idx}"),
+ u"data": dict()
+ }
+ for builds in data.values:
+ for build in builds:
+ for tst_name, tst_data in build.items():
+ if tag and tag not in tst_data[u"tags"]:
+ continue
+ tst_name_mod = \
+ _tpc_modify_test_name(tst_name, ignore_nic=True).\
+ replace(u"2n1l-", u"")
+ if col_data[u"data"].get(tst_name_mod, None) is None:
+ name = tst_data[u'name'].rsplit(u'-', 1)[0]
+ if u"across testbeds" in table[u"title"].lower() or \
+ u"across topologies" in table[u"title"].lower():
+ name = _tpc_modify_displayed_test_name(name)
+ col_data[u"data"][tst_name_mod] = {
+ u"name": name,
+ u"replace": True,
+ u"data": list(),
+ u"mean": None,
+ u"stdev": None
+ }
+ _tpc_insert_data(
+ target=col_data[u"data"][tst_name_mod],
+ src=tst_data,
+ include_tests=table[u"include-tests"]
+ )
+
+ replacement = col.get(u"data-replacement", None)
+ if replacement:
+ rpl_data = input_data.filter_data(
+ table,
+ params=[u"throughput", u"result", u"name", u"parent", u"tags"],
+ data=replacement,
+ continue_on_error=True
+ )
+ for builds in rpl_data.values:
+ for build in builds:
+ for tst_name, tst_data in build.items():
+ if tag and tag not in tst_data[u"tags"]:
+ continue
+ tst_name_mod = \
+ _tpc_modify_test_name(tst_name, ignore_nic=True).\
+ replace(u"2n1l-", u"")
+ if col_data[u"data"].get(tst_name_mod, None) is None:
+ name = tst_data[u'name'].rsplit(u'-', 1)[0]
+ if u"across testbeds" in table[u"title"].lower() \
+ or u"across topologies" in \
+ table[u"title"].lower():
+ name = _tpc_modify_displayed_test_name(name)
+ col_data[u"data"][tst_name_mod] = {
+ u"name": name,
+ u"replace": False,
+ u"data": list(),
+ u"mean": None,
+ u"stdev": None
+ }
+ if col_data[u"data"][tst_name_mod][u"replace"]:
+ col_data[u"data"][tst_name_mod][u"replace"] = False
+ col_data[u"data"][tst_name_mod][u"data"] = list()
+ _tpc_insert_data(
+ target=col_data[u"data"][tst_name_mod],
+ src=tst_data,
+ include_tests=table[u"include-tests"]
+ )
+
+ if table[u"include-tests"] in (u"NDR", u"PDR"):
+ for tst_name, tst_data in col_data[u"data"].items():
+ if tst_data[u"data"]:
+ tst_data[u"mean"] = mean(tst_data[u"data"])
+ tst_data[u"stdev"] = stdev(tst_data[u"data"])
+
+ cols.append(col_data)
+
+ tbl_dict = dict()
+ for col in cols:
+ for tst_name, tst_data in col[u"data"].items():
+ if tbl_dict.get(tst_name, None) is None:
+ tbl_dict[tst_name] = {
+ "name": tst_data[u"name"]
+ }
+ tbl_dict[tst_name][col[u"title"]] = {
+ u"mean": tst_data[u"mean"],
+ u"stdev": tst_data[u"stdev"]
+ }
+
+ if not tbl_dict:
+ logging.warning(f"No data for table {table.get(u'title', u'')}!")
+ return
+
+ tbl_lst = list()
+ for tst_data in tbl_dict.values():
+ row = [tst_data[u"name"], ]
+ for col in cols:
+ row.append(tst_data.get(col[u"title"], None))
+ 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:
+ col_ref = int(comp[u"reference"])
+ col_cmp = int(comp[u"compare"])
+ except KeyError:
+ 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):
+ 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:
+ for row in tbl_lst:
+ new_row = deepcopy(row)
+ for comp in comparisons:
+ ref_itm = row[int(comp[u"reference"])]
+ if ref_itm is None and \
+ comp.get(u"reference-alt", None) is not None:
+ ref_itm = row[int(comp[u"reference-alt"])]
+ cmp_itm = row[int(comp[u"compare"])]
+ if ref_itm is not None and cmp_itm is not None and \
+ ref_itm[u"mean"] is not None and \
+ cmp_itm[u"mean"] is not None and \
+ ref_itm[u"stdev"] is not None and \
+ cmp_itm[u"stdev"] is not None:
+ delta, d_stdev = relative_change_stdev(
+ ref_itm[u"mean"], cmp_itm[u"mean"],
+ ref_itm[u"stdev"], cmp_itm[u"stdev"]
+ )
+ if delta is None:
+ break
+ new_row.append({
+ u"mean": delta * 1e6,
+ u"stdev": d_stdev * 1e6
+ })