优化采样溢出处理,调整时间轴计算逻辑,确保在采样溢出时使用固定时间;更新显示信息以提示用户采样溢出情况

This commit is contained in:
feie9456 2025-11-18 21:00:07 +08:00
parent 2acda5959a
commit 491c42b321
2 changed files with 23 additions and 3 deletions

View File

@ -57,6 +57,8 @@ export async function POST(req: NextRequest) {
const dtMs = Number((r.rec_end_ms as bigint) - (r.rec_start_ms as bigint))
if (Number.isFinite(dtMs) && dtMs > 0) stepMs = dtMs / r.sample_count
}
// 采样溢出时强制 1ms 步长(与 16.384s/16384 对齐)
if (r.sample_count >= 16384) stepMs = 1
const hasFit = r.fit_a != null
for (let i = 0; i < r.code_data.length; i++) {
const t = (i * stepMs).toFixed(3)

View File

@ -117,8 +117,10 @@ export default function Page({ params }: { params: Promise<{ id: string }> }) {
const timeAxis = useMemo(() => {
if (!rec) return [] as number[]
// 使用秒为单位保留3位小数
const step = rec.sampleCount > 0 ? rec.duration / rec.sampleCount : 0
// 使用秒为单位保留3位小数若采样溢出固定为 16.384s
const overflow = rec.sampleCount >= 16384
const effectiveDuration = overflow ? 16.384 : rec.duration
const step = rec.sampleCount > 0 ? effectiveDuration / rec.sampleCount : 0
return Array.from({ length: rec.sampleCount }, (_, i) => +(i * step).toFixed(3))
}, [rec])
@ -198,7 +200,23 @@ export default function Page({ params }: { params: Promise<{ id: string }> }) {
</div>
<div className="rounded-lg border p-3 sm:p-4 dark:border-zinc-800">
<div className="text-sm text-zinc-500"></div>
<div className="mt-1 text-lg">{rec.sampleCount} · {rec.duration.toFixed(3)} s · {(rec.sampleCount / rec.duration).toFixed(2)} Hz</div>
{(() => {
const overflow = rec.sampleCount >= 16384
const effectiveDuration = overflow ? 16.384 : rec.duration
const hz = effectiveDuration > 0 ? (rec.sampleCount / effectiveDuration) : 0
return (
<div className="mt-1 text-lg">
{rec.sampleCount} ·{' '}
<span
className={overflow ? 'text-red-600 dark:text-red-400' : ''}
title={overflow ? '采样溢出,时间将不准确' : undefined}
>
{effectiveDuration.toFixed(3)} s
</span>
{' '}· {hz.toFixed(2)} Hz
</div>
)
})()}
</div>
<div className="rounded-lg border p-3 sm:p-4 dark:border-zinc-800">
<div className="text-sm text-zinc-500"></div>