perf(tracks): coalesce address lookups
This commit is contained in:
@@ -1,5 +1,22 @@
|
||||
import type { HistoryLocationRow, TrackPlaybackEvent, TrackPlaybackResponse } from '../../api/types';
|
||||
|
||||
export const TRACK_ADDRESS_SETTLE_MS = 650;
|
||||
|
||||
export type TrackAddressCoordinate = { longitude: number; latitude: number; key: string };
|
||||
|
||||
export function trackAddressCoordinate(longitude?: number, latitude?: number): TrackAddressCoordinate | undefined {
|
||||
if (!Number.isFinite(longitude) || !Number.isFinite(latitude)
|
||||
|| Math.abs(longitude ?? 0) > 180 || Math.abs(latitude ?? 0) > 90
|
||||
|| (longitude === 0 && latitude === 0)) return undefined;
|
||||
const roundedLongitude = Number(longitude!.toFixed(4));
|
||||
const roundedLatitude = Number(latitude!.toFixed(4));
|
||||
return {
|
||||
longitude: roundedLongitude,
|
||||
latitude: roundedLatitude,
|
||||
key: `${roundedLongitude.toFixed(4)},${roundedLatitude.toFixed(4)}`
|
||||
};
|
||||
}
|
||||
|
||||
export function formatDuration(seconds: number) {
|
||||
const safe = Math.max(0, Math.floor(seconds || 0));
|
||||
const hours = Math.floor(safe / 3600);
|
||||
|
||||
Reference in New Issue
Block a user