예제 #1
0
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
    }
예제 #2
0
def confirm_new_annotation(btn, app):
    global saved_annotations

    annotations = app.objects['annotations']
    annotation_txt = app.objects['annotation_txt'].value

    dlg = app.objects['new_annotation_dlg']
    dlg.visible = False

    new_annotations = MultiSelect.create(options=[x for x in annotations.options], name='annotations')
    rec = {'name': annotation_txt, 'value': annotation_txt}
    if annotation_txt and not rec in new_annotations.options:
        new_annotations.options.append(rec)

    saved_annotations[annotation_txt] = {
        "txt": annotation_txt,
        "charts_selection": current_selection,
    }
    #
    # for p in app.objects['charts_box'].children:
    #     import pdb; pdb.set_trace()
    #     p.text(
    #
    #         df['ind'][current_selection['1d']['indices'][0]], 0, annotation_txt,
    #         text_font_size="8pt", text_align="center", text_baseline="middle"
    #     )
    # import pdb; pdb.set_trace()
    # print "SAVED!!", saved_annotations

    return {'annotations': new_annotations}
예제 #3
0
def dash_remove_field(rbutton, app):
    """
    Event handler for click on "remove field" button
    """
    ms = app.objects['ms']
    to_remove = ms.value
    options = [x for x in ms.options if x['value'] not in to_remove]
    new_ms = MultiSelect.create(options=options, name='ms')

    # TODO: Do we really need to recreate the entire DataTable object?
    ndt = DataTable(source=source, columns=[], editable=True, width=500)
    for new_value in options:
        ndt.columns.append(
            TableColumn(
                field=new_value['value'], title=new_value['value'],editor=StringEditor()
            )
        )

    main_content = MultiSelect.create(options=['AW', 'BS', 'C'], name='pppp')
    main_tab = AppHBox(app=app, children=[main_content], width=300)

    return {'ms': new_ms, 'dt': ndt}
예제 #4
0
    def setup_filter_widgets(self, obj, attrname, old, new):
        # print ("setup_filter_widgets")
        """Creates new filter widget each time a new column is added to filters.

        Args:
          obj (Widget): the object that has an attribute change
          attrname (str): name of the attribute
          old (type): the previous value of unknown type
          new (type): the new value of unknown type

        """
        self.clear_selections(obj, attrname, old, new)

        # add new widget as required for each column set to filter on
        column_descriptor_dict = self.column_descriptor_dict()
        for col in self.filtering_columns:

            metadata = column_descriptor_dict[col]
            if not col in self.filter_widgets:

                # discrete
                if metadata['type'] == 'DiscreteColumn':
                    description = self.query('/bench/v1/desc/single/{0}'.format(col))
                    options = description['options']
                    select = MultiSelect.create(
                        name=col,
                        options=options)
                    self.filter_widgets[col] = select

                # continuous
                else:
                    col_query = self.query('/bench/v1/col/single/{0}'.format(col))
                    histogram = col_query['values']
                    source = make_histogram_source(histogram)
                    self.filter_sources[col] = source
                    hist_plot = make_histogram(self.filter_sources[col],
                                               plot_width=200, plot_height=100,
                                               title_text_font_size='8pt',
                                               tools='box_select'
                    )
                    hist_plot.title = col
                    self.filter_widgets[col] = hist_plot

        curdoc()._add_all()
예제 #5
0
    def setup_filter_widgets(self, obj, attrname, old, new):
        # print ("setup_filter_widgets")
        """Creates new filter widget each time a new column is added to filters.

        Args:
          obj (Widget): the object that has an attribute change
          attrname (str): name of the attribute
          old (type): the previous value of unknown type
          new (type): the new value of unknown type

        """
        self.clear_selections(obj, attrname, old, new)

        # add new widget as required for each column set to filter on
        column_descriptor_dict = self.column_descriptor_dict()
        for col in self.filtering_columns:

            metadata = column_descriptor_dict[col]
            if not col in self.filter_widgets:

                # discrete
                if metadata['type'] == 'DiscreteColumn':
                    description = self.query(
                        '/bench/v1/desc/single/{0}'.format(col))
                    options = description['options']
                    select = MultiSelect.create(name=col, options=options)
                    self.filter_widgets[col] = select

                # continuous
                else:
                    col_query = self.query(
                        '/bench/v1/col/single/{0}'.format(col))
                    histogram = col_query['values']
                    source = make_histogram_source(histogram)
                    self.filter_sources[col] = source
                    hist_plot = make_histogram(self.filter_sources[col],
                                               plot_width=200,
                                               plot_height=100,
                                               title_text_font_size='8pt',
                                               tools='box_select')
                    hist_plot.title = col
                    self.filter_widgets[col] = hist_plot

        curdoc()._add_all()
예제 #6
0
def update_select(select_sec, app):
    # TODO: Definitely needs a better design to avoid using globals...
    global source
    global csource
    global df
    global index

    ss = app.objects['select_sec'].value
    df = load_symbol(ss)

    index = df.pop('dt')

    df = df[num_columns]
    df['ind'] = list(range(len(index)))

    for name in num_columns:
        stdv = df[name].std()
        values = [stdv for x in df.index]
        df['%s_std_dv' % name] = values

    source = ColumnDataSource(df)
    source.tags = ['main_source']

    ndt = DataTable(source=source, columns=[], editable=True, width=500)
    charts_box = AppVBox(app=app, children=[], name='charts_box')

    templ = """FOUND %s CRASHES FOR SYMBOL %s"""
    crashes_info = check_for_crash(ss)

    crashes_source = ColumnDataSource(crashes_info)
    ccolumns = [TableColumn(field=x, title=x, editor=NumberEditor()) for x in crashes_info.columns]
    txt = PreText(text=templ % (len(crashes_info), ss), width=500, height=100)
    crashes_dt = DataTable(source=crashes_source, columns=ccolumns, editable=True, width=500)

    crashes_box = AppVBox(app=app, children=[txt, crashes_dt], name='crash_stats')

    new_ms = MultiSelect.create(options=[], name='ms')
    return {
        'charts_box': charts_box,
        'dt': ndt,
        'crash_stats': crashes_box,
        'ms': new_ms,
    }
예제 #7
0
def dash_update_input(abutton, app):
    """
    Event handler for click on "add field" button
    """
    ms = app.objects['ms']
    dt = app.objects['dt']

    columns = [x for x in dt.columns]
    ndt = DataTable(source=source, columns=columns, editable=True, width = 500)
    new_ms = MultiSelect.create(options=[x for x in ms.options], name='ms')
    new_value = app.objects['field_to_add'].value or app.objects['field_to_add'].options[0]['value']
    rec = {'name': new_value, 'value': new_value}
    if new_value and not rec in new_ms.options:
        new_ms.options.append(rec)
        ndt.columns.append(
            TableColumn(field=new_value, title=new_value, editor=StringEditor())
        )

    return {'ms': new_ms, 'dt': ndt}
예제 #8
0
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
    }
예제 #9
0
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'),
    }