Skip to content

[FIX] completion_rate 100% 초과 방지 및 진행률 계산 개선#111

Merged
b1351b1 merged 15 commits into
devfrom
feature/be-rv
Dec 9, 2025
Merged

[FIX] completion_rate 100% 초과 방지 및 진행률 계산 개선#111
b1351b1 merged 15 commits into
devfrom
feature/be-rv

Conversation

@b1351b1

@b1351b1 b1351b1 commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

개요

  • 강의 진행률 API에서 completion_rate가 100%를 초과하는 버그 수정

변경사항

1. DB 스키마 변경

  • Progress 모델에 unique_watched_seconds 필드 추가
    • watched_seconds: 총 시청 시간 (반복 재생 포함 누적) - 분석용
    • unique_watched_seconds: 유니크 시청 시간 - 진행률 계산용
  • Alembic 마이그레이션 파일 생성

2. 진행률 계산 로직 개선

  • completion_rate 계산 시 unique_watched_seconds 사용
  • completion_ratemin(completion_rate, 100.0)으로 100% 이하로 제한
  • last_positionduration_seconds 이하로 제한

3. 수정된 파일

  • app/models/progress.py: unique_watched_seconds 필드 추가
  • app/services/enrollment_service.py: 진행률 계산 로직 전면 개선
  • alembic/versions/a3a28d52a24f_add_unique_watched_seconds_to_progress.py:
    마이그레이션 파일

4. 기대 효과

  • completion_rate가 항상 0~100% 범위 내에서 반환
  • 반복 재생 시에도 정확한 진행률 표시
  • 학습 분석(watched_seconds)과 진행률(unique_watched_seconds) 분리로 데이터
    활용도 향상

관련 이슈

**Closes #105

@b1351b1
b1351b1 requested a review from Copilot December 9, 2025 12:01
@b1351b1 b1351b1 self-assigned this Dec 9, 2025
@b1351b1 b1351b1 added the fix 기존 코드의 버그 또는 오류를 수정하는 작업. label Dec 9, 2025
@b1351b1 b1351b1 added the area:backend 백엔드(BE) 영역의 로직, DB, API 서버 관련 작업. #531 label Dec 9, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a bug where completion_rate could exceed 100% by introducing a new database field unique_watched_seconds to track the unique (non-repeated) watch time for progress calculations, while preserving watched_seconds for analytics purposes. The PR adds proper capping logic to ensure completion rates never exceed 100%.

Key Changes:

  • Added unique_watched_seconds field to the Progress model with an Alembic migration
  • Updated progress calculation logic to use unique_watched_seconds instead of watched_seconds
  • Applied min(completion_rate, 100.0) capping throughout the codebase

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
app/models/progress.py Added unique_watched_seconds field to track unique watch time for progress calculations
app/services/enrollment_service.py Updated all progress calculation functions to use unique_watched_seconds and apply 100% capping
alembic/versions/a3a28d52a24f_add_unique_watched_seconds_to_progress.py Database migration to add the new field with default values

Critical Issues Found:

  1. Logic Bug: The unique_watched_seconds calculation (= last_position) will cause the value to decrease when users rewind videos, which defeats its purpose. It should use max(existing_value, last_position) to only track forward progress.
  2. Migration Data Issue: Existing records are migrated with unique_watched_seconds = watched_seconds, which may still allow >100% completion rates until users update their progress.
  3. Documentation Mismatch: Comments suggest a calculation is happening, but the implementation is just a direct assignment that doesn't properly handle the "unique" aspect.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread alembic/versions/a3a28d52a24f_add_unique_watched_seconds_to_progress.py Outdated
Comment thread app/services/enrollment_service.py Outdated
Comment thread app/services/enrollment_service.py Outdated
Comment thread app/services/enrollment_service.py Outdated
Comment thread app/services/enrollment_service.py Outdated
Comment thread app/services/enrollment_service.py Outdated
Comment on lines +85 to +87
# unique_watched_seconds 계산 (진행률 계산용)
# last_position을 기준으로 유니크 시청 시간 계산
unique_watched_seconds = last_position

Copilot AI Dec 9, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Logic Bug: The unique_watched_seconds calculation is incorrect. Setting it equal to last_position means that if a user watches a video from the beginning multiple times, the unique watched seconds won't update properly.

For example:

  • User watches 0-100 seconds → last_position=100, unique_watched_seconds=100 ✓
  • User rewinds and watches 0-150 seconds → last_position=150, unique_watched_seconds=150 ✓
  • User rewinds to 50 and watches to 120 → last_position=120, unique_watched_seconds=120 ✗ (should still be 150)

The current implementation only tracks the furthest position reached (last_position), which already serves that purpose. unique_watched_seconds should be calculated differently (e.g., tracking unique segments watched) or should be set to max(unique_watched_seconds, last_position) when updating existing records to preserve the maximum progress.

Copilot uses AI. Check for mistakes.
Comment thread app/services/enrollment_service.py Outdated
b1351b1 and others added 6 commits December 9, 2025 21:42
…ogress.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

@b1351b1 I've opened a new pull request, #112, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 3 commits December 9, 2025 12:47
…on tracking

Co-authored-by: b1351b1 <223806567+b1351b1@users.noreply.github.com>
Clarify unique_watched_seconds tracks maximum position, not unique watch time

Copilot AI commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

@b1351b1 I've opened a new pull request, #113, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits December 9, 2025 12:57
…ched_seconds

Co-authored-by: b1351b1 <223806567+b1351b1@users.noreply.github.com>
[WIP] Address feedback on completion rate improvements
@b1351b1

b1351b1 commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copilot AI commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

@b1351b1 I've opened a new pull request, #114, to work on those changes. Once the pull request is ready, I'll request review from you.

[WIP] Fix completion rate exceeding 100% and improve calculation
@b1351b1
b1351b1 merged commit 1f50e54 into dev Dec 9, 2025
@b1351b1 b1351b1 moved this to Done in bootrun project Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend 백엔드(BE) 영역의 로직, DB, API 서버 관련 작업. #531 fix 기존 코드의 버그 또는 오류를 수정하는 작업.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FIX] completion_rate 반환 값 버그 수정

3 participants