Add basic ui that displays live/history cadence data
This commit is contained in:
21
app.py
21
app.py
@@ -44,21 +44,16 @@ def handle_message(data):
|
|||||||
db.insert_cadence(data['rpm'], data['id'])
|
db.insert_cadence(data['rpm'], data['id'])
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/status", methods=['GET', 'POST'])
|
@ app.route("/")
|
||||||
def status():
|
def home():
|
||||||
req_data = save_request(request)
|
return render_template('base.html')
|
||||||
resp = Response(json.dumps(req_data, indent=4, default=str),
|
|
||||||
mimetype='application/json')
|
|
||||||
return resp
|
|
||||||
|
|
||||||
|
|
||||||
def save_request(request):
|
@app.route("/overview")
|
||||||
req_data = {}
|
def overview():
|
||||||
req_data['http'] = f"{request.method} {request.url}"
|
cadences = db.get_all_cadences()
|
||||||
req_data['json'] = request.json
|
last_cadence = cadences[-1]['rpm']
|
||||||
req_data['headers'] = dict(request.headers)
|
return render_template('overview.html', last_cadence=last_cadence, cadences=cadences)
|
||||||
|
|
||||||
return req_data
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
5
db.py
5
db.py
@@ -33,4 +33,7 @@ class DataBase():
|
|||||||
|
|
||||||
def insert_cadence(self, rpm, device_id):
|
def insert_cadence(self, rpm, device_id):
|
||||||
self.execute('INSERT INTO cadence (rpm, device_id) VALUES (%s, %s)',
|
self.execute('INSERT INTO cadence (rpm, device_id) VALUES (%s, %s)',
|
||||||
[rpm, device_id], commit=True, one=True)
|
[rpm, device_id], commit=True)
|
||||||
|
|
||||||
|
def get_all_cadences(self):
|
||||||
|
return self.execute('SELECT * FROM cadence')
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<title>Cardio</title>
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<script src="https://cdn.plot.ly/plotly-2.14.0.min.js"></script>
|
||||||
|
<script src="https://unpkg.com/htmx.org"></script>
|
||||||
|
<script src="https://unpkg.com/hyperscript.org"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="flex overflow-hidden bg-white pt-16">
|
||||||
|
|
||||||
|
<div class="h-full w-full bg-gray-50 relative overflow-y-auto">
|
||||||
|
<main>
|
||||||
|
<div class="pt-6 px-4" id="container">
|
||||||
|
<div hx-get="{{ url_for('overview') }}" hx-trigger="load, every 2s">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
37
templates/overview.html
Normal file
37
templates/overview.html
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<h1
|
||||||
|
class="mb-4 text-4xl font-extrabold leading-none tracking-tight text-gray-900 md:text-5xl lg:text-6xl dark:text-white">
|
||||||
|
{{last_cadence}} rpm</h1>
|
||||||
|
|
||||||
|
<div class="relative overflow-x-auto">
|
||||||
|
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400">
|
||||||
|
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||||
|
<tr>
|
||||||
|
<th scope="col" class="px-6 py-3">
|
||||||
|
TimeStamp
|
||||||
|
</th>
|
||||||
|
<th scope="col" class="px-6 py-3">
|
||||||
|
RPM
|
||||||
|
</th>
|
||||||
|
<th scope="col" class="px-6 py-3">
|
||||||
|
Device Id
|
||||||
|
</th>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for c in cadences|reverse %}
|
||||||
|
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
|
||||||
|
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||||
|
{{c['logged_at']}}
|
||||||
|
</th>
|
||||||
|
<td class="px-6 py-4">
|
||||||
|
{{c['rpm']}}
|
||||||
|
</td>
|
||||||
|
<td class="px-6 py-4">
|
||||||
|
{{c['device_id']}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user