Refactor codebase
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from flask import Blueprint, render_template
|
||||
from app.auth import login_required
|
||||
from app.db import query, query_one
|
||||
from app import SYDNEY_TZ
|
||||
from app.utils import calculate_streak
|
||||
from app.config import SYDNEY_TZ
|
||||
from app.utils import calculate_streak, calculate_weight_change
|
||||
from datetime import timezone
|
||||
|
||||
bp = Blueprint("leaderboard", __name__)
|
||||
@@ -33,13 +33,7 @@ def index():
|
||||
for u in users:
|
||||
start_w = float(u["starting_weight_kg"] or u["first_weight"] or 0)
|
||||
current_w = float(u["current_weight"] or start_w)
|
||||
|
||||
if start_w > 0:
|
||||
weight_lost = start_w - current_w
|
||||
pct_lost = round((weight_lost / start_w) * 100, 1)
|
||||
else:
|
||||
weight_lost = 0
|
||||
pct_lost = 0
|
||||
weight_lost, pct_lost = calculate_weight_change(start_w, current_w)
|
||||
|
||||
goal = float(u["goal_weight_kg"]) if u["goal_weight_kg"] else None
|
||||
goal_progress = None
|
||||
@@ -50,7 +44,7 @@ def index():
|
||||
streak = calculate_streak(u["id"])
|
||||
ranked.append({
|
||||
**u,
|
||||
"weight_lost": round(weight_lost, 1),
|
||||
"weight_lost": weight_lost,
|
||||
"pct_lost": pct_lost,
|
||||
"goal_progress": goal_progress,
|
||||
"streak": streak["current"],
|
||||
|
||||
Reference in New Issue
Block a user