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

Class HTMLTableVisualizer

tu/loggers/html_table.py:20–318  ·  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

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

Callers 2

setUpClassMethod · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by 1

setUpClassMethod · 0.72