def index():
    streaming = True
    source = AjaxDataSource(data_url="http://localhost:5000/source_data",
                            polling_interval=100)
    source.data = get_data(time_slice)
    payload = encode_utf8(get_html(source))
    return payload
Exemple #2
0
def index(request):    
    plot = figure(responsive=True, tools=[],
               plot_width=500, plot_height=250,
               x_range=(-180, 180), y_range=(-90, 90))
    plot.toolbar_location = None
    plot.axis.visible = None
  
    source = AjaxDataSource(method='GET',
                            data_url='http://localhost:8000/view2d/data/',
                            polling_interval=1000)   
    source.data = dict(x=[], y=[]) # Workaround to initialize the plot
 
    img = load_image("static/images/earth.png") 
    plot.image_rgba(image=[img], x=[-180], y=[-90], dw=[360], dh=[180])
    plot.cross(source=source, x='x', y='y', 
               size=22, line_width=4, color='Orange') # CLU1

    script, div = components(plot, INLINE)
    js_resources = INLINE.render_js()
    css_resources = INLINE.render_css()
    context = {
        'bokeh_script' : script,
        'bokeh_div' : div,
        'js_resources' : js_resources,
        'css_resources' : css_resources
        } 
    return render(request, 'view2d/index.html', context)
Exemple #3
0
def makeTable(period, route):
    source = AjaxDataSource(data_url=request.url_root + route,
                            polling_interval=period,
                            method='GET',
                            mode='replace')

    source.data = dict(x=[], y=[])
    colx = TableColumn(field="x", title="Time")
    coly = TableColumn(field="y", title="Info")
    table = DataTable(source=source, columns=[colx, coly], height=300)

    script, div = components(table)

    return script, div
def makePlot(period, route, title, line_color):
    source = AjaxDataSource(data_url=request.url_root + route,
                            polling_interval=period,
                            method='GET',
                            mode='replace')

    source.data = dict(x=[], y=[])

    plot = figure(plot_height=200, plot_width=800, title=title)

    plot.line('x', 'y', source=source, line_width=1, line_color=line_color)

    script, div = components(plot)

    return script, div
Exemple #5
0
def simple():
    source = AjaxDataSource(data_url="http://127.0.0.1:5000/data",
                            polling_interval=500,
                            mode='append',
                            max_size=30)
    source.data = dict(x=[], y=[])

    fig = figure(height=250, width=450)
    fig.circle('x', 'y', source=source)

    script, div = components(fig, INLINE)

    return jsonify(script=script,
                   div=div,
                   js_resources=INLINE.render_js(),
                   css_resources=INLINE.render_css())
Exemple #6
0
def bokeh_image_ajax_data(request, bokeh_id):
    model = BokehVisual.objects.get(pk=bokeh_id)
    x_title = ""
    y_title = ""
    with open(os.path.join(model.path,'vis.dat'),'r') as f_in:
        titles = f_in.readline().split(',')
        x_title = titles[0].replace(' ','')
        y_title = titles[1].replace(' ','')

    plot = figure(title= model.title,
                  x_axis_label= x_title,
                  y_axis_label= y_title,
                  plot_width = model.width,
                  plot_height = model.height)

    source = AjaxDataSource(data_url="http://localhost:8000/bokeh/id/{}/data/".format(bokeh_id), content_type="json", method="GET", mode='replace')
    source.data = dict(x=[], y=[])

    if(model.img_type == 'line'):
        im = plot.line('x', 'y', source=source)
    if(model.img_type == 'circle'):
        im = plot.circle('x', 'y', source=source)

    callback = bokeh.models.CustomJS(args=dict(src=source,plt=plot), code="""
        var source = src;
        var plot = plt;
        start_redrawing = Date.now();
        for (var i = 0; i < 100000; i++) {
            plot.change.emit();
        }
        stop_redrawing = Date.now();
        statistic_redrawing();
    """)
    button = bokeh.models.Button(label="Start redrawing", callback=callback)
    layout = bokeh.models.layouts.Column(button, plot)

    response_dict = {'script':'', 'div':''}
    response_dict['script'], response_dict['div'] = components(layout)
    return JsonResponse({'get':response_dict})
Exemple #7
0
def plot_conceptDrift():
    # "append" mode is used to output the concatenated data
    source = AjaxDataSource(data_url='http://127.0.0.1:5000/ConceptDrift/',
                            polling_interval=1000,
                            mode='append')
    source.data = dict(t_stamp=[],
                       drift_num=[],
                       avg_loss=[],
                       loss_batch=[],
                       label_avg_loss=[],
                       label_loss_batch=[],
                       label_concept_drift=[])
    plot = figure(plot_height=300,
                  plot_width=500,
                  x_range=(0, 2000),
                  y_range=(0, 1.1))
    plot.line('t_stamp',
              'avg_loss',
              source=source,
              line_color="red",
              legend="label_avg_loss",
              line_width=2)
    plot.line('t_stamp',
              'loss_batch',
              source=source,
              line_color="blue",
              legend="label_loss_batch",
              line_width=2)
    plot.square('t_stamp',
                'drift_num',
                source=source,
                color="orange",
                legend="label_concept_drift",
                size=5)
    script, div = components(plot)
    return script, div
Exemple #8
0
def index():
    global pollfreq
    global range
    post = False

    if request.method == 'POST':
        range = request.form['range']
        post = True
    # print("range:", range)

    # Initialize figure data and data source
    source = AjaxDataSource(data_url="/monitor/data",
                            max_size=5000,
                            polling_interval=pollfreq * 1000,
                            mode='append')

    dates = []
    tempfs = []
    dates, tempfs = get_initial_data(range)

    source.data = dict(x=dates, y=tempfs)

    # Create the plot
    TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
    fig = figure(title='DS18B20 Sensor',
                 x_axis_type='datetime',
                 tools=TOOLS,
                 plot_height=280,
                 sizing_mode='scale_width')
    hover = HoverTool(
        tooltips=[
            ('temp', '@y{0.00}'),
            ('time', '@x{%F %T}'),
        ],
        formatters={
            'x': 'datetime',  # use 'datetime' formatter for 'x' field
        },
        mode='vline')
    fig.add_tools(hover)
    fig.xgrid.grid_line_color = None
    fig.ygrid.grid_line_alpha = 0.8
    fig.xaxis.axis_label = 'Time'
    fig.yaxis.axis_label = 'Temperature'

    fig.y_range = Range1d(60, 90)

    fig.line('x', 'y', source=source, line_width=2)
    fig.add_layout(BoxAnnotation(top=70, fill_alpha=0.1, fill_color='blue'))
    fig.add_layout(
        BoxAnnotation(bottom=70,
                      top=80,
                      fill_alpha=0.1,
                      line_color='green',
                      fill_color='green'))
    fig.add_layout(BoxAnnotation(bottom=80, fill_alpha=0.1, fill_color='red'))

    plot_script, plot_div = components(fig)

    if post:
        return (jsonify(plotscript=plot_script, plotdiv=plot_div))
    else:
        return render_template(
            "monitor/index.html",
            plot_script=plot_script,
            plot_div=plot_div,
            pollfreq=pollfreq,
        )
def make_ajax_plot():

    source = AjaxDataSource(data_url=request.url_root + 'data/',
                            polling_interval=86400000,
                            mode='append',
                            max_size=300)
    source.data = dict(time=[], karma=[], daily_inc=[], ma_week=[])
    global df, t
    for i in xrange(len(df.karma)):
        t += 1
        source.data['karma'].append(df.karma[i])
        #  t2 = re.split(' .*', str(df.date[i]))[0]
        source.data['time'].append(t)
        if i == 0:
            source.data['daily_inc'].append(0)
            source.data['ma_week'].append(0)
        else:
            source.data['daily_inc'].append(df.karma[i] - df.karma[i - 1])
            source.data['ma_week'].append(_moving_avg(list(df.karma[:i])))

    p = figure(plot_height=500,
               tools="xpan,xwheel_zoom,xbox_zoom,reset",
               x_axis_type=None,
               y_axis_location="right")
    p.x_range.follow = "end"
    p.x_range.follow_interval = 100
    p.x_range.range_padding_units = 'absolute'
    p.x_range.range_padding = 10
    p.line(x='time',
           y='karma',
           alpha=0.2,
           line_width=3,
           color='orange',
           source=source,
           legend='Karma Trend')
    p.legend.location = "top_left"

    p2 = figure(plot_height=250,
                x_range=p.x_range,
                tools="xpan,xwheel_zoom,xbox_zoom,reset",
                y_axis_location="right")
    p2.segment(x0='time',
               y0=0,
               x1='time',
               y1='daily_inc',
               line_width=6,
               color='black',
               alpha=0.5,
               source=source,
               legend='Daily Increase')
    p2.line(x='time',
            y='ma_week',
            color='red',
            source=source,
            legend='Weekly Moving Average')
    p2.legend.location = "top_left"

    final_plot = gridplot([[p], [p2]],
                          toolbar_location="left",
                          plot_width=1000)

    script, div = components(final_plot)
    return script, div
Exemple #10
0
def plot_dataset():
    '''data_directory = "/Users/Jingwei/PycharmProjects/distributed_use/venv/TestDataset/UCR_TS_Archive_2015"
    datasetName = "/FordA/FordA_TRAIN"
    list_timeseries = util.load_dataset(data_directory+datasetName)'''
    plot_window = figure(plot_height=150,
                         plot_width=500,
                         title='New Incoming TS micro-batch')
    plot_all = figure(plot_height=150,
                      plot_width=500,
                      title='All historical TS')
    plot_window.axis.visible = False
    plot_all.axis.visible = False

    source = AjaxDataSource(data_url='http://127.0.0.1:5000/ConceptDrift/',
                            polling_interval=1000,
                            mode='replace')
    source.data = dict(inputTSBatch=[], TS_set=[])

    def deserialize(data_string):
        data_set = data_string.split(';')
        data_list = []
        print("data_set is: " + str(data_set))
        for data in data_set:
            print("data is: " + data)
            data_set.append([int(i) for i in data[1:-1].split(',')])
        return data_list

    if len(source.data['inputTSBatch']) != 0:
        inputTSBatch = deserialize(source.data['inputTSBatch'][0])
        TS_set = deserialize(source.data['TS_set'][0])
        for ts_w in inputTSBatch:
            x = range(len(ts_w.timeseries))
            y = ts_w.timeseries
            plot_window.line(x, y, line_width=1)

        for ts_history in TS_set:
            x = range(len(ts_history.timeseries))
            y = ts_history.timeseries
            plot_all.line(x, y, line_width=1)
    '''global datasetName
    list_timeseries = util.load_dataset(datasetName)
    name_dataset = {k: v for ds in list_timeseries for k, v in ds.items()}
    dataset_list = list(name_dataset.values())
    #plot_window: input_TSBatch
    #plot_all: TS_set in "ISETS_Web_backend", how to extract the value? refer to a function which returns an object
    plot_window = figure(plot_height=150, plot_width=500, title='New Incoming TS micro-batch')
    plot_all = figure(plot_height=150, plot_width=500, title='All historical TS')

    plot_window.axis.visible = False
    plot_all.axis.visible = False
    #get the window size
    for ts in dataset_list[:2]:
        x = range(len(ts.timeseries))
        y = ts.timeseries
        plot_window.line(x, y, line_width=1)
    for ts in dataset_list[:50]:
        x = range(len(ts.timeseries))
        y = ts.timeseries
        plot_all.line(x, y, line_width=1)'''
    plot = gridplot([[plot_window], [plot_all]])
    script, div = components(plot)
    return script, div