| | |
| | | import { formatTestDuration, parseTestDuration } from './testDataDuration.ts' |
| | | |
| | | const milliFields = new Set([ |
| | | 'current', 'capacity', 'energy', |
| | | 'chargeCapacity', 'dischargeCapacity', 'chargeEnergy', 'dischargeEnergy', |
| | |
| | | |
| | | /** 将编辑输入转回 API 单位;空值及非法输入交由原有校验处理。 */ |
| | | export function toTestApiValue(field: string, value: string): string { |
| | | if (field === 'stepDuration') { |
| | | const seconds = parseTestDuration(value) |
| | | return seconds == null ? '-' : String(seconds) |
| | | } |
| | | if (!milliFields.has(field) || !value.trim() || !Number.isFinite(Number(value))) return value |
| | | return String(Number((Number(value) / 1000).toPrecision(15))) |
| | | } |
| | | |
| | | /** 格式化 API 测量值,先换算再舍入,保留零值与缺失的区别。 */ |
| | | export function formatTestDisplayValue(field: string, value: unknown): string { |
| | | if (field === 'stepDuration' || field === 'relativeTimeSeconds') return formatTestDuration(value) |
| | | if (value === null || value === undefined || String(value).trim() === '') return '-' |
| | | const number = Number(value) |
| | | return Number.isFinite(number) ? toTestDisplayValue(field, number).toFixed(4) : '-' |