Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import sys
- tstyle = 'border="1"'
- def table_header(cols):
- def th(col):
- if col == "":
- col = '(empty)'
- return "<th>{}</th>".format(col.replace(" ", "-"))
- main_part = "".join(th(col) for col in cols)
- return "<tr><th>test</th>{}</tr>".format(main_part)
- def correctness_result(test, cols):
- if not test:
- return ""
- results = test["results"]
- def td(col):
- ans = results[col]
- color = "red"
- if ans == "<OK>":
- color = "green"
- ans = ans.replace("<", "<").replace(">", ">").replace(" ", "-")
- if ans == "":
- ans = '(empty)'
- return "<td style=\"color:{}\">{}</td>".format(color, ans)
- preface = "<td><a href=\"{}\">{}</a></td>".format(test["url"], test["name"])
- main_line = "".join(td(col) for col in cols)
- return "<tr>{}{}</tr>".format(preface, main_line)
- def output_correctness(all_tests):
- cols = list(key for key in all_tests[0]["results"].keys() if key != "dummy")
- header = table_header(cols)
- body = "\n ".join(correctness_result(test, cols) for test in all_tests)
- return "<table {}><thead>\n{}\n</thead><tbody>\n{}\n</tbody></table>\n\n".format(tstyle, header, body)
- def performance_result(test, cols):
- if not test:
- return ""
- results = test["results"]
- def td(col):
- if col == "dummy":
- return ""
- ans = results[col]
- return "<td>{:.9f}</td>".format(ans)
- preface = "<td><a href=\"{}\">{}</a></td>".format(test["url"], test["name"])
- main_line = "".join(td(col) for col in cols)
- return "<tr>{}{}</tr>".format(preface, main_line)
- def output_performance(all_tests):
- cols = list(key for key in all_tests[0]["results"].keys() if key != "dummy")
- header = table_header(cols)
- body = "\n ".join(performance_result(test, cols) for test in all_tests)
- return "<table {}><thead>\n{}\n</thead><tbody>\n{}\n</tbody></table>\n\n".format(tstyle, header, body)
- def main():
- results = json.load(sys.stdin)
- print(output_correctness(results["correctness"]))
- print(output_performance(results["timing"]))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement