MCPcopy Create free account
hub / github.com/Relento/lego_release / HTMLTableVisualizer

Class HTMLTableVisualizer

util/html_table.py:22–185  ·  view source on GitHub ↗

Example: >>> vis = HTMLTableVisualizer(' ', 'Visualization') >>> with vis.html(): >>> with vis.table('Table Name', [ >>> HTMLTableColumnDesc('column1', 'Image', 'image', {'width': '120px'}), >>> HTMLTableColumnDesc('column2',

Source from the content-addressed store, hash-verified

20
21
22class HTMLTableVisualizer(object):
23 """
24 Example:
25 >>> vis = HTMLTableVisualizer('<some_dir>', 'Visualization')
26 >>> with vis.html():
27 >>> with vis.table('Table Name', [
28 >>> HTMLTableColumnDesc('column1', 'Image', 'image', {'width': '120px'}),
29 >>> HTMLTableColumnDesc('column2', 'Result', 'figure' {}),
30 >>> HTMLTableColumnDesc('column3', 'Supervision', 'text' {}),
31 >>> HTMLTableColumnDesc('column4', 'Prediction', 'code' {'font-size': '12px'})
32 >>> ]):
33 >>> vis.row(...)
34 """
35
36 def __init__(self, visdir, title):
37 self.visdir = visdir
38 self.title = title
39
40 self._index_file = None
41 self._table_counter = 0
42 self._row_counter = 0
43
44 self._current_columns = None
45
46 @contextlib.contextmanager
47 def html(self):
48 self.begin_html()
49 yield self
50 self.end_html()
51
52 def begin_html(self):
53 if osp.isfile(self.visdir):
54 raise FileExistsError('Visualization dir "{}" is a file.'.format(self.visdir))
55 elif osp.isdir(self.visdir):
56 if yes_or_no('Visualization dir "{}" is not empty. Do you want to overwrite?'.format(self.visdir)):
57 shutil.rmtree(self.visdir)
58 else:
59 raise FileExistsError('Visualization dir "{}" already exists.'.format(self.visdir))
60
61 os.makedirs(self.visdir, exist_ok=True)
62 os.makedirs(osp.join(self.visdir, 'assets'), exist_ok=True)
63 self._index_file = open(self.get_index_filename(), 'w')
64 self._print('<html>')
65 self._print('<head>')
66 self._print('<title>{}</title>'.format(self.title))
67 self._print('<style>')
68 self._print('td {vertical-align:top;padding:5px}')
69 self._print('</style>')
70 self._print('</head>')
71 self._print('<body>')
72 self._print('<h1>{}</h1>'.format(self.title))
73
74 def end_html(self):
75 self._print('</body>')
76 self._print('</html>')
77 self._index_file.close()
78 self._index_file = None
79

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected