28 lines
822 B
TypeScript
28 lines
822 B
TypeScript
import type { MonitoringCache } from './types.js';
|
|
|
|
export interface TargetVehicleMileageSnapshot {
|
|
dailyKm: number;
|
|
totalKm: number | null;
|
|
isOnline: boolean;
|
|
}
|
|
|
|
export function targetVehicleMileageFromMonitoringCache(
|
|
cache: MonitoringCache | null,
|
|
requestedDate: string,
|
|
today: string,
|
|
plates: string[],
|
|
): Map<string, TargetVehicleMileageSnapshot> | null {
|
|
if (!cache || !requestedDate || requestedDate !== today) return null;
|
|
|
|
const selected = new Set(plates);
|
|
return new Map(
|
|
cache.vehicles
|
|
.filter(vehicle => selected.has(vehicle.plate))
|
|
.map(vehicle => [vehicle.plate, {
|
|
dailyKm: Math.max(0, Number(vehicle.dailyKm) || 0),
|
|
totalKm: vehicle.totalKm == null ? null : Math.max(0, Number(vehicle.totalKm) || 0),
|
|
isOnline: vehicle.isOnline,
|
|
}]),
|
|
);
|
|
}
|