def performace_table(self,
                         policy_names: list,
                         decimals: int,
                         height: int = 600,
                         width: int = 900):
        """Table of the result using Bokeh.
        
        Parameters
        ----------
        policy_names : list
            List of selected policy names

        decimals : int
            Number of decimal places to round

        height : int
            Height of the table
            
        width : int
            Width of the table
            
        Returns
        -------
        None
        """

        selected_performance_dict = {
            key: self.performance_dict[key]
            for key in policy_names
        }
        table = pd.concat([
            pd.DataFrame(v, index=[k]).T
            for k, v in selected_performance_dict.items()
        ],
                          axis=1)
        table.reset_index(inplace=True)
        table.rename(columns={"index": "metric"}, inplace=True)
        table = table.round(decimals)

        Columns = [TableColumn(field=Ci, title=Ci)
                   for Ci in table.columns]  # bokeh columns
        data_table = DataTable(columns=Columns,
                               source=ColumnDataSource(table),
                               fit_columns=False,
                               height=height,
                               width=width)  # bokeh table
        data_table.index_position = None
        show(data_table)
示例#2
0
def catalysator(width, height):
    df = pd.read_sql(
        """WITH [T] AS (
                                    SELECT [NAZWA], MIN([NEXT_PAY]) AS [NEXT_PAY] FROM [CATALYSATOR]
                                    WHERE [NEXT_PAY] < DATEADD(DAY, 30, GETDATE())
                                    GROUP BY [NAZWA]
                                    )

                        SELECT [C].[NEXT_PAY] AS [TERMIN], [C].[NAZWA], [ISIN], [CURR_OPR]/100 AS [%], [LICZBA_POZ_OKRESOW] AS [LPO],
                                "RODZAJ" = CASE
                                        WHEN [FREQ_WYPLAT] = 3 THEN 'Kwartalne'
                                        WHEN [FREQ_WYPLAT] = 6 THEN 'Półroczne'
                                END
                        FROM [CATALYSATOR] AS [C], [T]
                        WHERE [C].[NAZWA] = [T].[NAZWA]
                        AND [C].[NEXT_PAY] = [T].[NEXT_PAY]
                        ORDER BY [C].[NEXT_PAY]""", conn)

    #dane
    source = ColumnDataSource(data=df)
    #kolumny
    columns = [
        TableColumn(field="TERMIN", title="Termin", width=125),
        TableColumn(field="NAZWA", title="Emitent"),
        TableColumn(field="ISIN", title="ISIN", width=120),
        TableColumn(field="RODZAJ", title="Rodzaj", width=120),
        TableColumn(field="%",
                    title="%",
                    formatter=NumberFormatter(format='0.00%'),
                    width=50),
        TableColumn(field="LPO", title="Poz. wypłat", width=50),
    ]
    #tabela
    t = DataTable(source=source, columns=columns, width=width, height=height)
    t = finalize_table(t, True, False, False, True)
    t.index_position = None
    return t