Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 282fdbc2a6 | |||
| ad32500121 | |||
| 9fb37b29c2 |
@@ -16,7 +16,7 @@ export function MotionHeader({
|
||||
|
||||
return (
|
||||
<motion.header
|
||||
initial={{ opacity: 0, y: shouldReduceMotion ? 0 : 10 }}
|
||||
initial={shouldReduceMotion ? false : { opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5, delay, ease: [0.25, 0.1, 0.25, 1] }}
|
||||
className={className}
|
||||
@@ -37,7 +37,7 @@ export function MotionSection({
|
||||
|
||||
return (
|
||||
<motion.section
|
||||
initial={{ opacity: 0, y: shouldReduceMotion ? 0 : 10 }}
|
||||
initial={shouldReduceMotion ? false : { opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5, delay, ease: [0.25, 0.1, 0.25, 1] }}
|
||||
className={className}
|
||||
@@ -58,7 +58,7 @@ export function MotionDiv({
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
initial={{ opacity: 0, y: shouldReduceMotion ? 0 : 10 }}
|
||||
initial={shouldReduceMotion ? false : { opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5, delay, ease: [0.25, 0.1, 0.25, 1] }}
|
||||
className={className}
|
||||
@@ -112,9 +112,11 @@ export function MotionTableRow({
|
||||
className,
|
||||
...props
|
||||
}: { children: ReactNode } & ComponentPropsWithoutRef<typeof motion.tr>) {
|
||||
const { shouldReduceMotion } = useMotionConfig()
|
||||
|
||||
return (
|
||||
<motion.tr
|
||||
initial={{ opacity: 0 }}
|
||||
initial={shouldReduceMotion ? false : { opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
transition={{ duration: 0.3 }}
|
||||
className={className}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function toMysqlBoolean(value: boolean) {
|
||||
|
||||
export function fromMysqlBoolean(value: string | boolean) {
|
||||
if (typeof value === 'boolean') return value
|
||||
return value.toLowerCase() === MYSQL_BOOLEAN.TRUE
|
||||
return value.trim().toLowerCase() === MYSQL_BOOLEAN.TRUE
|
||||
}
|
||||
|
||||
export const DEVICE_STATUS = {
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createBatteriesResponse,
|
||||
createDashboardSnapshot,
|
||||
DEVICE_STATUS,
|
||||
fromMysqlBoolean,
|
||||
getDeviceStatus,
|
||||
MYSQL_BOOLEAN,
|
||||
POWER_STATUS,
|
||||
@@ -27,7 +28,7 @@ const rows = [
|
||||
userId: 7,
|
||||
mac: 'RING-B11',
|
||||
devModel: '2402-B',
|
||||
devName: 'RING-B11',
|
||||
devName: '',
|
||||
isLowPower: MYSQL_BOOLEAN.TRUE,
|
||||
powerStatus: POWER_STATUS.CHARGING,
|
||||
power: 84,
|
||||
@@ -43,6 +44,11 @@ describe('battery domain', () => {
|
||||
expect(getDeviceStatus(85)).toBe(DEVICE_STATUS.WARNING)
|
||||
})
|
||||
|
||||
test('trims MySQL boolean strings before normalization', () => {
|
||||
expect(fromMysqlBoolean(' true ')).toBe(true)
|
||||
expect(fromMysqlBoolean(' false ')).toBe(false)
|
||||
})
|
||||
|
||||
test('builds batteries response counters from records', () => {
|
||||
const now = new Date('2026-05-11T00:00:00.000Z')
|
||||
const items = rows.map(toBatteryInfo)
|
||||
@@ -75,6 +81,10 @@ describe('battery domain', () => {
|
||||
const snapshot = createDashboardSnapshot(rows.map(toBatteryInfo), now)
|
||||
|
||||
expect(snapshot.devices).toHaveLength(2)
|
||||
expect(snapshot.devices[0]?.id).toBe('RING-A03')
|
||||
expect(snapshot.devices[0]?.displayName).toBe('RING-A03')
|
||||
expect(snapshot.devices[1]?.id).toBe('RING-B11')
|
||||
expect(snapshot.devices[1]?.displayName).toBe('RING-B11')
|
||||
expect(snapshot.devices.every((device) => device.sohSource === 'unavailable')).toBe(true)
|
||||
expect(snapshot.devices.every((device) => device.soh === null)).toBe(true)
|
||||
expect(snapshot.devices.every((device) => device.soh30d === null)).toBe(true)
|
||||
|
||||
@@ -54,6 +54,7 @@ export type BatteryInfo = z.infer<typeof batteryInfoSchema>
|
||||
|
||||
export const fleetUnitSchema = z.object({
|
||||
id: z.string(),
|
||||
displayName: z.string(),
|
||||
batch: z.string(),
|
||||
firmware: z.string(),
|
||||
cycles: z.number().int(),
|
||||
@@ -267,7 +268,8 @@ function toFleetUnit(item: BatteryInfo, prediction?: BatteryPrediction): FleetUn
|
||||
const riskScore = Math.round(clamp(prediction?.riskScore ?? fallbackRiskScore, 0, 100))
|
||||
|
||||
return {
|
||||
id: item.devName || item.mac,
|
||||
id: item.mac,
|
||||
displayName: item.devName || item.mac,
|
||||
batch: item.devModel,
|
||||
firmware: item.remark ?? '未提供',
|
||||
cycles: prediction?.cyclesUsed ?? 0,
|
||||
|
||||
@@ -93,7 +93,11 @@ function formatPercentWithUnit(value: number | null) {
|
||||
|
||||
function formatDelta(from: number | null, to: number | null) {
|
||||
if (from === null || to === null) return '预测不可用'
|
||||
return `${(from - to).toFixed(1)}% 衰减`
|
||||
const delta = from - to
|
||||
|
||||
if (delta < 0) return `${Math.abs(delta).toFixed(1)}% 改善`
|
||||
if (delta === 0) return '0.0% 持平'
|
||||
return `${delta.toFixed(1)}% 衰减`
|
||||
}
|
||||
|
||||
function widthPercent(value: number | null) {
|
||||
@@ -540,7 +544,7 @@ function Dashboard() {
|
||||
.sort((a, b) => b.riskScore - a.riskScore)
|
||||
.map((unit) => (
|
||||
<tr key={unit.id} className="transition-colors hover:bg-white/[0.04]">
|
||||
<td className="px-6 py-4 font-medium text-white">{unit.id}</td>
|
||||
<td className="px-6 py-4 font-medium text-white">{unit.displayName}</td>
|
||||
<td className="px-6 py-4 text-[#A1A1AA]">{unit.batch}</td>
|
||||
<td className="px-6 py-4 tabular-nums text-white">{formatPercentWithUnit(unit.soh)}</td>
|
||||
<td className="px-6 py-4 tabular-nums text-[#A1A1AA]">
|
||||
|
||||
@@ -54,6 +54,7 @@ function getBatteryPool() {
|
||||
waitForConnections: true,
|
||||
connectionLimit: 5,
|
||||
namedPlaceholders: true,
|
||||
dateStrings: true,
|
||||
})
|
||||
|
||||
return pool
|
||||
@@ -166,7 +167,7 @@ function createLatestWhere(input: LatestBatteryPageInput, cursor: PageCursor | n
|
||||
}
|
||||
|
||||
if (input.lowPower !== undefined) {
|
||||
clauses.push('current_record.is_low_power = :lowPower')
|
||||
clauses.push('LOWER(TRIM(current_record.is_low_power)) = :lowPower')
|
||||
params.lowPower = toMysqlBoolean(input.lowPower)
|
||||
}
|
||||
|
||||
@@ -294,7 +295,7 @@ export async function getLatestBatteryPage(input: LatestBatteryPageInput): Promi
|
||||
`
|
||||
SELECT
|
||||
COUNT(*) AS total,
|
||||
COALESCE(SUM(CASE WHEN current_record.is_low_power = '${MYSQL_BOOLEAN.TRUE}' THEN 1 ELSE 0 END), 0) AS lowPower,
|
||||
COALESCE(SUM(CASE WHEN LOWER(TRIM(current_record.is_low_power)) = '${MYSQL_BOOLEAN.TRUE}' THEN 1 ELSE 0 END), 0) AS lowPower,
|
||||
COALESCE(SUM(CASE WHEN current_record.power_status = ${POWER_STATUS.CHARGING} THEN 1 ELSE 0 END), 0) AS charging
|
||||
FROM ls_battery_info AS current_record
|
||||
WHERE ${countWhere.whereSql}
|
||||
|
||||
Reference in New Issue
Block a user