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", "") == "xterm":
79 color_good = "\033[1;32m"
80 color_bad = "\033[1;31m"
81 color_equal = "\033[1;30m"
82 color_reset = "\033[0m"
91 print test_name_fmt % test,
92 ref_val = data[ref_f][test]
93 print "%7.2f" % ref_val,
101 percent = (val - ref_val) / ref_val
102 if percent < -options.accepted_error:
104 elif percent > options.accepted_error:
109 fmt = options.format % {"value": val, "percentual": percent * 100}
110 if len(fmt) < fmtsize:
112 print "%s%s%s" % (c, fmt, color_reset),
123 fnames = [os.path.basename(f) for f in files]
125 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
126 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
128 <html xmlns="http://www.w3.org/1999/xhtml">
130 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
131 <title>expedite comparison sheet: %(files)s</title>
133 <style type="text/css">
136 border: 1px solid black;
137 border-collapse: collapse;
141 border-bottom: 1px solid black;
145 border-top: 1px solid black;
148 td.value, td.value-reference, td.value-missing, td.value-good, td.value-bad, td.value-equal
150 font-family: courier, monospaced;
153 border-left: 1px solid black;
154 border-bottom: 1px dashed #ccc;
156 td.test-name, thead tr td { text-align: right; }\
160 td.value-good { background-color: #aaffaa; }
161 td.value-bad { background-color: #ffaaaa; }
162 td.value-missing { background-color: #ffffaa; }
163 td.test-name, thead tr td
166 background-color: #d9d9d9;
167 border-bottom: 1px dashed #ccc;
174 <p>Comparison sheet for %(files)s, created at %(date)s.</p>
179 """ % {"files": ", ".join(fnames),
180 "date": time.asctime(),
194 ref_val = data[ref_f][test]
195 if "EVAS SPEED" in test.upper():
196 extra_cls = ' class="overall-results"'
202 <td class="test-name">%s</td>
203 <td class="value-reference">%7.2f</td>\
204 """ % (extra_cls, test, ref_val)
211 <td class="value-missing">-?????-</td>\
215 percent = (val - ref_val) / ref_val
216 if percent < -options.accepted_error:
218 elif percent > options.accepted_error:
223 v = options.format % {"value": val, "percentual": percent * 100}
226 <td class="value-%s">%s</td>\
243 if options.report == "text":
245 elif options.report == "html":