X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fpresentation%2Fgenerator_tables.py;h=afd8390c919653be2e13410b5a9f23605c7d4c44;hp=0ff4de6c0893e7b9eba7ab0d8763bcf800297c30;hb=2b8547bc50fd06ea936f096794b8c2a5e09c5f8b;hpb=a2176b15e68b22277cbcd959de67c8fd169fec78 diff --git a/resources/tools/presentation/generator_tables.py b/resources/tools/presentation/generator_tables.py index 0ff4de6c08..afd8390c91 100644 --- a/resources/tools/presentation/generator_tables.py +++ b/resources/tools/presentation/generator_tables.py @@ -108,6 +108,66 @@ def table_details(table, input_data): logging.info(" Done.") +def table_merged_details(table, input_data): + """Generate the table(s) with algorithm: table_merged_details + 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(" Generating the table {0} ...". + format(table.get("title", ""))) + + # Transform the data + data = input_data.filter_data(table) + data = input_data.merge_data(data) + + suites = input_data.filter_data(table, data_set="suites") + suites = input_data.merge_data(suites) + + # Prepare the header of the tables + header = list() + for column in table["columns"]: + header.append('"{0}"'.format(str(column["title"]).replace('"', '""'))) + + for _, suite in suites.iteritems(): + # Generate data + suite_name = suite["name"] + table_lst = list() + for test in data.keys(): + if data[test]["parent"] in suite_name: + row_lst = list() + for column in table["columns"]: + try: + col_data = str(data[test][column["data"]. + split(" ")[1]]).replace('"', '""') + if column["data"].split(" ")[1] in ("vat-history", + "show-run"): + col_data = replace(col_data, " |br| ", "", + maxreplace=1) + col_data = " |prein| {0} |preout| ".\ + format(col_data[:-5]) + row_lst.append('"{0}"'.format(col_data)) + except KeyError: + row_lst.append("No data") + table_lst.append(row_lst) + + # Write the data to file + if table_lst: + file_name = "{0}_{1}{2}".format(table["output-file"], suite_name, + table["output-file-ext"]) + logging.info(" Writing file: '{}'".format(file_name)) + with open(file_name, "w") as file_handler: + file_handler.write(",".join(header) + "\n") + for item in table_lst: + file_handler.write(",".join(item) + "\n") + + logging.info(" Done.") + + def table_performance_improvements(table, input_data): """Generate the table(s) with algorithm: table_performance_improvements specified in the specification file. @@ -134,6 +194,8 @@ def table_performance_improvements(table, input_data): line_lst.append(item["data"]) elif isinstance(item["data"], float): line_lst.append("{:.1f}".format(item["data"])) + elif item["data"] is None: + line_lst.append("") file_handler.write(",".join(line_lst) + "\n") logging.info(" Generating the table {0} ...". @@ -175,26 +237,35 @@ def table_performance_improvements(table, input_data): val = tmpl_item[int(args[0])] tbl_item.append({"data": val}) elif cmd == "data": - job = args[0] - operation = args[1] + jobs = args[0:-1] + operation = args[-1] data_lst = list() - for build in data[job]: - try: - data_lst.append(float(build[tmpl_item[0]]["throughput"] - ["value"]) / 1000000) - except (KeyError, TypeError): - # No data, ignore - pass + for job in jobs: + for build in data[job]: + try: + data_lst.append(float(build[tmpl_item[0]] + ["throughput"]["value"])) + except (KeyError, TypeError): + # No data, ignore + continue if data_lst: - tbl_item.append({"data": eval(operation)(data_lst)}) + tbl_item.append({"data": (eval(operation)(data_lst)) / + 1000000}) + else: + tbl_item.append({"data": None}) elif cmd == "operation": operation = args[0] - nr1 = tbl_item[int(args[1])]["data"] - nr2 = tbl_item[int(args[2])]["data"] - if nr1 and nr2: - tbl_item.append({"data": eval(operation)(nr1, nr2)}) - else: + try: + nr1 = float(tbl_item[int(args[1])]["data"]) + nr2 = float(tbl_item[int(args[2])]["data"]) + if nr1 and nr2: + tbl_item.append({"data": eval(operation)(nr1, nr2)}) + else: + tbl_item.append({"data": None}) + except (IndexError, ValueError, TypeError): + logging.error("No data for {0}".format(tbl_item[1]["data"])) tbl_item.append({"data": None}) + continue else: logging.error("Not supported command {0}. Skipping the table.". format(cmd)) @@ -217,21 +288,25 @@ def table_performance_improvements(table, input_data): with open(file_name, "w") as file_handler: file_handler.write(",".join(header) + "\n") for item in tbl_lst: + if isinstance(item[-1]["data"], float): + rel_change = round(item[-1]["data"], 1) + else: + rel_change = item[-1]["data"] if "ndr_top" in file_name \ and "ndr" in item[1]["data"] \ - and item[-1]["data"] >= 10: + and rel_change >= 10.0: _write_line_to_file(file_handler, item) elif "pdr_top" in file_name \ and "pdr" in item[1]["data"] \ - and item[-1]["data"] >= 10: + and rel_change >= 10.0: _write_line_to_file(file_handler, item) elif "ndr_low" in file_name \ and "ndr" in item[1]["data"] \ - and item[-1]["data"] < 10: + and rel_change < 10.0: _write_line_to_file(file_handler, item) elif "pdr_low" in file_name \ and "pdr" in item[1]["data"] \ - and item[-1]["data"] < 10: + and rel_change < 10.0: _write_line_to_file(file_handler, item) logging.info(" Done.")