Refactor codebase
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from flask import Blueprint, render_template
|
||||
from app.auth import login_required, get_current_user
|
||||
from app.db import query, query_one
|
||||
from app.utils import calculate_streak
|
||||
from app.utils import calculate_streak, calculate_weight_change
|
||||
|
||||
bp = Blueprint("dashboard", __name__)
|
||||
|
||||
@@ -32,11 +32,11 @@ def index():
|
||||
weight_change = None
|
||||
weight_change_pct = None
|
||||
if latest and first_checkin:
|
||||
start_w = float(first_checkin["weight_kg"])
|
||||
current_w = float(latest["weight_kg"])
|
||||
weight_change = round(current_w - start_w, 1)
|
||||
if start_w > 0:
|
||||
weight_change_pct = round((weight_change / start_w) * 100, 1)
|
||||
kg_lost, pct_lost = calculate_weight_change(
|
||||
first_checkin["weight_kg"], latest["weight_kg"]
|
||||
)
|
||||
weight_change = round(-kg_lost, 1) # negative = gained, positive = lost
|
||||
weight_change_pct = round(-pct_lost, 1)
|
||||
|
||||
# Recent check-ins (last 5)
|
||||
recent_checkins = query(
|
||||
@@ -75,4 +75,3 @@ def index():
|
||||
milestones=milestones,
|
||||
streak=streak,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user