-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp_pi.py
73 lines (53 loc) · 1.62 KB
/
app_pi.py
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
from flask import Flask, render_template
import json
import plotly
from plotly import tools
import plotly.graph_objs as go
import sqlite3
app = Flask(__name__)
class SqlReader:
def getData(self):
#connection = sqlite3.connect('/fullpath/to/sqlit3/pirs.db')
connection = sqlite3.connect('pirs.db')
cursor = connection.cursor()
sql_command = """
SELECT * from pirone
ORDER BY thetime DESC
LIMIT 2000;"""
cursor.execute(sql_command)
result = cursor.fetchall()
cursor.close()
return result
@app.route('/')
def index():
sql = SqlReader()
result = sql.getData()
numOfPoints = len(result)
pir = [yValues[1] for yValues in result]
xValues = [xValues[0] for xValues in result]
graphs = [
dict(
data=[
dict(
x=xValues,
y=pir,
type='bar'
),
],
layout=dict(
title='Motion vs Time'
)
)
]
# Add "ids" to each of the graphs to pass up to the client
# for templating
ids = ['Graph {}'.format(i) for i, _ in enumerate(graphs)]
# Convert the figures to JSON
# PlotlyJSONEncoder appropriately converts pandas, datetime, etc
# objects to their JSON equivalents
graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder)
return render_template('layouts/index.html',
ids=ids,
graphJSON=graphJSON)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=9999)