fix(domain): 使用空值表示缺失业务指标
This commit is contained in:
@@ -90,9 +90,9 @@ describe('battery domain', () => {
|
|||||||
expect(snapshot.devices.every((device) => device.soh30d === null)).toBe(true)
|
expect(snapshot.devices.every((device) => device.soh30d === null)).toBe(true)
|
||||||
expect(snapshot.devices.every((device) => device.soh90d === null)).toBe(true)
|
expect(snapshot.devices.every((device) => device.soh90d === null)).toBe(true)
|
||||||
expect(snapshot.devices.every((device) => device.soh60d === null)).toBe(true)
|
expect(snapshot.devices.every((device) => device.soh60d === null)).toBe(true)
|
||||||
expect(snapshot.devices.every((device) => device.cycles === 0)).toBe(true)
|
expect(snapshot.devices.every((device) => device.cycles === null)).toBe(true)
|
||||||
expect(snapshot.devices.every((device) => device.temperature === 0)).toBe(true)
|
expect(snapshot.devices.every((device) => device.temperature === null)).toBe(true)
|
||||||
expect(snapshot.devices.every((device) => device.chargeEfficiency === 0)).toBe(true)
|
expect(snapshot.devices.every((device) => device.chargeEfficiency === null)).toBe(true)
|
||||||
expect(snapshot.devices[0]?.firmware).toBe('v3.8.2')
|
expect(snapshot.devices[0]?.firmware).toBe('v3.8.2')
|
||||||
expect(snapshot.devices[1]?.firmware).toBe('未提供')
|
expect(snapshot.devices[1]?.firmware).toBe('未提供')
|
||||||
expect(snapshot.soh.history).toHaveLength(0)
|
expect(snapshot.soh.history).toHaveLength(0)
|
||||||
@@ -140,8 +140,8 @@ describe('battery domain', () => {
|
|||||||
expect(predicted?.cycles).toBe(6)
|
expect(predicted?.cycles).toBe(6)
|
||||||
expect(predicted?.firmware).toBe('v3.8.2')
|
expect(predicted?.firmware).toBe('v3.8.2')
|
||||||
expect(predicted?.status).toBe(DEVICE_STATUS.WARNING)
|
expect(predicted?.status).toBe(DEVICE_STATUS.WARNING)
|
||||||
expect(predicted?.temperature).toBe(0)
|
expect(predicted?.temperature).toBeNull()
|
||||||
expect(predicted?.chargeEfficiency).toBe(0)
|
expect(predicted?.chargeEfficiency).toBeNull()
|
||||||
expect(snapshot.soh.history).toHaveLength(0)
|
expect(snapshot.soh.history).toHaveLength(0)
|
||||||
expect(snapshot.soh.forecast).toHaveLength(3)
|
expect(snapshot.soh.forecast).toHaveLength(3)
|
||||||
expect(snapshot.soh.forecast[0]).toEqual({ month: '当前', value: 60 })
|
expect(snapshot.soh.forecast[0]).toEqual({ month: '当前', value: 60 })
|
||||||
|
|||||||
@@ -57,15 +57,15 @@ export const fleetUnitSchema = z.object({
|
|||||||
displayName: z.string(),
|
displayName: z.string(),
|
||||||
batch: z.string(),
|
batch: z.string(),
|
||||||
firmware: z.string(),
|
firmware: z.string(),
|
||||||
cycles: z.number().int(),
|
cycles: z.number().int().nullable(),
|
||||||
soh: z.number().nullable(),
|
soh: z.number().nullable(),
|
||||||
sohSource: z.union([z.literal('prediction'), z.literal('unavailable')]),
|
sohSource: z.union([z.literal('prediction'), z.literal('unavailable')]),
|
||||||
soh30d: z.number().nullable(),
|
soh30d: z.number().nullable(),
|
||||||
soh60d: z.number().nullable(),
|
soh60d: z.number().nullable(),
|
||||||
soh90d: z.number().nullable(),
|
soh90d: z.number().nullable(),
|
||||||
temperature: z.number(),
|
temperature: z.number().nullable(),
|
||||||
riskScore: z.number().int(),
|
riskScore: z.number().int(),
|
||||||
chargeEfficiency: z.number(),
|
chargeEfficiency: z.number().nullable(),
|
||||||
status: deviceStatusSchema,
|
status: deviceStatusSchema,
|
||||||
riskFactors: z.array(z.string()),
|
riskFactors: z.array(z.string()),
|
||||||
})
|
})
|
||||||
@@ -260,8 +260,8 @@ function toFleetUnit(item: BatteryInfo, prediction?: BatteryPrediction): FleetUn
|
|||||||
const soh30d = prediction ? round1(clamp(prediction.monthSoh, 0, 100)) : null
|
const soh30d = prediction ? round1(clamp(prediction.monthSoh, 0, 100)) : null
|
||||||
const soh90d = prediction ? round1(clamp(prediction.trmonthSoh, 0, 100)) : null
|
const soh90d = prediction ? round1(clamp(prediction.trmonthSoh, 0, 100)) : null
|
||||||
const soh60d = null
|
const soh60d = null
|
||||||
const temperature = 0
|
const temperature = null
|
||||||
const chargeEfficiency = 0
|
const chargeEfficiency = null
|
||||||
const fallbackRiskScore =
|
const fallbackRiskScore =
|
||||||
(item.isLowPower || item.power <= SOH_THRESHOLDS.LOW_POWER ? 60 : 0) +
|
(item.isLowPower || item.power <= SOH_THRESHOLDS.LOW_POWER ? 60 : 0) +
|
||||||
(item.powerStatus === POWER_STATUS.CHARGING ? 20 : 0)
|
(item.powerStatus === POWER_STATUS.CHARGING ? 20 : 0)
|
||||||
@@ -272,7 +272,7 @@ function toFleetUnit(item: BatteryInfo, prediction?: BatteryPrediction): FleetUn
|
|||||||
displayName: item.devName || item.mac,
|
displayName: item.devName || item.mac,
|
||||||
batch: item.devModel,
|
batch: item.devModel,
|
||||||
firmware: item.remark ?? '未提供',
|
firmware: item.remark ?? '未提供',
|
||||||
cycles: prediction?.cyclesUsed ?? 0,
|
cycles: prediction?.cyclesUsed ?? null,
|
||||||
soh,
|
soh,
|
||||||
sohSource: prediction ? 'prediction' : 'unavailable',
|
sohSource: prediction ? 'prediction' : 'unavailable',
|
||||||
soh30d,
|
soh30d,
|
||||||
|
|||||||
Reference in New Issue
Block a user