stats.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const { prisma } = require('../src/models');
  2. async function main() {
  3. const total = await prisma.aiCallLog.count();
  4. console.log('=== AiCallLog 总数: ' + total + ' ===\n');
  5. const byType = await prisma.aiCallLog.groupBy({
  6. by: ['callType', 'provider'],
  7. _count: { id: true },
  8. });
  9. byType.sort((a: any, b: any) => b._count.id - a._count.id);
  10. for (const t of byType) {
  11. console.log(` ${t.callType.padEnd(30)} | ${(t.provider||'-').padEnd(15)} | ${t._count.id} 次`);
  12. }
  13. const success = await prisma.aiCallLog.count({ where: { success: true }});
  14. const failed = await prisma.aiCallLog.count({ where: { success: false }});
  15. console.log(`\n 成功: ${success} | 失败: ${failed}`);
  16. // TTS-only count
  17. const ttsTotal = await prisma.aiCallLog.count({ where: { callType: { startsWith: 'tts' } } });
  18. const llmTotal = await prisma.aiCallLog.count({ where: { callType: { startsWith: 'llm' } } });
  19. console.log(` TTS: ${ttsTotal} | LLM: ${llmTotal}`);
  20. // Show recent entries
  21. const recent = await prisma.aiCallLog.findMany({
  22. orderBy: { createdAt: 'desc' },
  23. take: 10,
  24. select: { callType: true, provider: true, success: true, duration: true, errorMsg: true }
  25. });
  26. console.log('\n=== 最近10条 ===');
  27. for (const r of recent) {
  28. const s = r.success ? '✅' : '❌';
  29. const e = r.errorMsg ? ` (${r.errorMsg.substring(0,50)})` : '';
  30. console.log(` ${s} ${r.callType.padEnd(25)} ${(r.provider||'-').padEnd(12)} ${r.duration}ms${e}`);
  31. }
  32. await prisma.$disconnect();
  33. }
  34. main().catch(e => { console.error(e); process.exit(1); });