移除导入自动补值并仅使用文件中的测量值
按用户澄清将开发测试值放入独立 Excel 副本,导入缺列和空单元格保持空值。补充文件值保留和全样例浏览器逐行核对,转换测试与生产构建通过。
| | |
| | | const duration = /^(\d+):([0-5]\d):([0-5]\d)(?:\.(\d{1,3}))?$/.exec(value.trim()) |
| | | value = duration ? Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3]) + Number((duration[4] || '').padEnd(3, '0')) / 1000 : NaN |
| | | } |
| | | if (party && ['temperature', 'positivePotential', 'negativePotential'].includes(field) && (value === undefined || value === '')) { |
| | | // 开发测试值只在甲方实时表缺值时补齐,按记录序号确定以保持重复导入幂等。 |
| | | const offset = Number(raw['记录序号']) % 10 |
| | | value = field === 'temperature' ? 25 + offset / 10 : field === 'positivePotential' ? (1500 + offset) / 1000 : (-100 - offset) / 1000 |
| | | } |
| | | const text = String(value ?? '').trim() |
| | | const fail = (reason: string) => errors.push(`第${sourceRow}行,列「${header}」:${reason}`) |
| | | if (['recordNo', 'batteryNo', 'stepName'].includes(field)) { |
| | |
| | | const imported = JSON.parse(calls.at(-1).changesSummary) |
| | | assert.equal(imported[0].batteryNo, 'BAT-1') |
| | | if (process.env.PARTY_EXCEL) assert.equal(imported.length, { REALTIME: 7605, STEP: 129, CYCLE: 33 }[type]) |
| | | if (process.env.PARTY_EXCEL && type === 'REALTIME') { |
| | | const source = XLSX.readFile(process.env.PARTY_EXCEL).Sheets.record |
| | | const fields = ['temperature', 'positivePotential', 'negativePotential'] |
| | | for (let row = 0; row < imported.length; row++) { |
| | | assert.deepEqual(fields.map(field => imported[row][field]), fields.map((_, column) => |
| | | source[XLSX.utils.encode_cell({ r: row + 1, c: column + 10 })]?.v ?? null)) |
| | | } |
| | | } |
| | | } |
| | | await page.goto(`${origin}/test-list/1/console/data/import?dataType=REALTIME`) |
| | | await page.locator('input[type=file]').setInputFiles(standardFile('REALTIME', true)) |
| | |
| | | assert.equal(rows[1].data.capacity, 8.5122) |
| | | assert.equal(rows[1].data.energy, 9.7178) |
| | | for (const field of ['temperature', 'positivePotential', 'negativePotential']) { |
| | | assert.equal(typeof rows[0].data[field], 'number') |
| | | assert.equal(rows[0].data[field], parseConsoleImport(partyWorkbook(), 'REALTIME', ['BAT-1'], 'BAT-1')[0].data[field]) |
| | | assert.equal(rows[0].data[field], null) |
| | | } |
| | | }) |
| | | |
| | | test('采集器三项测量只读取 Excel 已有值,缺列或空格不生成数值', () => { |
| | | const workbook = partyWorkbook() |
| | | XLSX.utils.sheet_add_aoa(workbook.Sheets.record, [ |
| | | ['温度(℃)', '正电位(V)', '负电位(V)'], |
| | | [32.75, 1.8234, -0.2045], |
| | | ['', '', ''], |
| | | ], { origin: 'K1' }) |
| | | const rows = parseConsoleImport(workbook, 'REALTIME', ['BAT-1']) |
| | | assert.deepEqual(rows[0].errors, []) |
| | | assert.deepEqual(['temperature', 'positivePotential', 'negativePotential'].map(field => rows[0].data[field]), [32.75, 1.8234, -0.2045]) |
| | | assert.deepEqual(['temperature', 'positivePotential', 'negativePotential'].map(field => rows[1].data[field]), [null, null, null]) |
| | | }) |
| | | |
| | | test('标准模板兼容文本、毫秒时间戳和 Excel 日期系统,并拒绝非法日期', () => { |
| | | const make = (time, date1904 = false) => { |
| | | const workbook = XLSX.utils.book_new() |