mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 11:19:59 +00:00
Add daily nutrition summary to daily log page
Calculates and displays total calories, protein, carbs, and fat for the current day on the daily log page. Updates both the route logic and the template to show these nutritional totals in a formatted overview.
This commit is contained in:
@@ -77,10 +77,24 @@ def daily_log():
|
|||||||
today = datetime.now(timezone.utc).date()
|
today = datetime.now(timezone.utc).date()
|
||||||
logs_today = current_user.food_logs.filter_by(date_=today).all()
|
logs_today = current_user.food_logs.filter_by(date_=today).all()
|
||||||
logs = [[], [], [], []]
|
logs = [[], [], [], []]
|
||||||
|
calories: float = 0
|
||||||
|
protein: float = 0
|
||||||
|
carbs: float = 0
|
||||||
|
fat: float = 0
|
||||||
for log in logs_today:
|
for log in logs_today:
|
||||||
logs[log.part_of_day].append(log)
|
logs[log.part_of_day].append(log)
|
||||||
|
calories += log.amount * log.food_item.energy_100 / 100
|
||||||
|
protein += log.amount * log.food_item.protein_100 / 100
|
||||||
|
carbs += log.amount * log.food_item.carbs_100 / 100
|
||||||
|
fat += log.amount * log.food_item.fat_100 / 100
|
||||||
return render_template(
|
return render_template(
|
||||||
"daily_log.html", date=(today.strftime("%d/%m/%y")), logs=logs
|
"daily_log.html",
|
||||||
|
date=(today.strftime("%d/%m/%y")),
|
||||||
|
logs=logs,
|
||||||
|
calories=calories,
|
||||||
|
protein=protein,
|
||||||
|
carbs=carbs,
|
||||||
|
fat=fat,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,11 +12,30 @@ Food Nutritional Info
|
|||||||
<div class="mb-4 p-3 border rounded">
|
<div class="mb-4 p-3 border rounded">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2>Daily Overview ({{date}})</h2>
|
<h2>Daily Overview ({{date}})</h2>
|
||||||
<p>Summary info here...</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<!-- Row 1 -->
|
||||||
|
<div class="row justify-content-center text-center mb-2">
|
||||||
|
<div class="col-auto">
|
||||||
|
<strong>Calories:</strong> {{ '%.0f' % calories }} kcal
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<strong>Protein:</strong> {{ '%.1f' % protein }} g
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Row 2 -->
|
||||||
|
<div class="row justify-content-center text-center">
|
||||||
|
<div class="col-auto">
|
||||||
|
<strong>Carbs:</strong> {{ '%.1f' % carbs }} g
|
||||||
|
</div>
|
||||||
|
<div class="col-auto">
|
||||||
|
<strong>Fat:</strong> {{ '%.1f' % fat }} g
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="p-3 border rounded">
|
<div class="p-3 border rounded">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2>Eaten today</h2>
|
<h2>Eaten today</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user