5 Commits

Author SHA1 Message Date
Stef
7fb75d46af Merge branch 'main' into development 2025-10-08 19:10:34 +02:00
70eef5b9a2 Daily log now sums up amount per item in a day 2025-10-08 19:08:44 +02:00
Stef
88f553a08e New webpage structure, not yet finished. Change password implemented again (#11)
* Adjusted GUI of daily dashboard to better deal with float values

* Change password + New base (#10)

* created a new Base template to test with

* Changed out the base and added a new password page

* Password change works, UI needs redisgn
2025-10-08 15:38:40 +02:00
Stef
573437f4cf Adjusted GUI of daily dashboard to better deal with float values (#9) 2025-10-08 11:56:20 +02:00
4bc319c32a Revert "Update requirements.txt"
This reverts commit 24a1757166.
2025-08-21 17:05:32 +02:00
3 changed files with 19 additions and 13 deletions

View File

@@ -15,6 +15,7 @@ from datetime import datetime
from application.utils import login_required, macro_arr_to_json
from numpy import array
from zoneinfo import ZoneInfo
from sqlalchemy import func
user_bp = Blueprint(
"user",
@@ -40,14 +41,23 @@ def daily_log():
session["selected_date"] = today.isoformat()
# Get logs from today
logs_today = current_user.food_logs.filter_by(
date_=today.isoformat()
).all()
logs_today = (
current_user.food_logs.join(
FoodItem, FoodItem.id == FoodLog.food_item_id
)
.filter(FoodLog.date_ == today)
.group_by(FoodItem.id)
.with_entities(
FoodItem, # the full object
func.sum(FoodLog.amount).label("total_amount"),
)
.all()
)
# calculate macros
macros = array((0.0, 0.0, 0.0, 0.0))
for log in logs_today:
macros += array(log.food_item.macros()) / 100 * log.amount
for food_item, amount in logs_today:
macros += array(food_item.macros()) / 100 * amount
macros = macro_arr_to_json(macros.tolist())
# Render HTML

View File

@@ -29,22 +29,22 @@
<div class="card p-3">
<h5>Items Eaten Today</h5>
<div class="list-group list-group-flush">
{% for log in logs %}
{% for food_item, amount in logs %}
<div class="list-group-item d-flex align-items-center">
<!-- Weight: fixed width, right-aligned -->
<span class="text-end" style="width: 6ch; flex-shrink: 0;">
({{ log.amount | int }}g)
({{ amount | int }}g)
</span>
<!-- Food name: flexible, truncates if too long -->
<span class="text-truncate flex-grow-1"
style="min-width: 0; margin-left: 0.5rem; margin-right: 0.5rem;">
{{ log.food_item.name }}
{{ food_item.name }}
</span>
<!-- kcal: fixed width, right-aligned, pushed to the right -->
<span class="d-inline-block text-end ms-auto" style="width: 9ch; flex-shrink: 0;">
{{ (log.food_item.energy_100 * log.amount / 100) | int }} kcal
{{ (food_item.energy_100 * amount / 100) | int }} kcal
</span>
</div>
{% endfor %}

View File

@@ -1,7 +1,3 @@
# For Python >=3.8, importlib-metadata backport is not needed
python_version >= "3.12.10"
# Package requirements
alembic==1.16.4
blinker==1.9.0
click==8.2.1