★★★★★
#앱별 실전 패턴 · claude-code
[prayer_app] 응답된 기도 통계 (응답률, 응답 시간)
기도제목 중 응답된 것의 통계 (응답률, 평균 응답 시간 등).
#prayer-app#statistics#analytics
기도제목 중 응답된 것의 통계 (응답률, 평균 응답 시간 등).
구현:
1. **응답 기도제목 표시:**
```dart
// Firestore 스키마:
prayers/{prayerId}:
- title
- content
- createdAt
- status: "pending" | "answered"
- answeredAt: (선택사항)
- category: (선택사항)
```
2. **통계 계산:**
```dart
class PrayerStatistics {
static Future<Map<String, dynamic>> getPrayerStats(String userId) async {
final snap = await db.collection('prayers')
.where('userId', isEqualTo: userId)
.get();
int totalPrayers = snap.size;
int answeredPrayers = 0;
int pendingPrayers = 0;
Duration totalDuration = Duration.zero;
for (final doc in snap.docs) {
final prayer = Prayer.fromDoc(doc);
if (prayer.status == 'answered') {
answeredPrayers++;
final duration = prayer.answeredAt.difference(prayer.createdAt);
totalDuration += duration;
} else {
pendingPrayers++;
}
}
final responseRate = totalPrayers > 0
? (answeredPrayers / totalPrayers * 100).toStringAsFixed(1)
: '0';
final avgDaysToAnswer = answeredPrayers > 0
? (totalDuration.inDays / answeredPrayers).toStringAsFixed(1)
: '0';
return {
'totalPrayers': totalPrayers,
'answeredPrayers': answeredPrayers,
'pendingPrayers': pendingPrayers,
'responseRate': '$responseRate%',
'avgDaysToAnswer': '$avgDaysToAnswer일',
};
}
}
```
3. **통계 UI:**
```dart
FutureBuilder<Map<String, dynamic>>(
future: PrayerStatistics.getPrayerStats(currentUserId),
builder: (context, snapshot) {
if (snapshot.hasData) {
final stats = snapshot.data!;
return Column(
children: [
StatCard('응답률', stats['responseRate']),
StatCard('평균 응답 시간', stats['avgDaysToAnswer']),
StatCard('응답된 기도', '${stats['answeredPrayers']}/${stats['totalPrayers']}'),
],
);
}
return LoadingWidget();
},
)
```
구현해줄까?
쓰는 법 — 위 칸에 본인 값을 채우면 아래 프롬프트에 바로 반영돼요. 복사 버튼을 누르면 채워진 그대로 클립보드에 담기니까, claude-code(또는 본인이 쓰는 AI)에 붙여넣기만 하면 됩니다. 변수가 없으면 그냥 복사해서 쓰세요.

