From e934633370e272f92ff354f0ec043b82cf7dfff6 Mon Sep 17 00:00:00 2001 From: Stef <48526421+StefBuwalda@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:12:19 +0200 Subject: [PATCH 1/2] Development (#12) * 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 * Daily log now sums up amount per item in a day --- application/user/routes.py | 20 +++++++++++++++----- application/user/templates/daily_log.html | 8 ++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/application/user/routes.py b/application/user/routes.py index c4513b2..c50f7d2 100644 --- a/application/user/routes.py +++ b/application/user/routes.py @@ -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 diff --git a/application/user/templates/daily_log.html b/application/user/templates/daily_log.html index 9fd6017..3d4774f 100644 --- a/application/user/templates/daily_log.html +++ b/application/user/templates/daily_log.html @@ -29,22 +29,22 @@
Items Eaten Today
- {% for log in logs %} + {% for food_item, amount in logs %}
- ({{ log.amount | int }}g) + ({{ amount | int }}g) - {{ log.food_item.name }} + {{ food_item.name }} - {{ (log.food_item.energy_100 * log.amount / 100) | int }} kcal + {{ (food_item.energy_100 * amount / 100) | int }} kcal
{% endfor %} From 312eda85dff13328f02baf0af69262e8eb32b5a5 Mon Sep 17 00:00:00 2001 From: Stef Date: Fri, 10 Oct 2025 19:50:18 +0200 Subject: [PATCH 2/2] Can now set macro target --- application/templates/navbar.html | 5 +-- application/templates/new_navbar.html | 1 + application/user/routes.py | 19 +++++++- application/user/templates/settings.html | 30 +++++++++++++ application/utils.py | 31 ++++++++----- forms.py | 24 ++++++++++ migrations/versions/21ec41b645e9_.py | 56 ++++++++++++++++++++++++ models.py | 14 ++++++ 8 files changed, 163 insertions(+), 17 deletions(-) create mode 100644 application/user/templates/settings.html create mode 100644 migrations/versions/21ec41b645e9_.py diff --git a/application/templates/navbar.html b/application/templates/navbar.html index 58625d2..c8c7848 100644 --- a/application/templates/navbar.html +++ b/application/templates/navbar.html @@ -17,15 +17,12 @@