묵상 통계/히스토리 + routes.rb 관리

ID: d3fcfb29-2e1f-44c4-bd8d-d8456948aaa2

높음 완료

## 목표
묵상 통계 대시보드 + 묵상 히스토리 목록 + routes.rb 통합 관리

## routes.rb 관리 (최우선!)
이 티켓의 에이전트가 routes.rb 유일한 관리자입니다. 아래 라우트를 모두 추가하세요:
```ruby
# Tongtok (tongtok-dev가 구현)
get "tongtok", to: "tongtok#index", as: :tongtok
resources :bible_readings, only: [:create, :destroy]

# Stats & Records
get "stats", to: "stats#show", as: :stats
get "records", to: "records#index", as: :records
```

## 컨트롤러
### StatsController
- show: 묵상 통계 대시보드
- params[:year] (기본 올해)
- UserMeditation 기반 통계 계산:
- 총 묵상 수 (count)
- 완료 묵상 수 (personal_meditation 또는 action_plan이 존재하는 것)
- 완료율 (%)
- 평균 기분 (mood_after 평균, 1-5)
- 연속 묵상일수 (current_streak: 오늘부터 거슬러 올라가며 연속된 날 수)
- 최대 연속일수 (max_streak)
- 월별 묵상 수 배열 (1-12월)
- @stats 해시로 뷰에 전달

### RecordsController
- index: 묵상 기록 목록
- params[:page] (기본 1), params[:month] (YYYY-MM 형태)
- current_user.user_meditations.includes(:qt_content).order(meditation_date: :desc)
- 페이지네이션 (10개/페이지)
- 월별 필터

## 통계 계산 로직 (StatsHelper 또는 concern)
### 연속일수 (Streak) 계산
```ruby
# current_streak: 오늘(또는 가장 최근 묵상일)부터 연속된 날 수
dates = user.user_meditations.where(meditation_date: year_range).pluck(:meditation_date).uniq.sort.reverse
streak = 0
expected = Date.current
dates.each do |d|
break unless d == expected
streak += 1
expected -= 1.day
end

# max_streak: 전체 기간 중 최대 연속
```

### 완료 판단
```ruby
# personal_meditation 또는 action_plan 중 하나에 내용이 있으면 완료
scope :completed, -> { where("personal_meditation IS NOT NULL AND personal_meditation != '' OR action_plan IS NOT NULL AND action_plan != ''") }
```

## 뷰
### stats/show.html.erb
- 제목: "묵상 통계" (h1)
- 연도 선택
- 핵심 지표 카드 4개: 총 묵상, 완료율, 연속일수, 평균 기분
- 월별 묵상 차트 (bar chart - 순수 HTML/CSS 또는 SVG 바 차트)
- 외부 JS 라이브러리 사용 하지 마세요. 순수 Tailwind CSS로 바 차트 구현:
```erb


<% @stats[:monthly_data].each_with_index do |count, i| %>


<% end %>

```
- data-testid="stat-card" (각 지표 카드)
- data-testid="monthly-chart" (월별 차트)

### records/index.html.erb
- 제목: "묵상 기록" (h1)
- 월별 필터 (month input)
- 기록 목록: 날짜, 성경구절, 묵상 내용 미리보기, 기분 이모지
- 페이지네이션 (이전/다음)
- 빈 상태 처리
- data-testid="record-item" (각 기록)

## 테스트
- 컨트롤러 테스트: StatsController (show, 통계값 검증), RecordsController (index, 페이지네이션, 필터)
- 연속일수 계산 정확성 검증

## Fixtures
- 기존 user_meditations.yml에 테스트용 데이터가 있으면 활용
- 없으면 stats 테스트용 fixture 추가 (연속일수 테스트를 위해 여러 날짜의 묵상)

## 파일 담당 (다른 에이전트 파일 수정 금지)
- 수정 가능: config/routes.rb, app/controllers/stats_controller.rb, app/controllers/records_controller.rb, app/views/stats/*, app/views/records/*, test/*, app/models/user_meditation.rb (scope 추가)
- 수정 금지: app/models/bible_reading_log.rb, app/controllers/tongtok_controller.rb, app/controllers/bible_readings_controller.rb, app/views/tongtok/*

첨부 이미지

이미지 추가 (Ctrl+V로 붙여넣기 또는 클릭)

JPEG, PNG, GIF, WebP / 최대 10MB

담당자: stats-dev
생성일: 2026년 03월 02일 03:40

활동 로그

  • 팀리드 상태 변경: 리뷰 → 완료

    2026년 03월 02일 03:49:20

  • S
    stats-dev 상태 변경: 진행 중 → 리뷰

    2026년 03월 02일 03:47:30

  • S
    stats-dev 묵상 통계/히스토리 + routes.rb 구현 완료

    2026년 03월 02일 03:47:29

    상세 보기

    ## 수정/생성 파일 목록

    ### 수정
    - `config/routes.rb` - tongtok, bible_readings, stats, records 라우트 추가
    - `app/models/user_meditation.rb` - completed, by_date_range, recent 스코프 추가
    - `test/models/user_meditation_test.rb` - 스코프 테스트 5개 추가

    ### 신규 생성
    - `app/controllers/stats_controller.rb` - 묵상 통계 (총 묵상, 완료율, 스트릭, 기분 평균, 월별 데이터)
    - `app/controllers/records_controller.rb` - 묵상 기록 목록 (월별 필터, 페이지네이션)
    - `app/views/stats/index.html.erb` - 통계 대시보드 (카드 그리드 + CSS bar chart)
    - `app/views/records/index.html.erb` - 기록 목록 (카드, 필터, 페이지네이션)
    - `test/controllers/stats_controller_test.rb` - 8개 테스트
    - `test/controllers/records_controller_test.rb` - 10개 테스트

    ## 테스트 결과
    - 제 코드 관련: 38 tests, 75 assertions, 0 failures, 0 errors
    - 전체: 262 tests, 602 assertions, 2 failures (tongtok-dev 관련, 제 코드 무관)

  • S
    stats-dev 작업 시작 - 묵상 통계/히스토리 + routes.rb 관리

    2026년 03월 02일 03:44:52

  • S
    stats-dev 티켓 클레임 완료

    2026년 03월 02일 03:44:44