fix(mileage): skip missing daily mileage in interval totals
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { MonitoringVehicle } from './types';
|
||||
import type { VehicleRecentDay } from './api';
|
||||
|
||||
export function monitoringMileageValue(vehicle: MonitoringVehicle): number | string {
|
||||
if (vehicle.mileageAnomaly) return '数据异常';
|
||||
if (!vehicle.isDataSynced) return '—';
|
||||
return Math.max(0, vehicle.dailyKm || 0);
|
||||
}
|
||||
|
||||
export function hasDailyMileage(day: VehicleRecentDay): boolean {
|
||||
return day.isDataSynced && Number.isFinite(day.dailyKm) && day.dailyKm >= 0;
|
||||
}
|
||||
|
||||
export function recentMileageStats(days: VehicleRecentDay[]) {
|
||||
const validDays = days.filter(hasDailyMileage);
|
||||
const totalKm = validDays.reduce((sum, day) => sum + day.dailyKm, 0);
|
||||
return {
|
||||
totalKm,
|
||||
synced: validDays.length,
|
||||
avg: validDays.length ? totalKm / validDays.length : 0,
|
||||
max: Math.max(1, ...validDays.map(day => day.dailyKm)),
|
||||
totalDays: days.length,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user