def test_total_by_sector_single_filter(self, mock_get_data): mock_get_data.return_value = self.sample1 df = get_total_by_sector(("UDIBONOS", )) expected_df = pd.DataFrame( [[None, 10.], [20., 20.]], columns=pd.Series(['Banco de Mexico', 'Foreign Direct Investment'], name='short_name')) expected_df.index = pd.Series( ["2018-10-01T00:00:00", "2018-11-01T00:00:00"], name='date') assert_frame_equal(df, expected_df)
def drilldown_instrument(evt): if evt is not None: series = set([p['curveNumber'] for p in evt['points']]) instrument_types = [df_instrument.columns[i] for i in series] df = get_total_by_sector(frozenset(instrument_types)) return _figure_from_df( df, title='Sector Breakdown for %s Bonds' % ', '.join(instrument_types), height=SECTOR_CHART_HEIGHT, ) global df_sector return _figure_from_df( df_sector, title='Sector Breakdown', height=SECTOR_CHART_HEIGHT, )
import dash import dash_core_components as dcc import dash_html_components as html from dash.dependencies import Output, Input from plotly import tools import plotly.graph_objs as go from model import get_total_by_instrument, get_total_by_sector SECTOR_CHART_HEIGHT = 330 df_instrument = get_total_by_instrument() df_sector = get_total_by_sector() x_range = min(df_instrument.index), max(df_instrument.index) def _figure_from_df(df, select_enabled=False, title='', height=None): return { 'data': [ go.Bar( x=df.index, y=df[name], name=name, marker={ 'line': { 'width': 0, }, }, ) for name in df.columns