Skip to content

Fix incorrect streak calculation always returning minimum 1 #530

Description

@DeFiVC

Bug Description

The streakCount calculation in src/modules/badges/badge.service.ts (lines 213-216) always returns at least 1, even when the user has no activity. This means every user automatically has a "streak" of 1, which is incorrect.

Location

src/modules/badges/badge.service.ts lines 213-216

const streakCount = Math.max(
    completedCourseCount > 0 || quizCompletionCount > 0 ? 1 : 0,
    1,  // This always forces minimum 1!
);

The Problem

The logic is:

  1. If user has completed courses OR quizzes: streakCount = 1
  2. Otherwise: streakCount = 0
  3. Then Math.max(..., 1) forces the minimum to 1

This means:

  • A brand new user with zero activity has a streak of 1
  • The streak badge criteria can never be properly evaluated
  • A badge requiring "3-day streak" would show progress 1/3 for a user with no activity

Recommended Fix

const streakCount = completedCourseCount > 0 || quizCompletionCount > 0 ? 1 : 0;

Or better, implement actual streak calculation based on consecutive days with activity (which is what the getLearningStats method in user.service.ts does).

Acceptance Criteria

  • Remove the Math.max(..., 1) that forces minimum streak to 1
  • A user with no activity should have a streak of 0
  • Consider implementing actual consecutive-day streak calculation

Severity

low - Incorrect badge progress display, but doesn't affect core functionality.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions