-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroutes.py
More file actions
87 lines (69 loc) · 2.56 KB
/
routes.py
File metadata and controls
87 lines (69 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# ===============================================================================
# Copyright 2018 ross
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
from datetime import datetime
from bokeh.embed import components
from bokeh.plotting import figure
from flask import render_template, request, session, redirect, url_for, flash
from numpy.ma import array
from application import app
from sensor import get_sensor_data
def create_figure(x, y, title):
tools = "crosshair,pan,reset,save,wheel_zoom"
plot = figure(plot_height=400, plot_width=400,
title=title,
tools=tools)
plot.line(x, y, line_width=3, line_alpha=0.6)
# plot.xaxis.axis_label = 'Demo X'
# Set the y axis label
#
# plot.yaxis.axis_label = 'Demo Y'
return plot
def make_demo_plot():
x = array([1, 2, 3, 4])
a, b, c = 1, 2, 3
y = a * x * x + b * x + c
# Create the plot
plot = create_figure(x, y, 'Demo Plot')
return components(plot)
@app.route('/')
def index():
print 'executing index'
script, div = make_demo_plot()
ctx = {'timestamp': datetime.now(),
'sensor1': get_sensor_data(1),
'sensor2': get_sensor_data(2),
'temp_script': script,
'temp_div': div}
return render_template('index.html', **ctx)
@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('index'))
return render_template('login.html', error=error)
@app.route('/logout')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('index'))
# ============= EOF =============================================