\n'
f'
\n' # noqa
f'
\n' # noqa
f'
\n' # noqa
f'')
sec_ret_str = f'
{label}' if show_label else ''
elif type == Media.VIDEO_PAIR:
assert isinstance(content, (list, tuple)) and len(content) == 2
ret_str = f'\n' # noqa
ret_str += f'
\n'
f'
\n' # noqa
f'
\n' # noqa
f'
\n' # noqa
f'
')
sec_ret_str = f'
{label}' if show_label else ''
else:
raise NotImplementedError
if cols_span > 1:
ret_str = f'
{ret_str} | \n'
sec_ret_str = f'
{sec_ret_str} | \n' if not sec_ret_str == '' else sec_ret_str
else:
ret_str = f'
{ret_str} | \n'
sec_ret_str = f'
{sec_ret_str} | \n' if not sec_ret_str == '' else sec_ret_str
return [ret_str, sec_ret_str]
def format_row(self):
sample_id = 0
all_sample_html = []
for one_content, one_row_meta in zip(self.content_list,
self.rows_meta):
one_row_str = '
'
one_row_str += '\n'.join([v[0] for v in one_content])
if self.allow_annotation:
row_meta = '#;#'.join(one_row_meta)
one_row_str += (
f' | \n'
)
one_row_str += '
'
one_row_str += '\n'.join([v[1] for v in one_content]) # noqa
if self.allow_annotation: # noqa
one_row_str += f' | \n' # noqa
one_row_str += '
'
if self.allow_annotation:
one_row_str = f'
'
all_sample_html.append(one_row_str)
sample_id += 1
return '
' + '\n'.join(all_sample_html) + '
'
def add_record(self,
content,
label='',
type=Media.TEXT,
row_id=1,
col_id=1,
cols_span=1,
annotation_meta=None,
show_label=True):
if row_id >= len(self.content_list):
self.content_list.append([])
self.rows_meta.append([])
if row_id != len(self.content_list) - 1:
raise RuntimeError(
'row_id should be next number of the last row_id.')
if col_id > len(self.content_list[row_id]):
raise RuntimeError(
'col_id should be next number of the last col_id.')
format_col = self.format_col(content,
f"{row_id}-{col_id}: {label}",
type,
show_label=show_label,
cols_span=cols_span)
annotation_meta = annotation_meta if annotation_meta else ''
if col_id == len(self.content_list[row_id]):
self.content_list[row_id].append(format_col)
self.rows_meta[row_id].append(annotation_meta)
else:
self.content_list[row_id][col_id] = format_col
self.rows_meta[row_id][col_id] = annotation_meta
def save_html(self, path):
html_body = self.format_row()
ret_html_list = [
self.html_start, self.html_head, self.html_style,
self.html_body.replace('{BODY}', html_body)
]
if self.allow_annotation:
ret_html_list.append(self.label_button)
ret_html_list.append(self.html_script)
ret_html_list.append(self.html_end)
ret_html = '\n'.join(ret_html_list)
with open(path, 'w') as f:
f.write(ret_html)