特性点顺序问题
This commit is contained in:
@@ -50,11 +50,20 @@ interface ChartPoint {
|
||||
status: ChartPointStatus
|
||||
}
|
||||
|
||||
interface CharacteristicCurvePoint {
|
||||
duration: number
|
||||
residualVoltage: number
|
||||
time: string | null
|
||||
timeMs: number | null
|
||||
}
|
||||
|
||||
interface NormalizedTolerantPoint {
|
||||
duration: number
|
||||
residualVoltage: number
|
||||
tolerant: number | null
|
||||
status: ChartPointStatus
|
||||
time: string | null
|
||||
timeMs: number | null
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -72,8 +81,8 @@ const STATUS_COLOR_MAP: Record<ChartPointStatus, string> = {
|
||||
const CHARACTERISTIC_POINT_COLOR = '#ff4d4f'
|
||||
|
||||
const chartPoints = ref<ChartPoint[]>([])
|
||||
const characteristicCurveData = ref<Array<[number, number]>>([])
|
||||
const drawnCharacteristicCurveData = ref<Array<[number, number]>>([])
|
||||
const characteristicCurveData = ref<CharacteristicCurvePoint[]>([])
|
||||
const drawnCharacteristicCurveData = ref<CharacteristicCurvePoint[]>([])
|
||||
const characteristicCurveVisible = ref(false)
|
||||
const chartRef = ref<any>(null)
|
||||
|
||||
@@ -117,21 +126,45 @@ const sortedChartPoints = computed(() => {
|
||||
|
||||
const sortedCharacteristicCurveData = computed(() => {
|
||||
return [...characteristicCurveData.value].sort((a, b) => {
|
||||
if (a[0] !== b[0]) {
|
||||
return a[0] - b[0]
|
||||
if (a.timeMs !== null && b.timeMs !== null && a.timeMs !== b.timeMs) {
|
||||
return a.timeMs - b.timeMs
|
||||
}
|
||||
|
||||
return a[1] - b[1]
|
||||
if (a.timeMs !== null && b.timeMs === null) {
|
||||
return -1
|
||||
}
|
||||
|
||||
if (a.timeMs === null && b.timeMs !== null) {
|
||||
return 1
|
||||
}
|
||||
|
||||
if (a.duration !== b.duration) {
|
||||
return a.duration - b.duration
|
||||
}
|
||||
|
||||
return a.residualVoltage - b.residualVoltage
|
||||
})
|
||||
})
|
||||
|
||||
const sortedDrawnCharacteristicCurveData = computed(() => {
|
||||
return [...drawnCharacteristicCurveData.value].sort((a, b) => {
|
||||
if (a[0] !== b[0]) {
|
||||
return a[0] - b[0]
|
||||
if (a.timeMs !== null && b.timeMs !== null && a.timeMs !== b.timeMs) {
|
||||
return a.timeMs - b.timeMs
|
||||
}
|
||||
|
||||
return a[1] - b[1]
|
||||
if (a.timeMs !== null && b.timeMs === null) {
|
||||
return -1
|
||||
}
|
||||
|
||||
if (a.timeMs === null && b.timeMs !== null) {
|
||||
return 1
|
||||
}
|
||||
|
||||
if (a.duration !== b.duration) {
|
||||
return a.duration - b.duration
|
||||
}
|
||||
|
||||
return a.residualVoltage - b.residualVoltage
|
||||
})
|
||||
})
|
||||
|
||||
@@ -141,12 +174,12 @@ const solidCharacteristicCurveSeriesData = computed(() => {
|
||||
}
|
||||
|
||||
const curveSource = props.autoDrawCurve ? sortedCharacteristicCurveData.value : sortedDrawnCharacteristicCurveData.value
|
||||
return curveSource.map(item => [item[0], item[1], '特性曲线'])
|
||||
return curveSource.map(item => [item.duration, item.residualVoltage, '特性曲线'])
|
||||
})
|
||||
|
||||
const characteristicCurvePointSeriesData = computed(() => {
|
||||
return sortedCharacteristicCurveData.value.map(item => ({
|
||||
value: [item[0], item[1], '特性点']
|
||||
value: [item.duration, item.residualVoltage, '特性点']
|
||||
}))
|
||||
})
|
||||
|
||||
@@ -206,6 +239,58 @@ const toNumber = (value: unknown) => {
|
||||
return Number.isFinite(result) ? result : null
|
||||
}
|
||||
|
||||
const parsePointTime = (value: unknown) => {
|
||||
if (typeof value !== 'string') {
|
||||
return {
|
||||
time: null,
|
||||
timeMs: null
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedValue = value.trim()
|
||||
const match = normalizedValue.match(
|
||||
/^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})\.(\d{3})$/
|
||||
)
|
||||
|
||||
if (!match) {
|
||||
return {
|
||||
time: normalizedValue || null,
|
||||
timeMs: null
|
||||
}
|
||||
}
|
||||
|
||||
const [, year, month, day, hour, minute, second, millisecond] = match
|
||||
const parsedDate = new Date(
|
||||
Number(year),
|
||||
Number(month) - 1,
|
||||
Number(day),
|
||||
Number(hour),
|
||||
Number(minute),
|
||||
Number(second),
|
||||
Number(millisecond)
|
||||
)
|
||||
|
||||
if (
|
||||
parsedDate.getFullYear() !== Number(year) ||
|
||||
parsedDate.getMonth() !== Number(month) - 1 ||
|
||||
parsedDate.getDate() !== Number(day) ||
|
||||
parsedDate.getHours() !== Number(hour) ||
|
||||
parsedDate.getMinutes() !== Number(minute) ||
|
||||
parsedDate.getSeconds() !== Number(second) ||
|
||||
parsedDate.getMilliseconds() !== Number(millisecond)
|
||||
) {
|
||||
return {
|
||||
time: normalizedValue,
|
||||
timeMs: null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
time: normalizedValue,
|
||||
timeMs: parsedDate.getTime()
|
||||
}
|
||||
}
|
||||
|
||||
const normalizeTolerantValue = (value: unknown) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return null
|
||||
@@ -251,6 +336,7 @@ const normalizeStatus = (value: unknown): ChartPointStatus => {
|
||||
const normalizeTolerantPoint = (source: Record<string, any>): NormalizedTolerantPoint | null => {
|
||||
const duration = normalizeDuration(source)
|
||||
const residualVoltage = normalizeResidualVoltageValue(source)
|
||||
const { time, timeMs } = parsePointTime(source.time)
|
||||
|
||||
if (duration === null || residualVoltage === null) {
|
||||
return null
|
||||
@@ -276,6 +362,8 @@ const normalizeTolerantPoint = (source: Record<string, any>): NormalizedTolerant
|
||||
duration,
|
||||
residualVoltage,
|
||||
tolerant,
|
||||
time,
|
||||
timeMs,
|
||||
status:
|
||||
tolerant === 0
|
||||
? 'fail'
|
||||
@@ -313,7 +401,7 @@ const normalizePoint = (source: Record<string, any>): ChartPoint | null => {
|
||||
}
|
||||
|
||||
const extractCharacteristicCurvePoints = (payload: any) => {
|
||||
const result: Array<[number, number]> = []
|
||||
const result: CharacteristicCurvePoint[] = []
|
||||
const seen = new Set<string>()
|
||||
const rootPayload = payload?.data && typeof payload.data === 'object' ? payload.data : payload
|
||||
|
||||
@@ -333,10 +421,15 @@ const extractCharacteristicCurvePoints = (payload: any) => {
|
||||
|
||||
const point = normalizeTolerantPoint(node)
|
||||
if (point?.tolerant === 2) {
|
||||
const key = `${point.duration}|${point.residualVoltage}`
|
||||
const key = point.time ? `${point.time}|${point.duration}|${point.residualVoltage}` : `${point.duration}|${point.residualVoltage}`
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key)
|
||||
result.push([point.duration, point.residualVoltage])
|
||||
result.push({
|
||||
duration: point.duration,
|
||||
residualVoltage: point.residualVoltage,
|
||||
time: point.time,
|
||||
timeMs: point.timeMs
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,17 +444,21 @@ const extractCharacteristicCurvePoints = (payload: any) => {
|
||||
return result
|
||||
}
|
||||
|
||||
const mergeCharacteristicCurvePoints = (points: Array<[number, number]>) => {
|
||||
const mergeCharacteristicCurvePoints = (points: CharacteristicCurvePoint[]) => {
|
||||
if (!points.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const existingPointMap = new Map(
|
||||
characteristicCurveData.value.map(item => [`${item[0]}|${item[1]}`, item] as const)
|
||||
characteristicCurveData.value.map(item => [
|
||||
item.time ? `${item.time}|${item.duration}|${item.residualVoltage}` : `${item.duration}|${item.residualVoltage}`,
|
||||
item
|
||||
] as const)
|
||||
)
|
||||
|
||||
points.forEach(item => {
|
||||
existingPointMap.set(`${item[0]}|${item[1]}`, item)
|
||||
const key = item.time ? `${item.time}|${item.duration}|${item.residualVoltage}` : `${item.duration}|${item.residualVoltage}`
|
||||
existingPointMap.set(key, item)
|
||||
})
|
||||
|
||||
characteristicCurveData.value = Array.from(existingPointMap.values())
|
||||
@@ -472,8 +569,9 @@ const exportChartData = () => {
|
||||
const curveSheet = XLSX.utils.json_to_sheet(
|
||||
sortedCharacteristicCurveData.value.map((item, index) => ({
|
||||
序号: index + 1,
|
||||
持续时间_s: item[0],
|
||||
残余电压_pct: item[1]
|
||||
持续时间_s: item.duration,
|
||||
残余电压_pct: item.residualVoltage,
|
||||
时间: item.time ?? ''
|
||||
}))
|
||||
)
|
||||
XLSX.utils.book_append_sheet(workbook, curveSheet, '特性点')
|
||||
|
||||
Reference in New Issue
Block a user