Skip to content

Commit

Permalink
feat(#13): custom content in report
Browse files Browse the repository at this point in the history
  • Loading branch information
williamfzc committed Jul 27, 2019
1 parent 8d49c91 commit 7c1ec71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions example/cut_and_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

# cut
video_path = '../test.mp4'
cutter = VideoCutter()
cutter = VideoCutter(step=10)
res = cutter.cut(video_path)
stable, unstable = res.get_range()
data_home = res.pick_and_save(stable, 5)
data_home = res.pick_and_save(stable, 3)

# classify
cl = SVMClassifier()
Expand All @@ -22,7 +22,7 @@
stable,
# 步长,可以自行设置用于平衡效率与颗粒度
# 默认为1,即每帧都检测
step=1
step=10
)

# draw
Expand All @@ -33,4 +33,6 @@
for each in unstable:
r.add_thumbnail(f'{each.start}-{each.end}', res.thumbnail(each))

# 在0.3.2及之后的版本,你可以在报告中加入一些自定义内容 (https://github.com/williamfzc/stagesepx/issues/13)
# r.add_extra('here is title', 'here is content')
r.draw(classify_result)
19 changes: 19 additions & 0 deletions stagesepx/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@
</div>
{% endif %}
{% if extras %}
<div class="container">
<div class="card border-light">
<div class="card-body">
<h2>Extras</h2>
{% for name, value in extras.items() %}
<h3> {{ name }} </h3>
<p> {{ value }} </p>
{% endfor %}
</div>
</div>
</div>
{% endif %}
<div class="container">
<div class="card border-light">
<div class="card-body">
Expand Down Expand Up @@ -100,6 +114,7 @@ class Reporter(object):
def __init__(self):
self.dir_link_list: typing.List[str] = list()
self.thumbnail_list: typing.List[typing.Tuple[str, str]] = list()
self.extra_dict: typing.Dict[str, str] = dict()

def add_dir_link(self, data_path: str):
self.dir_link_list.append(data_path)
Expand All @@ -109,6 +124,9 @@ def add_thumbnail(self, name: str, pic_object: np.ndarray):
b64_str = b64encode(buffer).decode()
self.thumbnail_list.append((name, b64_str))

def add_extra(self, name: str, value: str):
self.extra_dict[name] = value

@staticmethod
def _draw_line(data_list: typing.List[ClassifierResult]) -> Line:
# draw line chart
Expand Down Expand Up @@ -167,6 +185,7 @@ def draw(self,
chart=Markup(page.render_embed()),
dir_link_list=self.dir_link_list,
thumbnail_list=self.thumbnail_list,
extras=self.extra_dict,
)

# save to file
Expand Down

0 comments on commit 7c1ec71

Please sign in to comment.