Skip to content

Commit 91c0b13

Browse files
authored
Merge pull request opencv#9922 from alalek:ts_markdown_table
ts(misc): support tables exporting in markdown format
2 parents 1f214d2 + 9e9881a commit 91c0b13

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

modules/ts/misc/summary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def getSetName(tset, idx, columns, short = True):
3030
exit(0)
3131

3232
parser = OptionParser()
33-
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto")
33+
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html', 'markdown' or 'auto' - default)", metavar="FMT", default="auto")
3434
parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean")
3535
parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms")
3636
parser.add_option("-f", "--filter", dest="filter", help="regex to filter tests", metavar="REGEX", default=None)
@@ -142,7 +142,7 @@ def parseRegressionColumn(s):
142142
getter_score = metrix_table["score"][1] if options.calc_score else None
143143
getter_p = metrix_table[options.metric + "%"][1] if options.calc_relatives else None
144144
getter_cr = metrix_table[options.metric + "$"][1] if options.calc_cr else None
145-
tbl = table(metrix_table[options.metric][0])
145+
tbl = table(metrix_table[options.metric][0], options.format)
146146

147147
# header
148148
tbl.newColumn("name", "Name of Test", align = "left", cssclass = "col_name")

modules/ts/misc/table_formatter.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys, re, os.path, cgi, stat, math
44
from optparse import OptionParser
5-
from color import getColorizer
5+
from color import getColorizer, dummyColorizer
66

77
class tblCell(object):
88
def __init__(self, text, value = None, props = None):
@@ -34,7 +34,9 @@ class table(object):
3434
def_italic = False
3535
def_text="-"
3636

37-
def __init__(self, caption = None):
37+
def __init__(self, caption = None, format=None):
38+
self.format = format
39+
self.is_markdown = self.format == 'markdown'
3840
self.columns = {}
3941
self.rows = []
4042
self.ridx = -1;
@@ -248,7 +250,7 @@ def getValue(self, name, *elements):
248250

249251
def consolePrintTable(self, out):
250252
columns = self.layoutTable()
251-
colrizer = getColorizer(out)
253+
colrizer = getColorizer(out) if not self.is_markdown else dummyColorizer(out)
252254

253255
if self.caption:
254256
out.write("%s%s%s" % ( os.linesep, os.linesep.join(self.reformatTextValue(self.caption)), os.linesep * 2))
@@ -288,19 +290,40 @@ def consolePrintRow2(self, out, r, columns):
288290
i += colspan
289291

290292
#print content
291-
for ln in range(row.minheight):
292-
i = 0
293-
while i < len(row.cells):
294-
if i > 0:
295-
out.write(" ")
296-
cell = row.cells[i]
297-
column = columns[i]
298-
if cell is None:
299-
out.write(" " * column.minwidth)
300-
i += 1
293+
if self.is_markdown:
294+
out.write("|")
295+
for c in row.cells:
296+
text = ' '.join(self.getValue('text', c) or [])
297+
out.write(text + "|")
298+
out.write(os.linesep)
299+
else:
300+
for ln in range(row.minheight):
301+
i = 0
302+
while i < len(row.cells):
303+
if i > 0:
304+
out.write(" ")
305+
cell = row.cells[i]
306+
column = columns[i]
307+
if cell is None:
308+
out.write(" " * column.minwidth)
309+
i += 1
310+
else:
311+
self.consolePrintLine(cell, row, column, out)
312+
i += self.getValue("colspan", cell)
313+
if self.is_markdown:
314+
out.write("|")
315+
out.write(os.linesep)
316+
317+
if self.is_markdown and row.props.get('header', False):
318+
out.write("|")
319+
for th in row.cells:
320+
align = self.getValue("align", th)
321+
if align == 'center':
322+
out.write(":-:|")
323+
elif align == 'right':
324+
out.write("--:|")
301325
else:
302-
self.consolePrintLine(cell, row, column, out)
303-
i += self.getValue("colspan", cell)
326+
out.write("---|")
304327
out.write(os.linesep)
305328

306329
def consolePrintLine(self, cell, row, column, out):
@@ -588,7 +611,7 @@ def getStdoutFilename():
588611
return ""
589612

590613
def detectHtmlOutputType(requestedType):
591-
if requestedType == "txt":
614+
if requestedType in ['txt', 'markdown']:
592615
return False
593616
elif requestedType in ["html", "moinwiki"]:
594617
return True
@@ -701,7 +724,7 @@ def formatValue(val, metric, units = None):
701724
exit(0)
702725

703726
parser = OptionParser()
704-
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto")
727+
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html', 'markdown' or 'auto' - default)", metavar="FMT", default="auto")
705728
parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean")
706729
parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms")
707730
(options, args) = parser.parse_args()
@@ -750,7 +773,7 @@ def formatValue(val, metric, units = None):
750773

751774
for arg in args:
752775
tests = testlog_parser.parseLogFile(arg)
753-
tbl = table(arg)
776+
tbl = table(arg, format=options.format)
754777
tbl.newColumn("name", "Name of Test", align = "left")
755778
tbl.newColumn("value", metrix_table[options.metric][0], align = "center", bold = "true")
756779

0 commit comments

Comments
 (0)