Skip to content

chore: 통계 시간 단위를 ms로 변경#65

Merged
kon28289 merged 3 commits intodevfrom
chore/statistics
Jan 16, 2026
Merged

chore: 통계 시간 단위를 ms로 변경#65
kon28289 merged 3 commits intodevfrom
chore/statistics

Conversation

@kon28289
Copy link
Contributor

@kon28289 kon28289 commented Jan 16, 2026

🚀 1. 개요

  • 통계에서 제공하는 데이터의 시간 단위를 ms로 변경합니다.

📝 2. 주요 변경 사항

  • StudySessionRepository에 존재하던 통계 관련 코드를 StatisticsRepository로 분리합니다.
  • dto의 필드 명이 전달하는 정보를 명확하게 하기 위해 dto 명을 변경합니다.

📸 3. 스크린샷 (API 테스트 결과)

Summary by CodeRabbit

릴리스 노트

  • 리팩터링
    • 통계 기능을 위한 전담 저장소 도입으로 코드 구조 개선
    • 시간 단위를 밀리초 기준으로 통일하여 통계 계산의 정확도 향상
    • 일일, 주간, 월간 학습 통계 조회 로직 재구성

✏️ Tip: You can customize this high-level summary in your review settings.

@kon28289 kon28289 requested a review from Juhye0k January 16, 2026 06:28
@kon28289 kon28289 self-assigned this Jan 16, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

Walkthrough

통계 기능의 저장소 계층을 리팩터링하여 StudySessionRepository의 복잡한 통계 쿼리를 새로운 StatisticsRepository로 이동하고, 시간 단위 메서드명을 초(seconds)에서 밀리초(milliseconds)로 일관되게 변경했습니다.

Changes

Cohort / File(s) 변경 요약
시간 단위 DTO 업데이트
src/main/java/com/gpt/geumpumtabackend/statistics/dto/DayMaxFocusAndFullTimeStatistics.java, src/main/java/com/gpt/geumpumtabackend/statistics/dto/MonthlyStatistics.java, src/main/java/com/gpt/geumpumtabackend/statistics/dto/WeeklyStatistics.java, src/main/java/com/gpt/geumpumtabackend/statistics/dto/TwoHourSlotStatistics.java
반환 타입 유지 하며 메서드명 변경: *Seconds()*Millis() (총 4개 DTO, 6개 메서드)
저장소 리팩터링
src/main/java/com/gpt/geumpumtabackend/statistics/repository/StatisticsRepository.java
새로운 JpaRepository 인터페이스 추가: 5개의 네이티브 SQL 쿼리 메서드 (getTwoHourSlotStats, getDayMaxFocusAndFullTime, getWeeklyStatistics, getMonthlyStatistics, getGrassStatistics) 포함
기존 저장소 정리
src/main/java/com/gpt/geumpumtabackend/study/repository/StudySessionRepository.java
5개의 통계 쿼리 메서드 제거 (getTwoHourSlotStats, getDayMaxFocusAndFullTime, getWeeklyStatistics, getMonthlyStatistics, getGrassStatistics)
서비스 의존성 업데이트
src/main/java/com/gpt/geumpumtabackend/statistics/service/StatisticsService.java
주입 저장소 타입 변경: StudySessionRepository → StatisticsRepository, 모든 호출 지점 업데이트

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Juhye0k

Poem

🐰 통계의 집을 새로 짓고,
초에서 밀리초로 옮겨가며,
저장소 정리는 마무리 지으니,
더욱 정확한 시간들이여,
이제 함께 춤을 춥니다! ⏱️✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed 제목은 PR의 주요 변경 사항을 명확하게 요약하고 있습니다: 통계 시간 단위를 밀리초로 변경하는 작업입니다.
Description check ✅ Passed PR 설명이 템플릿의 세 섹션(개요, 주요 변경 사항, 스크린샷)을 모두 포함하고 있으며, 변경 목적과 주요 내용이 충분히 기술되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@src/main/java/com/gpt/geumpumtabackend/statistics/repository/StatisticsRepository.java`:
- Around line 53-57: 메서드 getTwoHourSlotStats의 선언에 불필요하게 포함된 파라미터
`@Param`("dayEnd") LocalDateTime dayEnd을 제거하세요: TwoHourSlotStatistics
getTwoHourSlotStats(`@Param`("dayStart") LocalDateTime dayStart, `@Param`("userId")
Long userId); 또한 이 시그니처 변경에 맞춰 해당 메서드를 호출하는 모든 위치(및 관련 테스트)에서 dayEnd 인자를 제거하거나,
만약 실제로 dayEnd를 쿼리에서 사용하려는 의도라면 현재 쿼리 내에서 dayEnd를 참조하도록 수정해 일관성을 유지하세요.
🧹 Nitpick comments (3)
src/main/java/com/gpt/geumpumtabackend/statistics/dto/TwoHourSlotStatistics.java (1)

6-6: 네이밍 일관성 검토 권장.

다른 DTO들은 *Millis 접미사를 사용하는 반면(getTotalStudyMillis, getAverageDailyMillis 등), 이 메서드는 getMillisecondsStudied로 다른 패턴을 사용합니다. 일관성을 위해 getStudiedMillis 또는 getSlotMillis로 변경하는 것을 고려해 주세요.

♻️ 일관된 네이밍 제안
-    Integer getMillisecondsStudied();
+    Integer getStudiedMillis();
src/main/java/com/gpt/geumpumtabackend/statistics/repository/StatisticsRepository.java (2)

106-120: 불필요한 COALESCE 사용.

Line 109의 COALESCE(s.end_time, d.day_end)는 실제로 실행되지 않는 코드입니다. Line 120의 JOIN 조건 s.end_time > d.day_start에서 이미 end_time이 NULL인 세션이 필터링되므로, SELECT 절에서 s.end_time은 항상 non-NULL입니다. 코드 가독성을 위해 COALESCE를 제거하는 것이 좋습니다.

Based on learnings, 완료된 세션만 통계에 포함되어야 하며, 현재 JOIN 조건으로 이 요구사항이 충족됩니다.

♻️ 제안: 불필요한 COALESCE 제거
                   GREATEST(
                     0,
                     TIMESTAMPDIFF(
                       MICROSECOND,
                       GREATEST(s.start_time, d.day_start),
-                      LEAST(COALESCE(s.end_time, d.day_end), d.day_end)
+                      LEAST(s.end_time, d.day_end)
                     ) / 1000
                   )

194-207: 주간 통계와 동일한 불필요한 COALESCE 패턴.

Line 197의 COALESCE(s.end_time, d.day_end)도 주간 통계와 동일하게 불필요한 코드입니다. Line 207의 JOIN 조건에서 NULL end_time이 이미 제외됩니다.

♻️ 제안: 불필요한 COALESCE 제거
                   GREATEST(
                     0,
                     TIMESTAMPDIFF(
                       MICROSECOND,
                       GREATEST(s.start_time, d.day_start),
-                      LEAST(COALESCE(s.end_time, d.day_end), d.day_end)
+                      LEAST(s.end_time, d.day_end)
                     ) / 1000
                   )
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b23cd2a and 23cc938.

📒 Files selected for processing (7)
  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/DayMaxFocusAndFullTimeStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/MonthlyStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/TwoHourSlotStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/WeeklyStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/repository/StatisticsRepository.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/service/StatisticsService.java
  • src/main/java/com/gpt/geumpumtabackend/study/repository/StudySessionRepository.java
💤 Files with no reviewable changes (1)
  • src/main/java/com/gpt/geumpumtabackend/study/repository/StudySessionRepository.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-11T11:48:29.664Z
Learnt from: kon28289
Repo: Geumpumta/backend PR: 16
File: src/main/java/com/gpt/geumpumtabackend/study/repository/StudySessionRepository.java:264-287
Timestamp: 2025-11-11T11:48:29.664Z
Learning: In the Geumpumta backend project, study session statistics (daily, weekly, monthly, grass) intentionally exclude in-progress sessions where end_time is NULL. Only completed sessions (with non-null end_time) should be counted in the statistics calculations.

Applied to files:

  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/WeeklyStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/DayMaxFocusAndFullTimeStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/service/StatisticsService.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/dto/MonthlyStatistics.java
  • src/main/java/com/gpt/geumpumtabackend/statistics/repository/StatisticsRepository.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test (Gradle + Testcontainers)
🔇 Additional comments (8)
src/main/java/com/gpt/geumpumtabackend/statistics/dto/WeeklyStatistics.java (1)

4-6: LGTM!

타입 선택이 적절합니다. Long은 주간 총 밀리초를 안전하게 담을 수 있고, Integer는 일일 평균(최대 ~86,400,000ms)에 충분합니다.

src/main/java/com/gpt/geumpumtabackend/statistics/dto/DayMaxFocusAndFullTimeStatistics.java (1)

4-6: LGTM!

일일 통계이므로 Integer 타입이 적절합니다. 하루 최대 밀리초(86,400,000ms)가 Integer.MAX_VALUE보다 훨씬 작습니다.

src/main/java/com/gpt/geumpumtabackend/statistics/service/StatisticsService.java (2)

31-31: LGTM! 통계 책임 분리가 잘 되었습니다.

StudySessionRepository에서 StatisticsRepository로의 의존성 변경은 단일 책임 원칙(SRP)에 부합하는 좋은 리팩토링입니다.


140-145: 저장소 메서드 시그니처 확인됨 - 이슈 없음

StatisticsRepository.getMonthlyStatistics의 실제 시그니처는 2개의 파라미터(LocalDateTime monthStart, Long userId)를 받으며, 서비스에서 정확히 2개의 인자(monthStart, targetUserId)를 전달하고 있습니다. 시그니처가 일치하므로 컴파일 오류가 발생하지 않습니다.

Likely an incorrect or invalid review comment.

src/main/java/com/gpt/geumpumtabackend/statistics/dto/MonthlyStatistics.java (1)

4-7: LGTM!

타입 선택과 주석이 잘 작성되었습니다. Long은 월간 총 밀리초에 적합하고, Integer는 일일 평균 및 일수 카운트에 충분합니다.

src/main/java/com/gpt/geumpumtabackend/statistics/repository/StatisticsRepository.java (3)

1-13: LGTM!

패키지 구조와 import가 적절합니다. JpaRepository<StudySession, Long>를 확장하여 통계 전용 리포지토리로 분리한 것은 단일 책임 원칙(SRP)에 부합합니다.


60-84: LGTM!

일일 총 공부시간과 최대 집중시간을 계산하는 쿼리가 올바르게 구현되었습니다. s.end_time > :dayStart 조건으로 진행 중인 세션(NULL end_time)이 자연스럽게 제외됩니다.


268-276: 명시적인 NULL 체크로 완료된 세션만 필터링 - 좋습니다!

s.end_time IS NOT NULL 조건을 명시적으로 사용하여 진행 중인 세션을 제외한 것이 좋습니다. 다른 쿼리들도 이와 같이 명시적인 조건을 사용하면 의도가 더 명확해집니다.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@Juhye0k Juhye0k left a comment

Choose a reason for hiding this comment

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

LGTM!

@kon28289 kon28289 merged commit 97bf643 into dev Jan 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants