From 4d052fe399721a516d2b3bf5a99ebaad481342bf Mon Sep 17 00:00:00 2001 From: Nitin Awari Date: Mon, 6 Apr 2026 16:13:04 +0530 Subject: [PATCH] fix(ctf): align profile/share hint-cost scoring with stats endpoint --- finbot/apps/ctf/routes/profile.py | 8 ++++---- finbot/apps/ctf/routes/share.py | 6 +++--- finbot/apps/ctf/routes/web.py | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/finbot/apps/ctf/routes/profile.py b/finbot/apps/ctf/routes/profile.py index f6bd2ecd..8c9d0c99 100644 --- a/finbot/apps/ctf/routes/profile.py +++ b/finbot/apps/ctf/routes/profile.py @@ -441,18 +441,19 @@ async def get_public_profile( challenge_repo = ChallengeRepository(db) badge_repo = BadgeRepository(db) - # Query completed challenges for this user + # Load all progress rows for consistent profile stats with /api/v1/stats. from finbot.core.data.models import UserChallengeProgress, UserBadge - completed_progress = ( + all_progress = ( db.query(UserChallengeProgress) .filter( UserChallengeProgress.namespace == owner_namespace, UserChallengeProgress.user_id == profile.user_id, - UserChallengeProgress.status == "completed", ) .all() ) + completed_progress = [p for p in all_progress if p.status == "completed"] + hints_cost = sum(p.hints_cost for p in all_progress) # Get badge data earned_badges = ( @@ -468,7 +469,6 @@ async def get_public_profile( # Calculate points challenge_points = challenge_repo.get_effective_points(completed_progress) badge_points = badge_repo.get_total_points(earned_badge_ids) - hints_cost = sum(p.hints_cost for p in completed_progress) total_points = challenge_points + badge_points - hints_cost # Get totals diff --git a/finbot/apps/ctf/routes/share.py b/finbot/apps/ctf/routes/share.py index 73e0fb28..03aee4cd 100644 --- a/finbot/apps/ctf/routes/share.py +++ b/finbot/apps/ctf/routes/share.py @@ -194,15 +194,16 @@ async def get_profile_card( if not profile or not user: raise HTTPException(status_code=404, detail="Profile not found") - completed_progress = ( + all_progress = ( db.query(UserChallengeProgress) .filter( UserChallengeProgress.namespace == user.namespace, UserChallengeProgress.user_id == profile.user_id, - UserChallengeProgress.status == "completed", ) .all() ) + completed_progress = [p for p in all_progress if p.status == "completed"] + hints_cost = sum(p.hints_cost for p in all_progress) earned_badges = ( db.query(UserBadge) @@ -219,7 +220,6 @@ async def get_profile_card( challenge_points = challenge_repo.get_effective_points(completed_progress) earned_badge_ids = [b.badge_id for b in earned_badges] badge_points = badge_repo.get_total_points(earned_badge_ids) - hints_cost = sum(p.hints_cost for p in completed_progress) total_points = challenge_points + badge_points - hints_cost level, level_title = calculate_level(total_points) diff --git a/finbot/apps/ctf/routes/web.py b/finbot/apps/ctf/routes/web.py index a261c1e8..374ec06c 100644 --- a/finbot/apps/ctf/routes/web.py +++ b/finbot/apps/ctf/routes/web.py @@ -152,15 +152,16 @@ async def ctf_public_profile( challenge_repo = ChallengeRepository(db) badge_repo = BadgeRepository(db) - completed_progress = ( + all_progress = ( db.query(UserChallengeProgress) .filter( UserChallengeProgress.namespace == user.namespace, UserChallengeProgress.user_id == profile.user_id, - UserChallengeProgress.status == "completed", ) .all() ) + completed_progress = [p for p in all_progress if p.status == "completed"] + hints_cost = sum(p.hints_cost for p in all_progress) earned_badge_ids = [ b.badge_id for b in db.query(UserBadge) @@ -176,7 +177,7 @@ async def ctf_public_profile( total_points = ( challenge_repo.get_effective_points(completed_progress) + badge_repo.get_total_points(earned_badge_ids) - - sum(p.hints_cost for p in completed_progress) + - hints_cost ) level, level_title = calculate_level(total_points) bio = profile.bio or "AI Security Enthusiast"