def get_analyzers_tables(
            self,
            analyzer: bt.analyzers.Analyzer) -> (Paragraph, List[DataTable]):
        """Return a header for this analyzer and one *or more* data tables."""
        if hasattr(analyzer, 'get_analysis_table'):
            title, table_columns_list = analyzer.get_analysis_table()
        else:
            # Analyzer does not provide a table function. Use our generic one
            title, table_columns_list = TableGenerator._get_analysis_table_generic(
                analyzer)

        param_str = get_params_str(analyzer.params)
        if len(param_str) > 0:
            title += f' ({param_str})'

        elems: List[DataTable] = []
        for table_columns in table_columns_list:
            cds = ColumnDataSource()
            columns = []
            for i, c in enumerate(table_columns):
                col_name = f'col{i}'
                cds.add(c[2:], col_name)
                columns.append(
                    TableColumn(field=col_name,
                                title=c[0],
                                formatter=self._get_formatter(c[1])))
            column_height = len(table_columns[0]) * 25
            elems.append(
                DataTable(source=cds,
                          columns=columns,
                          index_position=None,
                          height=column_height))
        return Paragraph(text=title, style={'font-size': 'large'}), elems
Esempio n. 2
0
    def _get_analysis_table_generic(analyzer: bt.analyzers.Analyzer) -> Tuple[object, List[object]]:
        """Returns two columns labeled 'Performance' and 'Value'"""
        table = [['Performance', ColummDataType.STRING], ['Value', ColummDataType.STRING]]

        def add_to_table(item: object, baselabel: str = ""):
            for ak, av in item.items():
                label = f"{baselabel} - {ak}" if len(baselabel) > 0 else ak
                if isinstance(av, (bt.AutoOrderedDict, OrderedDict)):
                    add_to_table(av, label)
                else:
                    table[0].append(label)
                    table[1].append(av)

        add_to_table(analyzer.get_analysis())
        return type(analyzer).__name__, [table]
Esempio n. 3
0
    def get_analyzers_tables(
            self, analyzer: bt.analyzers.Analyzer, strategy: bt.Strategy,
            params: Optional[bt.AutoInfoClass]
    ) -> (Paragraph, List[DataTable]):
        if hasattr(analyzer, 'get_analysis_table'):
            title, table_columns_list = analyzer.get_analysis_table()
        else:
            # Analyzer does not provide a table function. Use our generic one
            title, table_columns_list = TableGenerator._get_analysis_table_generic(
                analyzer)

        # if we have multiple strategies in the mix, add the name of the involved one
        if len(strategy.env.strats) > 0:
            title += f' ({get_strategy_label(strategy, params)})'

        elems: List[DataTable] = []
        for table_columns in table_columns_list:
            cds = ColumnDataSource()
            columns = []
            for i, c in enumerate(table_columns):
                col_name = f'col{i}'
                cds.add(c[2:], col_name)
                columns.append(
                    TableColumn(field=col_name,
                                title=c[0],
                                formatter=TableGenerator._get_formatter(c[1])))
            column_height = len(table_columns[0]) * 25
            elems.append(
                DataTable(source=cds,
                          columns=columns,
                          width=self._scheme.table_width,
                          height=column_height,
                          row_headers=False))
        return Paragraph(text=title,
                         width=self._scheme.table_width,
                         style={'font-size': 'large'}), elems