55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
|
|
#!/usr/bin/env node
|
|||
|
|
/**
|
|||
|
|
* 最近用 doubao lite 模型跑出来的已完成课程:平均生成时间、90 分位(秒)
|
|||
|
|
* 用法:node scripts/stats-lite-duration.js
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
const { PrismaClient } = require('@prisma/client');
|
|||
|
|
const prisma = new PrismaClient();
|
|||
|
|
|
|||
|
|
async function main() {
|
|||
|
|
const tasks = await prisma.courseGenerationTask.findMany({
|
|||
|
|
where: {
|
|||
|
|
status: 'completed',
|
|||
|
|
modelId: { contains: 'lite' },
|
|||
|
|
},
|
|||
|
|
orderBy: { createdAt: 'desc' },
|
|||
|
|
take: 50,
|
|||
|
|
select: { id: true, courseId: true, modelId: true, createdAt: true, updatedAt: true },
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (tasks.length === 0) {
|
|||
|
|
console.log('没有用 doubao lite 完成的课程');
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const durations = tasks
|
|||
|
|
.map((t) => (t.updatedAt && t.createdAt ? (new Date(t.updatedAt) - new Date(t.createdAt)) / 1000 : null))
|
|||
|
|
.filter((d) => d != null);
|
|||
|
|
|
|||
|
|
if (durations.length === 0) {
|
|||
|
|
console.log('无有效时长数据');
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const sorted = [...durations].sort((a, b) => a - b);
|
|||
|
|
const sum = sorted.reduce((a, b) => a + b, 0);
|
|||
|
|
const avg = sum / sorted.length;
|
|||
|
|
const idx90 = Math.min(Math.ceil(0.9 * sorted.length) - 1, sorted.length - 1);
|
|||
|
|
const p90 = sorted[idx90];
|
|||
|
|
|
|||
|
|
console.log('=== doubao lite 模型:最近已完成课程生成时间 ===\n');
|
|||
|
|
console.log('条数:', sorted.length);
|
|||
|
|
console.log('平均(秒):', Math.round(avg * 10) / 10);
|
|||
|
|
console.log('90分位(秒):', Math.round(p90 * 10) / 10);
|
|||
|
|
console.log('\n明细(秒):', sorted.map((d) => Math.round(d)).join(', '));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
main()
|
|||
|
|
.then(() => process.exit(0))
|
|||
|
|
.catch((e) => {
|
|||
|
|
console.error(e);
|
|||
|
|
process.exit(1);
|
|||
|
|
})
|
|||
|
|
.finally(() => prisma.$disconnect());
|