<commit_before>
from bokeh.sampledata import glucose
from bokeh.plotting import *

day = glucose.data.ix['2010-10-06']
highs = day[day['glucose'] > 180]
lows = day[day['glucose'] < 80]


output_file("glucose.html", title="glucose.py example")

hold()

line(glucose.data.index.astype('int')/1000000, glucose.data['glucose'], color='red', tools="pan,zoom,resize", legend='glucose')
line(glucose.data.index.astype('int')/1000000, glucose.data['isig'], color='blue', legend='isig')
curplot().title = "Glucose Measurements"

figure()

line(day.index.astype('int')/1000000, day['glucose'], line_color="gray", line_dash="4 4", legend="glucose", line_width=2, tools="pan,zoom,resize")
scatter(highs.index.astype('int')/1000000, highs['glucose'], color='tomato', radius=4, legend="high")
scatter(lows.index.astype('int')/1000000, lows['glucose'], color='navy', radius=4, legend="low")
xgrid()[0].grid_line_color=None
ygrid()[0].grid_line_dash="3 6"
ygrid()[0].grid_line_alpha=0.5
curplot().title = "Glucose Range"

# open a browser
show()
<commit_msg>improve glucose example<commit_after>
import pandas as pd

from bokeh.sampledata.glucose import data
from bokeh.plotting import *



output_file("glucose.html", title="glucose.py example")

hold()

dates = data.index.astype('int')/1000000 # Pandas keeps nanoseconds, need microseconds

line(dates, data['glucose'], color='red', tools="pan,zoom,resize", legend='glucose')
line(dates, data['isig'], color='blue', legend='isig')
curplot().title = "Glucose Measurements"

figure()

day = data.ix['2010-10-06']
highs = day[day['glucose'] > 180]
lows = day[day['glucose'] < 80]

line(day.index.astype('int')/1000000, day['glucose'], line_color="gray", line_dash="4 4", legend="glucose", line_width=2, tools="pan,zoom,resize")
scatter(highs.index.astype('int')/1000000, highs['glucose'], color='tomato', radius=4, legend="high")
scatter(lows.index.astype('int')/1000000, lows['glucose'], color='navy', radius=4, legend="low")
xgrid()[0].grid_line_color=None
ygrid()[0].grid_line_dash="3 6"
ygrid()[0].grid_line_alpha=0.5
curplot().title = "Glucose Range"

figure()

data['inrange'] = (data['glucose'] < 180) & (data['glucose'] > 80)
window = 30.5*288 #288 is average number of samples in a month
inrange = pd.rolling_sum(data.inrange, window)
inrange = inrange.dropna()
inrange = inrange/float(window)

line(inrange.index.astype('int')/1000000, inrange, line_color="navy", legend="in-range", tools="pan,zoom,resize")
curplot().title = "Glucose In-Range Rolling Sum"

# open a browser
show()

{'fraction_non_alphanumeric': 0.19714964370546317, 'fraction_numerical': 0.05304829770387965, 'mean_word_length': 7.624573378839591, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7200117', 'n_tokens_mistral': 1050, 'n_tokens_neox': 887, 'n_words': 171}