Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions finbot/apps/ctf/routes/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions finbot/apps/ctf/routes/share.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions finbot/apps/ctf/routes/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down
Loading