def add_thumbnail(self, name: str, pic_object: np.ndarray): """ add picture object (cv2) to your report :param name: :param pic_object: :return: """ b64_str = toolbox.np2b64str(pic_object) self.thumbnail_list.append((name, b64_str))
def draw( self, data_list: typing.List[ClassifierResult], report_path: str = None, cut_result: VideoCutResult = None, language: str = None, *args, **kwargs, ): """ draw report file :param data_list: classifierResult list, output of classifier :param report_path: your report will be there :param cut_result: more charts would be built :param language: 'en' or 'zh' :return: """ # draw line = self._draw_line(data_list) bar = self._draw_bar(data_list) # merge charts page = Page() page.add(line) page.add(bar) # calc time cost cost_dict = DataUtils.calc_changing_cost(data_list) # insert pictures if cut_result: # sim chart sim_line = self._draw_sim(cut_result) page.add(sim_line) _, unstable = cut_result.get_range(*args, **kwargs) # insert thumbnail if not self.thumbnail_list: logger.debug("auto insert thumbnail ...") for each in unstable: self.add_thumbnail( f"{each.start}({each.start_time}) - {each.end}({each.end_time}), " f"duration: {each.end_time - each.start_time}", cut_result.thumbnail(each, *args, **kwargs), ) # insert stable frames stable_stage_sample = self.get_stable_stage_sample(data_list, compress_rate=0.2) stable_stage_sample = toolbox.np2b64str(stable_stage_sample) # time stamp timestamp = toolbox.get_timestamp_str() # insert extras # default: zh_cn report if not language: language = "zh" template = Template(get_template(language)) template_content = template.render( chart=Markup(page.render_embed()), dir_link_list=self.dir_link_list, thumbnail_list=self.thumbnail_list, stable_sample=stable_stage_sample, extras=self.extra_dict, background_color=BACKGROUND_COLOR, cost_dict=cost_dict, timestamp=timestamp, version_code=__VERSION__, ) # save to file if not report_path: report_path = f"{timestamp}.html" with open(report_path, "w", encoding=constants.CHARSET) as fh: fh.write(template_content) logger.info(f"save report to {report_path}")
def draw(self, data_list: typing.List[ClassifierResult], report_path: str = None, cut_result: VideoCutResult = None, *args, **kwargs): """ draw report file :param data_list: classifierResult list, output of classifier :param report_path: your report will be there :param cut_result: more charts would be built :return: """ # draw line = self._draw_line(data_list) bar = self._draw_bar(data_list) # merge charts page = Page() page.add(line) page.add(bar) # calc time cost cost_dict = DataUtils.calc_changing_cost(data_list) # insert pictures if cut_result: # sim chart sim_line = self._draw_sim(cut_result) page.add(sim_line) _, unstable = cut_result.get_range(*args, **kwargs) # insert thumbnail if not self.thumbnail_list: logger.debug('auto insert thumbnail ...') for each in unstable: self.add_thumbnail( f'{each.start}({each.start_time}) - {each.end}({each.end_time}), ' f'duration: {each.end_time - each.start_time}', cut_result.thumbnail(each, *args, **kwargs), ) # insert stable frames stable_stage_sample = self.get_stable_stage_sample(data_list, compress_rate=0.2) stable_stage_sample = toolbox.np2b64str(stable_stage_sample) # insert extras template = Template(TEMPLATE) template_content = template.render( chart=Markup(page.render_embed()), dir_link_list=self.dir_link_list, thumbnail_list=self.thumbnail_list, stable_sample=stable_stage_sample, extras=self.extra_dict, background_color=BACKGROUND_COLOR, cost_dict=cost_dict, ) # save to file if not report_path: report_path = f'{toolbox.get_timestamp_str()}.html' with open(report_path, "w") as fh: fh.write(template_content) logger.info(f'save report to {report_path}')