|
1 | 1 | import logging |
2 | 2 | from django.db.models import Sum, Max |
3 | 3 | from django.db import transaction |
4 | | -from core.models import UserActivity, UserSolvedProblem, UserProgress, PracticeDetail |
| 4 | +from core.models import UserActivity, UserSolvedProblem, UserProgress, PracticeDetail, UserWarsScore |
5 | 5 |
|
6 | 6 | logger = logging.getLogger(__name__) |
7 | 7 |
|
@@ -38,12 +38,20 @@ def save_user_problem_record(user_profile, detail_id, score, submitted_data): |
38 | 38 | # [2026-02-18 상세] 2. 누적 포인트 업데이트 |
39 | 39 | # - 단순 합산이 아닌, 동일 문제에 대해 여러 번 기록이 있을 경우 '최고 점수'만 반영함 |
40 | 40 | # - values('practice_detail')로 그룹화하여 문제별 Max 점수를 구한 뒤 최종 합산(Sum)함 |
41 | | - total_points_data = UserSolvedProblem.objects.filter(user=user_profile) \ |
| 41 | + practice_points_data = UserSolvedProblem.objects.filter(user=user_profile) \ |
42 | 42 | .values('practice_detail') \ |
43 | 43 | .annotate(max_score=Max('score')) \ |
44 | 44 | .aggregate(total=Sum('max_score')) |
45 | | - |
46 | | - total_points = total_points_data['total'] or 0 |
| 45 | + practice_points = practice_points_data['total'] or 0 |
| 46 | + |
| 47 | + # [2026-03-04] Wars 게임 점수도 합산 (game_type별 최고점) |
| 48 | + wars_points_data = UserWarsScore.objects.filter(user=user_profile) \ |
| 49 | + .values('game_type') \ |
| 50 | + .annotate(max_score=Max('score')) \ |
| 51 | + .aggregate(total=Sum('max_score')) |
| 52 | + wars_points = wars_points_data['total'] or 0 |
| 53 | + |
| 54 | + total_points = practice_points + wars_points |
47 | 55 |
|
48 | 56 | # [2026-02-18 상세] 유저 활동 정보(UserActivity) 갱신 또는 생성 |
49 | 57 | activity, _ = UserActivity.objects.get_or_create(user=user_profile) |
|
0 commit comments