Change flow so home page is device select from where you can browse to overview
This commit is contained in:
13
app.py
13
app.py
@@ -56,10 +56,15 @@ def devices():
|
|||||||
return render_template('devices.html', devices=devices)
|
return render_template('devices.html', devices=devices)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/overview")
|
@ app.route("/device/<device_id>")
|
||||||
def overview():
|
def device(device_id):
|
||||||
cadences = db.get_all_cadences()
|
return render_template('device.html', device_id=device_id)
|
||||||
last_cadence = cadences[-1]['rpm']
|
|
||||||
|
|
||||||
|
@app.route("/overview/<device_id>")
|
||||||
|
def overview(device_id):
|
||||||
|
cadences = db.get_all_cadences(device_id)
|
||||||
|
last_cadence = cadences[-1]['rpm'] if cadences else 0
|
||||||
|
|
||||||
graph_data = generate_graph([c['logged_at'] for c in cadences[::2]], [
|
graph_data = generate_graph([c['logged_at'] for c in cadences[::2]], [
|
||||||
("RPM", [c['rpm'] for c in cadences[::2]])])
|
("RPM", [c['rpm'] for c in cadences[::2]])])
|
||||||
|
|||||||
4
db.py
4
db.py
@@ -40,8 +40,8 @@ class DataBase():
|
|||||||
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)
|
[rpm, device_id], commit=True)
|
||||||
|
|
||||||
def get_all_cadences(self):
|
def get_all_cadences(self, device_id):
|
||||||
return self.execute('SELECT * FROM cadence')
|
return self.execute('SELECT * FROM cadence WHERE device_id = %s', [device_id])
|
||||||
|
|
||||||
def get_devices(self):
|
def get_devices(self):
|
||||||
return self.execute("""
|
return self.execute("""
|
||||||
|
|||||||
@@ -12,15 +12,59 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="h-full w-full bg-gray-50 relative overflow-y-auto">
|
<div class="h-full w-full bg-gray-50 relative overflow-y-auto container mx-auto">
|
||||||
<main>
|
<div class="text-sm breadcrumbs">
|
||||||
<div class="px-4 container mx-auto pt-8" id="container">
|
<nav class="flex" aria-label="Breadcrumb">
|
||||||
<div hx-get="{{ url_for('devices') }}" hx-trigger="load">
|
<ol class="inline-flex items-center space-x-1 md:space-x-3">
|
||||||
</div>
|
<li class="inline-flex items-center">
|
||||||
<div hx-get="{{ url_for('overview') }}" hx-trigger="load, every 2s">
|
<a href="/"
|
||||||
</div>
|
class="inline-flex items-center text-sm font-medium text-gray-700 hover:text-blue-600 dark:text-gray-400 dark:hover:text-white">
|
||||||
</div>
|
<svg aria-hidden="true" class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 20 20"
|
||||||
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z">
|
||||||
|
</path>
|
||||||
|
</svg>
|
||||||
|
Devices
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li aria-current="page">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<svg aria-hidden="true" class="w-6 h-6 text-gray-400" fill="currentColor"
|
||||||
|
viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path fill-rule="evenodd"
|
||||||
|
d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
|
||||||
|
clip-rule="evenodd"></path>
|
||||||
|
</svg>
|
||||||
|
<span class="ml-1 text-sm font-medium text-gray-500 md:ml-2 dark:text-gray-400">Assault
|
||||||
|
Bike</span>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<div class="px-4 pt-8" id="container">
|
||||||
|
<div hx-get="{{ url_for('devices') }}" hx-trigger="load">
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<div role="status">
|
||||||
|
<svg aria-hidden="true"
|
||||||
|
class="w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
|
||||||
|
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||||
|
fill="currentColor" />
|
||||||
|
<path
|
||||||
|
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||||
|
fill="currentFill" />
|
||||||
|
</svg>
|
||||||
|
<span class="sr-only">Loading...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
16
templates/device.html
Normal file
16
templates/device.html
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div hx-get="{{ url_for('overview', device_id=device_id) }}" hx-trigger="load, every 2s">
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<div role="status">
|
||||||
|
<svg aria-hidden="true" class="w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
|
||||||
|
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path
|
||||||
|
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||||
|
fill="currentColor" />
|
||||||
|
<path
|
||||||
|
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||||
|
fill="currentFill" />
|
||||||
|
</svg>
|
||||||
|
<span class="sr-only">Loading...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -1,26 +1,29 @@
|
|||||||
<div class="relative overflow-x-auto">
|
<div class="flex justify-center">
|
||||||
<table class="lg:w-1/4 sm:w-full text-sm text-left text-gray-500 dark:text-gray-400">
|
<div class="relative overflow-x-auto">
|
||||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
<table class="lg:w-1/4 sm:w-full text-sm text-left text-gray-500 dark:text-gray-400">
|
||||||
<tr>
|
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||||
<th scope="col" class="px-6 py-3">
|
<tr>
|
||||||
Name
|
<th scope="col" class="px-6 py-3">
|
||||||
</th>
|
Name
|
||||||
<th scope="col" class="px-6 py-3">
|
</th>
|
||||||
Status
|
<th scope="col" class="px-6 py-3">
|
||||||
</th>
|
Status
|
||||||
</tr>
|
</th>
|
||||||
</thead>
|
</tr>
|
||||||
<tbody>
|
</thead>
|
||||||
{% for d in devices %}
|
<tbody>
|
||||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 cursor-pointer">
|
{% for d in devices %}
|
||||||
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 cursor-pointer"
|
||||||
{{d['name']}}
|
hx-get="{{ url_for('overview', device_id=d['id']) }}" hx-target="#container">
|
||||||
</th>
|
<th scope="row" class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||||
<td class="px-6 py-4">
|
{{d['name']}}
|
||||||
{{d['is_active']}}
|
</th>
|
||||||
</td>
|
<td class="px-6 py-4">
|
||||||
</tr>
|
{{d['is_active']}}
|
||||||
{% endfor %}
|
</td>
|
||||||
</tbody>
|
</tr>
|
||||||
</table>
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user