def set_input_selector(self): # print ("set_input_selector") """Creates and configures each selector (drop-down menu).""" col_names = [x['name'] for x in self.columns] col_names.append('None') self.plot_selector = Select.create( title="PlotType", name="plot_type", value=self.plot_type, options=["line", "scatter", "bar"], ) self.x_selector = Select.create( name="x", value=self.x, options=col_names, ) self.y_selector = Select.create( name="y", value=self.y, options=col_names, ) self.agg_selector = Select.create( name='agg', value=self.agg, options=['sum', 'mean', 'last', 'count', 'percent'], )
def create_layout(self): # create figure self.x_range = Range1d(start=self.model.map_extent[0], end=self.model.map_extent[2], bounds=None) self.y_range = Range1d(start=self.model.map_extent[1], end=self.model.map_extent[3], bounds=None) self.fig = Figure(tools='wheel_zoom,pan', x_range=self.x_range, y_range=self.y_range) self.fig.plot_height = 660 self.fig.plot_width = 990 self.fig.axis.visible = False # add tiled basemap self.tile_source = WMTSTileSource(url=self.model.basemap) self.tile_renderer = TileRenderer(tile_source=self.tile_source) self.fig.renderers.append(self.tile_renderer) # add datashader layer self.image_source = ImageSource(url=self.model.service_url, extra_url_vars=self.model.shader_url_vars) self.image_renderer = DynamicImageRenderer(image_source=self.image_source) self.fig.renderers.append(self.image_renderer) # add ui components axes_select = Select.create(name='Axes', options=self.model.axes) axes_select.on_change('value', self.on_axes_change) field_select = Select.create(name='Field', options=self.model.fields) field_select.on_change('value', self.on_field_change) aggregate_select = Select.create(name='Aggregate', options=self.model.aggregate_functions) aggregate_select.on_change('value', self.on_aggregate_change) transfer_select = Select.create(name='Transfer Function', options=self.model.transfer_functions) transfer_select.on_change('value', self.on_transfer_function_change) basemap_select = Select.create(name='Basemap', value='Toner', options=self.model.basemaps) basemap_select.on_change('value', self.on_basemap_change) opacity_slider = Slider(title="Opacity", value=100, start=0, end=100, step=1) opacity_slider.on_change('value', self.on_opacity_slider_change) controls = [axes_select, field_select, aggregate_select, transfer_select, basemap_select, opacity_slider] self.controls = HBox(width=self.fig.plot_width, children=controls) self.layout = VBox(width=self.fig.plot_width, height=self.fig.plot_height, children=[self.controls, self.fig])
def line_config(app, df): options = CheckboxGroup( labels=['Show peaks', 'Show Std. Dev.', 'Bolinger Bands'], name='new_chart_options') title = TextInput(title="Chart Title", name='new_chart_title', value="Line") new_chart_index = Select.create(options=['---'] + list(df.columns), name='"new_chart_index"', title="Chart index") chart_values_select = MultiSelect.create(options=df.columns, name="chart_values", title="Values") chart_data = AppHBox( app=app, children=[new_chart_index, chart_values_select, options]) main_tab = AppVBox(app=app, children=[title, chart_data, 'select_palette']) confirm_chart_button = Button(label="Confirm", type="success", name='confirm_add_chart') return { 'dlg': Dialog(buttons=[confirm_chart_button], content=main_tab, visible=True), "new_chart_index": new_chart_index, 'new_chart_title': title, 'chart_values': chart_values_select, 'new_chart_options': options }
def create_layout(self): self.plot_selector = Select.create( title="PlotType", name="plot_type", value='area', options=['area', "line", "scatter", "bar"], ) self.btn_confirm = Button(label='add plot') self.layout = vplot(hplot(self.plot_selector, self.btn_confirm), self.plot)
def make_inst_date_input(self): observations = self._ccf_interface.get_observations(self.star) observations = ['/'.join(obs).ljust(20, ' ') for obs in observations] self.inst_date = observations[0] if isinstance(self.inst_date_select, Select): self.inst_date_select.update(value=observations[0], options=observations) else: self.inst_date_select = Select.create( name='Instrument/Date', value=observations[0], options=observations, )
def line_config(app, df): options = CheckboxGroup( labels=['Show peaks', 'Show Std. Dev.', 'Bolinger Bands'], name='new_chart_options' ) title = TextInput(title="Chart Title", name='new_chart_title', value="Line") new_chart_index = Select.create(options=['---']+list(df.columns), name='"new_chart_index"', title="Chart index") chart_values_select = MultiSelect.create(options=df.columns, name="chart_values", title="Values") chart_data = AppHBox(app=app, children=[new_chart_index, chart_values_select, options]) main_tab = AppVBox(app=app, children=[title, chart_data, 'select_palette']) confirm_chart_button = Button(label="Confirm", type="success", name='confirm_add_chart') return { 'dlg': Dialog(buttons=[confirm_chart_button], content=main_tab, visible=True), "new_chart_index": new_chart_index, 'new_chart_title': title, 'chart_values': chart_values_select, 'new_chart_options': options }
def dashboard(): """ Creates the main app objects """ # TODO: Should find a better design and remove those global objs... global source global csource source = ColumnDataSource(df) source.tags = ['main_source'] csource = ColumnDataSource(cdf) csource.tags = ['crash_source'] select_sec = Select.create(options=SECURITIES, name='select_sec', title="") asel = Select.create(options=df.columns, name='field_to_add', title="") chart_sel = Select.create(options=chart_types, name='chart_to_add', title="") msel = MultiSelect.create(options=[], name='ms') abutton = Button(label="add", type="success", name='add_button') rbutton = Button(label="remove", type="danger", name='remove_button') add_chart_button = Button(label="add chart", type="success", name='add_chart') data_table = DataTable(source=source, editable=True, width=500, height=400) ccolumns = [TableColumn(field=x, title=x, editor=NumberEditor()) for x in cdf.columns] crashes_table = DataTable(source=csource, editable=True, width=1200, height=400, columns=ccolumns) charts_box = AppVBox(children=[], name='charts_box') counts = cdf['crashes'] crashes_hist = charts.Histogram({'crash_counts': counts}, bins=20, height=300, title="# Crashes per Symbol") crashes_scatter = create_crashes_scatter() main_tab = VBox(children=[], name='d_box') dlg = Dialog(buttons=[], content=main_tab , visible=False) options = CheckboxGroup( labels=['Show peaks', 'Show Std. Dev.', 'Bolinger Bands'], name='new_chart_options' ) select_palette = Select.create(options=brewer.keys(), name='select_palette', title="Palette") return { # security tab 'select_sec': select_sec, 'field_to_add': asel, 'chart_to_add': chart_sel, 'ms': msel, 'dt': data_table, 'add_button': abutton, 'remove_button': rbutton, 'add_chart': add_chart_button, 'charts_box': charts_box, 'dlg': dlg, # Crashes tab objs 'crashes_hist': crashes_hist, 'crashes_scatter': crashes_scatter, 'crashes_table': crashes_table, 'crash_stats': PreText(text="NO CRASHES FOR SYMBOL %s" % SYMBOL, width=300), # 'chart_values': MultiSelect.create(options=df.columns, name="chart_values", title="Values"), 'new_chart_index': Select.create(options=['---']+list(df.columns), title="Chart index", name="new_chart_index"), 'new_chart_title': TextInput(title="Chart Title", name='new_chart_title', value=''), 'new_chart_options': options, 'select_palette': select_palette, # ANNOTATIONS "annotations": MultiSelect.create(options=[], name="annotations", title="Annotations"), "add_annotation": Button(label="add", type="success", name='add_annotation'), "delete_annotation": Button(label="remove", type="danger", name='delete_annotation'), "show_annotation": Button(label="Show", type="link", name='show_annotation'), 'new_annotation_dlg': Dialog(buttons=[], content=main_tab , visible=False), 'annotation_txt': TextInput(title="New Annotation", name='annotation_txt', value=''), 'new_annotation_options': CheckboxGroup(labels=[], name='new_annotation_options'), }
def create_objects(cls, symbol, df, securities): descr_box = Paragraph(text='content loading...') btn_close_loading = Button(label='Close Loading') dialog_loading = Dialog( title='loading', content=vplot(descr_box), name='loading_dialog', buttons=[btn_close_loading], visible=False) source_data = dict(df) main_source = ColumnDataSource(dict(df)) source = ColumnDataSource(source_data) # TODO: REMOVE THIS COMMENTED CODE! IT'S JUST THE PREVIOUS # VERSION USED BEFORE NEW P&D Cached results and algorithm # get the cached results of the P&D algorithm computed with the # "default" configuration # intervals = utils.cached_pumps.get(symbol, pumps.to_dicts(((),(),(),(),(),()))) # intervals['bottom'] = [0] * len(intervals['start']) # intervals['values'] = [max(df['price'])] * len(intervals['start']) # # intervals = pd.DataFrame(intervals) # new version stats = utils.get_symbols_cached_stats()[symbol] intervals = pd.DataFrame(stats) intervals['bottom'] = [0] * len(intervals['start']) intervals['values'] = [max(df['price'])] * len(intervals['start']) conv = lambda x: utils.to_seconds(pd.to_datetime(x)) intervals = intervals[ (pd.to_datetime(intervals['start']) > conv(config.date_range[0])) & (pd.to_datetime(intervals['start']) < conv(config.date_range[1])) ] # Create P&Ds intervals DataSource intervals_source = ColumnDataSource(intervals) source.tags = ['main_source'] trends = utils.load_trends_data(symbol, start_date=min(df['dt'])) trends_source = ColumnDataSource(trends) trades = Slider( title="trades", name='trades', value=0, start=0, end=124, step=1 ) # Selectors symbol = Select.create( options=securities, value=symbol, name='symbol', title="" ) window_selector = Select.create( options=['---'], name='period_selector', title="Search intervals with:" ) symbol_filter = Select.create( options=['All', 'Stocks with Spam', 'Stocks without Spam'], name='symbol_filter', title="Filter Symbols:", value='Stocks with Spam' ) callback = Callback( args={'symbol_filter': symbol_filter, 'dialog_loading': dialog_loading}, code=callbacks.symbol_filter ) symbol_filter.callback = callback btn_detect_pumps = Button(label='Configure P&D Detection', name='config_pumps') main_tab = Panel(title="Main") tabs = Tabs() # Create STOCKS TABLE ranks = utils.get_pumps_rank() # quotient_metrics = utils.get_quotient_metrics() # ranks['quotient'] = quotient_metrics['quotient'] foo = lambda x: utils.spams_count.get(x, 0) ranks['spams'] = map(foo, ranks['symbol']) ranks = ranks.sort(['spams', 'vol_quotient'], ascending=False) cls._pre_filtered_ranks = { 'All': {k: ranks[k] for k in ranks.columns}, 'Stocks with Spam': dict(ranks[ranks['spams'] > 0]. sort('vol_quotient', ascending=False)), 'Stocks without Spam': dict(ranks[ranks['spams'] == 0]. sort('vol_quotient', ascending=False)), } source_stocks_rank = ColumnDataSource(cls._pre_filtered_ranks['All']) table_stocks_rank = DataTable( source=source_stocks_rank, width=560, height=450, selectable=True, editable=True, columns=[ TableColumn(field='symbol', title='symbol', width=130, editor=StringEditor()), TableColumn(field='vol_quotient', title='volume ratio', editor=StringEditor(), default_sort='descending'), TableColumn(field='risk_score', title='risk', width=100, editor=StringEditor(), default_sort='descending'), TableColumn(field='spams', title='spams', width=130, editor=StringEditor(), default_sort='descending'), ]) callback = Callback(args={'tr': table_stocks_rank, 'sr': source_stocks_rank, 'symb': symbol, 'dialog_loading': dialog_loading}, code=callbacks.source_stocks_rank) source_stocks_rank.callback = callback return locals()
def create_objects(cls, symbol, df, securities): descr_box = Paragraph(text='content loading...') btn_close_loading = Button(label='Close Loading') dialog_loading = Dialog(title='loading', content=vplot(descr_box), name='loading_dialog', buttons=[btn_close_loading], visible=False) source_data = dict(df) main_source = ColumnDataSource(dict(df)) source = ColumnDataSource(source_data) # TODO: REMOVE THIS COMMENTED CODE! IT'S JUST THE PREVIOUS # VERSION USED BEFORE NEW P&D Cached results and algorithm # get the cached results of the P&D algorithm computed with the # "default" configuration # intervals = utils.cached_pumps.get(symbol, pumps.to_dicts(((),(),(),(),(),()))) # intervals['bottom'] = [0] * len(intervals['start']) # intervals['values'] = [max(df['price'])] * len(intervals['start']) # # intervals = pd.DataFrame(intervals) # new version stats = utils.get_symbols_cached_stats()[symbol] intervals = pd.DataFrame(stats) intervals['bottom'] = [0] * len(intervals['start']) intervals['values'] = [max(df['price'])] * len(intervals['start']) conv = lambda x: utils.to_seconds(pd.to_datetime(x)) intervals = intervals[ (pd.to_datetime(intervals['start']) > conv(config.date_range[0])) & (pd.to_datetime(intervals['start']) < conv(config.date_range[1]))] # Create P&Ds intervals DataSource intervals_source = ColumnDataSource(intervals) source.tags = ['main_source'] trends = utils.load_trends_data(symbol, start_date=min(df['dt'])) trends_source = ColumnDataSource(trends) trades = Slider(title="trades", name='trades', value=0, start=0, end=124, step=1) # Selectors symbol = Select.create(options=securities, value=symbol, name='symbol', title="") window_selector = Select.create(options=['---'], name='period_selector', title="Search intervals with:") symbol_filter = Select.create( options=['All', 'Stocks with Spam', 'Stocks without Spam'], name='symbol_filter', title="Filter Symbols:", value='Stocks with Spam') callback = Callback(args={ 'symbol_filter': symbol_filter, 'dialog_loading': dialog_loading }, code=callbacks.symbol_filter) symbol_filter.callback = callback btn_detect_pumps = Button(label='Configure P&D Detection', name='config_pumps') main_tab = Panel(title="Main") tabs = Tabs() # Create STOCKS TABLE ranks = utils.get_pumps_rank() # quotient_metrics = utils.get_quotient_metrics() # ranks['quotient'] = quotient_metrics['quotient'] foo = lambda x: utils.spams_count.get(x, 0) ranks['spams'] = map(foo, ranks['symbol']) ranks = ranks.sort(['spams', 'vol_quotient'], ascending=False) cls._pre_filtered_ranks = { 'All': {k: ranks[k] for k in ranks.columns}, 'Stocks with Spam': dict(ranks[ranks['spams'] > 0].sort('vol_quotient', ascending=False)), 'Stocks without Spam': dict(ranks[ranks['spams'] == 0].sort('vol_quotient', ascending=False)), } source_stocks_rank = ColumnDataSource(cls._pre_filtered_ranks['All']) table_stocks_rank = DataTable( source=source_stocks_rank, width=560, height=450, selectable=True, editable=True, columns=[ TableColumn(field='symbol', title='symbol', width=130, editor=StringEditor()), TableColumn(field='vol_quotient', title='volume ratio', editor=StringEditor(), default_sort='descending'), TableColumn(field='risk_score', title='risk', width=100, editor=StringEditor(), default_sort='descending'), TableColumn(field='spams', title='spams', width=130, editor=StringEditor(), default_sort='descending'), ]) callback = Callback(args={ 'tr': table_stocks_rank, 'sr': source_stocks_rank, 'symb': symbol, 'dialog_loading': dialog_loading }, code=callbacks.source_stocks_rank) source_stocks_rank.callback = callback return locals()