1
|
|
|
from urlparse import urlparse |
|
|
|
|
2
|
|
|
from collections import Counter |
|
|
|
|
3
|
|
|
import datetime |
4
|
|
|
from operator import itemgetter |
|
|
|
|
5
|
|
|
|
6
|
|
|
import numpy as np |
|
|
|
|
7
|
|
|
import pandas as pd |
|
|
|
|
8
|
|
|
|
9
|
|
|
from bokeh.plotting import figure, curdoc, vplot |
|
|
|
|
10
|
|
|
from bokeh.embed import autoload_server, components |
|
|
|
|
11
|
|
|
from bokeh.client import push_session |
|
|
|
|
12
|
|
|
from bokeh.models import Button, ColumnDataSource |
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
def pages_timeseries(response): |
|
|
|
|
16
|
|
|
parse_datetime = lambda x: datetime.datetime.strptime(x, "%Y-%m-%dT%H:%M:%S.%f") |
17
|
|
|
parsed_dates = [parse_datetime(x[1]) for x in response] |
18
|
|
|
dates = sorted(parsed_dates) |
19
|
|
|
plot = figure(plot_width=584, x_axis_type="datetime", x_axis_label="Dates", |
20
|
|
|
y_axis_label="Number Fetched") |
21
|
|
|
plot.line(x=dates, y=range(len(dates))) |
22
|
|
|
|
23
|
|
|
button = Button(label="Press Me") |
24
|
|
|
|
25
|
|
|
session = push_session(curdoc()) |
26
|
|
|
script = autoload_server(vplot(plot, button), session_id=session.id) |
27
|
|
|
return script |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
def add_line(): |
|
|
|
|
31
|
|
|
print("Clicked!") |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
def line_scratch(): |
|
|
|
|
35
|
|
|
|
36
|
|
|
line_width = 4 |
37
|
|
|
|
38
|
|
|
line1 = [(0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)] |
39
|
|
|
line2 = [(0, 1, 2, 3, 4, 5), (0, 5, 1, 4, 2, 3)] |
40
|
|
|
line3 = [(5, 4, 3, 2, 1), (5, 4, 3, 2, 1)] |
|
|
|
|
41
|
|
|
|
42
|
|
|
plot = figure() |
43
|
|
|
red = plot.line(x=line1[0], y=line1[1], line_width=line_width, color="crimson") |
|
|
|
|
44
|
|
|
blue = plot.line(x=line2[0], y=line2[1], line_width=line_width) |
|
|
|
|
45
|
|
|
# purple = plot.line(x=line3[0], y=line3[1], line_width=line_width, color="purple") |
46
|
|
|
|
47
|
|
|
button = Button(label="Add Line") |
48
|
|
|
button.on_click(add_line) |
49
|
|
|
|
50
|
|
|
curdoc().add_root(vplot(plot, button)) |
51
|
|
|
session = push_session(curdoc()) |
52
|
|
|
|
53
|
|
|
script = autoload_server(model=None, session_id=session.id) |
54
|
|
|
|
55
|
|
|
# script, div = components(vplot(plot, button)) |
56
|
|
|
return script |
57
|
|
|
|
58
|
|
|
line_scratch() |
59
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.