mirror of
				https://github.com/StefBuwalda/cal_counter.git
				synced 2025-10-29 19:00:00 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stef
					Stef