fix
This commit is contained in:
@ -115,4 +115,46 @@ async def get_unique_cards(db: AsyncSession = Depends(get_session)):
|
||||
"unique_id": str(uc.unique_id)
|
||||
}
|
||||
for uc in unique_cards
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
async def get_gacha_stats(db: AsyncSession = Depends(get_session)):
|
||||
"""
|
||||
ガチャ統計情報を取得
|
||||
"""
|
||||
try:
|
||||
card_repo = CardRepository(db)
|
||||
|
||||
# 総ガチャ実行数
|
||||
total_draws = await card_repo.get_total_card_count()
|
||||
|
||||
# レアリティ別カード数
|
||||
cards_by_rarity = await card_repo.get_cards_by_rarity()
|
||||
|
||||
# 成功率計算(簡易版)
|
||||
success_rates = {}
|
||||
if total_draws > 0:
|
||||
for rarity, count in cards_by_rarity.items():
|
||||
success_rates[rarity] = count / total_draws
|
||||
|
||||
# 最近の活動(最新10件)
|
||||
recent_cards = await card_repo.get_recent_cards(limit=10)
|
||||
recent_activity = []
|
||||
for card_data in recent_cards:
|
||||
recent_activity.append({
|
||||
"timestamp": card_data.get("obtained_at", "").isoformat() if card_data.get("obtained_at") else "",
|
||||
"user_did": card_data.get("owner_did", "unknown"),
|
||||
"card_name": f"Card #{card_data.get('card_id', 0)}",
|
||||
"rarity": card_data.get("status", "common")
|
||||
})
|
||||
|
||||
return {
|
||||
"total_draws": total_draws,
|
||||
"cards_by_rarity": cards_by_rarity,
|
||||
"success_rates": success_rates,
|
||||
"recent_activity": recent_activity
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Statistics error: {str(e)}")
|
Reference in New Issue
Block a user