7 from optparse import OptionParser
9 fmttext = '%(value)7.2f (%(percentual)+6.1f%%)'
10 fmthtml = '%(value)7.2f <span style="color: #666; width: 55pt; display: inline-block; text-align: right; text-shadow: #999 1px 1px 3px;">(%(percentual)+0.1f%%)</span>'
13 parser = OptionParser(usage="%prog [options] <reference> <file2> .. <fileN>",
15 Generate reports comparing two or more outputs of expedite.
17 Just run expedite and save output to a file and then feed them to this
18 program. The first file is used as base for comparison and other files
19 will print relative improvements.
21 parser.add_option("-e", "--accepted-error",
22 help=("maximum error to accept as percentage 0.0-1.0. "
23 "[default=%default]"),
24 action="store", type="float", default=0.05)
25 parser.add_option("-r", "--report",
26 help=("kind of report to use. One of text or html. "
27 "[default=%default]"),
28 action="store", type="choice", default="text",
29 choices=["text", "html"])
30 parser.add_option("-F", "--format",
31 help=("format to use as python format string, "
32 "valid keys are: value and percentual. "
33 "[defaults: html=\"%s\", text=\"%s\"]" %
35 action="store", type="str", default=None)
36 parser.add_option("-C", "--no-color", dest="color",
37 help="do not use color in reports.",
38 action="store_false", default=True)
40 options, files = parser.parse_args()
42 raise SystemExit("need at least 2 files to compare")
44 if options.format is None:
45 if options.report == "html":
46 options.format = fmthtml
48 options.format = fmttext
58 for row in csv.reader(open(f)):
63 max_test_name = max(len(t), max_test_name)
66 test_name_fmt = "%%%ds:" % max_test_name
68 fmtsize = len(options.format % {"value": 12345.67, "percentual": 1234.56})
69 hdrfmt = "%%%d.%ds" % (fmtsize, fmtsize)
71 print test_name_fmt % "\\",
72 print "%7.7s" % (files[0][-7:],),
74 n, e = os.path.splitext(f)
75 print hdrfmt % n[-fmtsize:],
78 if options.color and os.environ.get("TERM", "") in (
79 "xterm", "xterm-color", "rxvt", "rxvt-unicode", "screen",
80 "Eterm", "aterm", "gnome", "interix"):
81 color_good = "\033[1;32m"
82 color_bad = "\033[1;31m"
83 color_equal = "\033[1;30m"
84 color_reset = "\033[0m"
93 print test_name_fmt % test,
94 ref_val = data[ref_f][test]
95 print "%7.2f" % ref_val,
103 percent = (val - ref_val) / ref_val
104 if percent < -options.accepted_error:
106 elif percent > options.accepted_error:
111 fmt = options.format % {"value": val, "percentual": percent * 100}
112 if len(fmt) < fmtsize:
114 print "%s%s%s" % (c, fmt, color_reset),
125 fnames = [os.path.basename(f) for f in files]
127 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
128 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
130 <html xmlns="http://www.w3.org/1999/xhtml">
132 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
133 <title>expedite comparison sheet: %(files)s</title>
135 <style type="text/css">
138 border: 1px solid black;
139 border-collapse: collapse;
143 border-bottom: 1px solid black;
147 border-top: 1px solid black;
150 td.value, td.value-reference, td.value-missing, td.value-good, td.value-bad, td.value-equal
152 font-family: courier, monospaced;
155 border-left: 1px solid black;
156 border-bottom: 1px dashed #ccc;
158 td.test-name, thead tr td { text-align: right; }\
162 td.value-good { background-color: #aaffaa; }
163 td.value-bad { background-color: #ffaaaa; }
164 td.value-missing { background-color: #ffffaa; }
165 td.test-name, thead tr td
168 background-color: #d9d9d9;
169 border-bottom: 1px dashed #ccc;
176 <p>Comparison sheet for %(files)s, created at %(date)s.</p>
181 """ % {"files": ", ".join(fnames),
182 "date": time.asctime(),
196 ref_val = data[ref_f][test]
197 if "EVAS SPEED" in test.upper():
198 extra_cls = ' class="overall-results"'
204 <td class="test-name">%s</td>
205 <td class="value-reference">%7.2f</td>\
206 """ % (extra_cls, test, ref_val)
213 <td class="value-missing">-?????-</td>\
217 percent = (val - ref_val) / ref_val
218 if percent < -options.accepted_error:
220 elif percent > options.accepted_error:
225 v = options.format % {"value": val, "percentual": percent * 100}
228 <td class="value-%s">%s</td>\
245 if options.report == "text":
247 elif options.report == "html":