This commit is contained in:
Daniel Bulant 2026-03-14 17:13:35 +01:00
parent c2afc3654c
commit b66cdea753
No known key found for this signature in database
8 changed files with 18 additions and 9 deletions

1
a5/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__

View file

@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS measurements
cursor.execute( cursor.execute(
# sql # sql
"SELECT timestamp, tvoc, co2 FROM measurements ORDER BY timestamp DESC LIMIT ?, ?", "SELECT timestamp, tvoc, co2 FROM measurements ORDER BY timestamp DESC LIMIT ?, ?",
(page_size, page * page_size), (page_size, (page - 1) * page_size),
) )
return cursor.fetchall() return cursor.fetchall()

BIN
a5/greetings.db Normal file

Binary file not shown.

View file

@ -28,7 +28,7 @@ def report() -> ResponseReturnValue:
return "ok", 200 return "ok", 200
@app.route("/stats", methods=["GET"]) @app.route("/", methods=["GET"])
def stats() -> ResponseReturnValue: def stats() -> ResponseReturnValue:
"""Gets overall statistics as well as few recent measurements""" """Gets overall statistics as well as few recent measurements"""
db = get_db() db = get_db()
@ -45,7 +45,7 @@ def measurements() -> ResponseReturnValue:
"""Lists measurements""" """Lists measurements"""
db = get_db() db = get_db()
page_size = 20 page_size = 20
page = request.args["page"] page = request.args["page"] if "page" in request.args else 1
try: try:
page = int(page) page = int(page)
if page < 0: if page < 0:

View file

@ -20,10 +20,10 @@
{% endfor %} {% endfor %}
<div> <div>
{% if has_next_page %} {% if page > 1 %}
<a href="/measurements?page={{page+1}}" class="btn btn-link">Previous page</a> <a href="/measurements?page={{page+1}}" class="btn btn-link">Previous page</a>
{% endif %} {% endif %}
{% if page > 0 %} {% if has_next_page %}
<a href="/measurements?page={{page-1}}" class="btn btn-link">Next page</a> <a href="/measurements?page={{page-1}}" class="btn btn-link">Next page</a>
{% endif %} {% endif %}

View file

@ -1,6 +1,6 @@
{% extends "../base.html.j2" %} {% extends "base.html.j2" %}
{% block title %}Overview{% endblock %} {% block title %}Overview{% endblock %}
{% block description %}Overview of a CO2 and TVOC sensor data.{% endblock %} {% block description %}Overview of a CO2 and TVOC sensor data.{% endblock %}
{% block content %} {% block content %}
{% include "../block/index.html.j2" %} {% include "block/index.html.j2" %}
{% endblock %} {% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "../base.html.j2" %} {% extends "base.html.j2" %}
{% block title %}Measurements{% endblock %} {% block title %}Measurements{% endblock %}
{% block description %}List of measurements{% endblock %} {% block description %}List of measurements{% endblock %}
{% block content %} {% block content %}
{% include "../block/measurements.html.j2" %} {% include "block/measurements.html.j2" %}
{% endblock %} {% endblock %}

8
a5/uv.lock Normal file
View file

@ -0,0 +1,8 @@
version = 1
revision = 3
requires-python = ">=3.13"
[[package]]
name = "a5"
version = "0.1.0"
source = { virtual = "." }