1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
| import assert from 'node:assert/strict'
| import { test } from 'node:test'
| import load from './load-typescript.cjs'
| const { projectCycleChartOption, projectMetrics } = load(new URL('../src/utils/projectCycleChart.ts', import.meta.url))
| const { spliceProjectSeries } = load(new URL('../src/utils/spliceProjectChart.ts', import.meta.url))
| const { measurementChartOption } = load(new URL('../src/utils/reportMeasurementChart.ts', import.meta.url))
|
| test('导入快照只有记录时间时,已有正负电位和温度仍绘成曲线', () => {
| // 当前报表的导入记录有三个辅助测量值,但没有独立采集器时间。
| const items = [{ name: '导入电池', zeroTime: 1000, records: [
| { sourceType: 'SNAPSHOT', deviceTime: 1000, temperature: 25.5, positivePotential: 1.505, negativePotential: -0.105 },
| { sourceType: 'SNAPSHOT', deviceTime: 61000, temperature: 26, positivePotential: 1.6, negativePotential: -0.1 },
| ] }]
| for (const [key, values] of [['temperature', [25.5,26]], ['positiveVoltage', [1.505,1.6]], ['negativeVoltage', [-0.105,-0.1]]]) {
| const option = measurementChartOption({key, unit:key === 'temperature' ? '℃' : 'V'}, items, ['#123456'])
| assert.deepEqual(option.series[0].data, [[0,values[0]],[60,values[1]]], key)
| }
| })
|
| test('辅助测量优先使用独立采集器时间,不为缺少时间或数值的记录补点', () => {
| const records = [
| { sourceType:'SNAPSHOT', deviceTime:1000, collectorDeviceTime:9000, temperature:0 },
| { sourceType:'SNAPSHOT', deviceTime:61000, temperature:null },
| { sourceType:'SNAPSHOT', temperature:26 },
| { sourceType:'COLLECTOR', deviceTime:121000, temperature:27 },
| ]
| const option = measurementChartOption({key:'temperature',unit:'℃'}, [{name:'甲',zeroTime:1000,records}], [])
| assert.deepEqual(option.series[0].data, [[8,0],[60,null]])
| })
|
| test('每个测试电池独立横向接续,同组同电池跨测试不合线且提示原循环', () => {
| const segment = (testId, groupId, originalCycleNos, cyclePositions) => ({ source: { name: `测试${testId}`, group: `组${groupId}`, groupId, batteryNo: '1号', selection: { testId, testBatteryId: testId } }, originalCycleNos, cyclePositions, statistics: Object.fromEntries(originalCycleNos.map(no => [no, { finalVoltage1: no === 3 ? null : 4, dischargeCapacityF: 2 }])) })
| const matrix = { cycleNos: [1, 2, 3, 4, 5], segments: [segment(1, 9, [1,3], {1:1,3:2}), segment(2, 9, [10,11], {10:3,11:4}), segment(3, 10, [1], {1:5})] }
| const before = structuredClone(matrix)
| const series = spliceProjectSeries(matrix)
| assert.equal(series.length, 3)
| assert.equal(new Set(series.map(item => item.key)).size, 3)
| assert.deepEqual(series[0].points.map(point => point.position), [1,2])
| assert.equal(series[0].points[1].source, '测试1 (#1) · 1号 · 原循环3')
| assert.equal(series[1].points[0].source, '测试2 (#2) · 1号 · 原循环10')
| assert.deepEqual(series[1].points.map(point => point.position), [3,4])
| assert.deepEqual(series[2].points.map(point => point.position), [5])
| assert.match(series[0].name, /测试1/)
| assert.match(series[1].name, /测试2/)
| const option = projectCycleChartOption(projectMetrics[0], series, matrix.cycleNos, ['#123456', '#abcdef'], [series[1].key], true)
| assert.deepEqual(option.series[0].data.map(point => point.value), [[1,4],[2,null]])
| assert.deepEqual(option.series[1].data.map(point => point.value), [[3,4],[4,4]])
| assert.equal(option.series[2].showSymbol, true)
| assert.equal(option.legend.selected[series[1].name], false)
| assert.equal(option.series[0].connectNulls, false)
| assert.equal(option.xAxis.name, '累计位置')
| assert.equal(projectCycleChartOption(projectMetrics[1], series, matrix.cycleNos, []).series.length, 0)
| assert.deepEqual(matrix, before)
| })
|
| test('对比来源独立归零并重叠,采集器时间和毫单位保持事实', () => {
| const items = [
| { name: '甲', zeroTime: 1000, records: [{ deviceTime: 1000, current: -0.125, collectorDeviceTime: 9000, temperature: 0 }, { deviceTime: 181000, current: null }] },
| { name: '乙', zeroTime: 3000, records: [{ deviceTime: 3000, current: 0.25 }, { deviceTime: 7203000, current: 0 }] },
| ]
| const option = measurementChartOption({key:'current', unit:'mA'}, items, ['#123456','#abcdef'])
| assert.deepEqual(option.series[0].data, [[0,-125],[180,null]])
| assert.deepEqual(option.series[1].data, [[0,250],[7200,0]])
| const hidden = measurementChartOption({key:'current', unit:'mA'}, [{...items[0], hidden:true}, items[1]], ['#123456','#abcdef'])
| assert.equal(hidden.legend.selected['甲'], false)
| assert.equal(hidden.xAxis.max, option.xAxis.max)
| assert.deepEqual(hidden.yAxis.map(axis => [axis.min, axis.max]), option.yAxis.map(axis => [axis.min, axis.max]))
| const temperature = measurementChartOption({key:'temperature', unit:'℃'}, items, [])
| assert.deepEqual(temperature.series[0].data, [[8,0]])
| })
|
|