Beispiel #1
0
def trying():
	now=datetime.datetime.now().strftime("%Y%m%d")
	now_30=(datetime.datetime.now()-datetime.timedelta(days=30)).strftime("%Y%m%d")
	tick=app.vars
	stock_data = requests.get("https://www.quandl.com/api/v3/datatables/WIKI/PRICES.json?date.gte="+now_30+"&date.lt="+now+"&ticker="+tick+"&api_key=yvSB52TFjUsFTyZU-n--")
	unp_data=stock_data.json()["datatable"]["data"]
	unp_label=stock_data.json()["datatable"]["columns"]
	label=[]
	for entries in unp_label:
		label.append(str(entries["name"]))
	df=pandas.DataFrame(unp_data)
	df.columns=label
	close_mean="%.2f" %df[["close"]].mean()
	close_std="%.2f" %df[["close"]].std()
	captions="mean="+ close_mean +", std="+ close_std
	df2=df[["date","close"]]
	li=Line(df2,x="date",y="close",xlabel="date",ylabel="closing price",legend=False,title=tick+" stock chart from "+now_30+" to "+now)
	caption1=Label(x=400, y=100, x_units='screen', y_units='screen', text=captions, text_font_size='9pt', text_font_style="bold")
	li.add_layout(caption1)
	script, div = components(li)
	return render_template('trying.html', script=script, div=div)
    return breath, status, vol


df = pd.read_csv(r'c:\Research_data\DH_data\test-840-1.txt', engine = 'python', skiprows = 2, skipfooter = 2,
                 names = ['flow', 'paw', 'other'])

df.reset_index(drop = False, inplace = True)
df.drop(labels = 'other', axis = 1, inplace = True)
df.flow = pd.to_numeric(df.flow, errors = 'coerce')
df.paw = pd.to_numeric(df.paw, errors = 'coerce')

df['breath'], df['status'], df['vol'] = count_breath(df.flow.values)
df.dropna(axis = 0, how = 'all', subset = ['flow'], inplace = True)

df.vol = df.groupby('breath')['vol'].cumsum()

p = Line(df, x = 'index', y = ['flow', 'paw', 'vol', 'breath', 'status'], color = 'red')
p.extra_y_ranges = {'flow': Range1d(start = 0, end = 30)}
p.add_layout(LinearAxis(y_range_name = 'flow'), 'left')

check_button = CheckboxButtonGroup(labels = ['Double Stacked', 'Flow Limited', 'Ineffective Trigger'],
                                   active = [0, 0, 0])
next_button = Button(label = 'Next', type = 'success')
next_button.on_click(print('ok'))
output_file('test.html')

show(vform(p, check_button, next_button))