aboutsummaryrefslogtreecommitdiff
path: root/crosperf/results_report_templates.py
diff options
context:
space:
mode:
Diffstat (limited to 'crosperf/results_report_templates.py')
-rw-r--r--crosperf/results_report_templates.py129
1 files changed, 75 insertions, 54 deletions
diff --git a/crosperf/results_report_templates.py b/crosperf/results_report_templates.py
index ea411e21..3ef9e74a 100644
--- a/crosperf/results_report_templates.py
+++ b/crosperf/results_report_templates.py
@@ -1,26 +1,28 @@
# -*- coding: utf-8 -*-
-# Copyright 2016 The Chromium OS Authors. All rights reserved.
+# Copyright 2016 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Text templates used by various parts of results_report."""
-from __future__ import print_function
import html
from string import Template
-_TabMenuTemplate = Template("""
+
+_TabMenuTemplate = Template(
+ """
<div class='tab-menu'>
<a href="javascript:switchTab('$table_name', 'html')">HTML</a>
<a href="javascript:switchTab('$table_name', 'text')">Text</a>
<a href="javascript:switchTab('$table_name', 'tsv')">TSV</a>
-</div>""")
+</div>"""
+)
def _GetTabMenuHTML(table_name):
- # N.B. cgi.escape does some very basic HTML escaping. Nothing more.
- escaped = html.escape(table_name)
- return _TabMenuTemplate.substitute(table_name=escaped)
+ # N.B. cgi.escape does some very basic HTML escaping. Nothing more.
+ escaped = html.escape(table_name)
+ return _TabMenuTemplate.substitute(table_name=escaped)
_ExperimentFileHTML = """
@@ -33,12 +35,15 @@ _ExperimentFileHTML = """
def _GetExperimentFileHTML(experiment_file_text):
- if not experiment_file_text:
- return ''
- return _ExperimentFileHTML % (html.escape(experiment_file_text, quote=False),)
+ if not experiment_file_text:
+ return ""
+ return _ExperimentFileHTML % (
+ html.escape(experiment_file_text, quote=False),
+ )
-_ResultsSectionHTML = Template("""
+_ResultsSectionHTML = Template(
+ """
<div class='results-section'>
<div class='results-section-title'>$sect_name</div>
<div class='results-section-content'>
@@ -48,22 +53,25 @@ _ResultsSectionHTML = Template("""
</div>
$tab_menu
</div>
-""")
+"""
+)
def _GetResultsSectionHTML(print_table, table_name, data):
- first_word = table_name.strip().split()[0]
- short_name = first_word.lower()
- return _ResultsSectionHTML.substitute(
- sect_name=table_name,
- html_table=print_table(data, 'HTML'),
- text_table=print_table(data, 'PLAIN'),
- tsv_table=print_table(data, 'TSV'),
- tab_menu=_GetTabMenuHTML(short_name),
- short_name=short_name)
-
-
-_MainHTML = Template("""
+ first_word = table_name.strip().split()[0]
+ short_name = first_word.lower()
+ return _ResultsSectionHTML.substitute(
+ sect_name=table_name,
+ html_table=print_table(data, "HTML"),
+ text_table=print_table(data, "PLAIN"),
+ tsv_table=print_table(data, "TSV"),
+ tab_menu=_GetTabMenuHTML(short_name),
+ short_name=short_name,
+ )
+
+
+_MainHTML = Template(
+ """
<html>
<head>
<style type="text/css">
@@ -169,37 +177,50 @@ _MainHTML = Template("""
$experiment_file
</body>
</html>
-""")
+"""
+)
# It's a bit ugly that we take some HTML things, and some non-HTML things, but I
# need to balance prettiness with time spent making things pretty.
-def GenerateHTMLPage(perf_table, chart_js, summary_table, print_table,
- chart_divs, full_table, experiment_file):
- """Generates a crosperf HTML page from the given arguments.
-
- print_table is a two-arg function called like: print_table(t, f)
- t is one of [summary_table, print_table, full_table]; it's the table we want
- to format.
- f is one of ['TSV', 'HTML', 'PLAIN']; it's the type of format we want.
- """
- summary_table_html = _GetResultsSectionHTML(print_table, 'Summary Table',
- summary_table)
- if perf_table:
- perf_html = _GetResultsSectionHTML(print_table, 'Perf Table', perf_table)
- perf_init = "switchTab('perf', 'html')"
- else:
- perf_html = ''
- perf_init = ''
-
- full_table_html = _GetResultsSectionHTML(print_table, 'Full Table',
- full_table)
- experiment_file_html = _GetExperimentFileHTML(experiment_file)
- return _MainHTML.substitute(
- perf_init=perf_init,
- chart_js=chart_js,
- summary_table=summary_table_html,
- perf_html=perf_html,
- chart_divs=chart_divs,
- full_table=full_table_html,
- experiment_file=experiment_file_html)
+def GenerateHTMLPage(
+ perf_table,
+ chart_js,
+ summary_table,
+ print_table,
+ chart_divs,
+ full_table,
+ experiment_file,
+):
+ """Generates a crosperf HTML page from the given arguments.
+
+ print_table is a two-arg function called like: print_table(t, f)
+ t is one of [summary_table, print_table, full_table]; it's the table we want
+ to format.
+ f is one of ['TSV', 'HTML', 'PLAIN']; it's the type of format we want.
+ """
+ summary_table_html = _GetResultsSectionHTML(
+ print_table, "Summary Table", summary_table
+ )
+ if perf_table:
+ perf_html = _GetResultsSectionHTML(
+ print_table, "Perf Table", perf_table
+ )
+ perf_init = "switchTab('perf', 'html')"
+ else:
+ perf_html = ""
+ perf_init = ""
+
+ full_table_html = _GetResultsSectionHTML(
+ print_table, "Full Table", full_table
+ )
+ experiment_file_html = _GetExperimentFileHTML(experiment_file)
+ return _MainHTML.substitute(
+ perf_init=perf_init,
+ chart_js=chart_js,
+ summary_table=summary_table_html,
+ perf_html=perf_html,
+ chart_divs=chart_divs,
+ full_table=full_table_html,
+ experiment_file=experiment_file_html,
+ )