mirror of
				https://github.com/StefBuwalda/cal_counter.git
				synced 2025-10-30 19:29:59 +00:00 
			
		
		
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			88f553a08e
			...
			v0.18.0
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | e934633370 | 
| @@ -15,6 +15,7 @@ from datetime import datetime | |||||||
| from application.utils import login_required, macro_arr_to_json | from application.utils import login_required, macro_arr_to_json | ||||||
| from numpy import array | from numpy import array | ||||||
| from zoneinfo import ZoneInfo | from zoneinfo import ZoneInfo | ||||||
|  | from sqlalchemy import func | ||||||
|  |  | ||||||
| user_bp = Blueprint( | user_bp = Blueprint( | ||||||
|     "user", |     "user", | ||||||
| @@ -40,14 +41,23 @@ def daily_log(): | |||||||
|     session["selected_date"] = today.isoformat() |     session["selected_date"] = today.isoformat() | ||||||
|  |  | ||||||
|     # Get logs from today |     # Get logs from today | ||||||
|     logs_today = current_user.food_logs.filter_by( |     logs_today = ( | ||||||
|         date_=today.isoformat() |         current_user.food_logs.join( | ||||||
|     ).all() |             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 |     # calculate macros | ||||||
|     macros = array((0.0, 0.0, 0.0, 0.0)) |     macros = array((0.0, 0.0, 0.0, 0.0)) | ||||||
|     for log in logs_today: |     for food_item, amount in logs_today: | ||||||
|         macros += array(log.food_item.macros()) / 100 * log.amount |         macros += array(food_item.macros()) / 100 * amount | ||||||
|     macros = macro_arr_to_json(macros.tolist()) |     macros = macro_arr_to_json(macros.tolist()) | ||||||
|  |  | ||||||
|     # Render HTML |     # Render HTML | ||||||
|   | |||||||
| @@ -29,22 +29,22 @@ | |||||||
|     <div class="card p-3"> |     <div class="card p-3"> | ||||||
|         <h5>Items Eaten Today</h5> |         <h5>Items Eaten Today</h5> | ||||||
|         <div class="list-group list-group-flush"> |         <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"> |             <div class="list-group-item d-flex align-items-center"> | ||||||
|                 <!-- Weight: fixed width, right-aligned --> |                 <!-- Weight: fixed width, right-aligned --> | ||||||
|                 <span class="text-end" style="width: 6ch; flex-shrink: 0;"> |                 <span class="text-end" style="width: 6ch; flex-shrink: 0;"> | ||||||
|                     ({{ log.amount | int }}g) |                     ({{ amount | int }}g) | ||||||
|                 </span> |                 </span> | ||||||
|  |  | ||||||
|                 <!-- Food name: flexible, truncates if too long --> |                 <!-- Food name: flexible, truncates if too long --> | ||||||
|                 <span class="text-truncate flex-grow-1" |                 <span class="text-truncate flex-grow-1" | ||||||
|                     style="min-width: 0; margin-left: 0.5rem; margin-right: 0.5rem;"> |                     style="min-width: 0; margin-left: 0.5rem; margin-right: 0.5rem;"> | ||||||
|                     {{ log.food_item.name }} |                     {{ food_item.name }} | ||||||
|                 </span> |                 </span> | ||||||
|  |  | ||||||
|                 <!-- kcal: fixed width, right-aligned, pushed to the right --> |                 <!-- kcal: fixed width, right-aligned, pushed to the right --> | ||||||
|                 <span class="d-inline-block text-end ms-auto" style="width: 9ch; flex-shrink: 0;"> |                 <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> |                 </span> | ||||||
|             </div> |             </div> | ||||||
|             {% endfor %} |             {% endfor %} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user