feat(web): finish Semi UI track workspace
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { TrackPlaybackResponse } from '../../api/types';
|
||||
import { buildTrackRailSelection, formatDuration, sampledEventIndex, trackAddressCoordinate, trackCsv, trackPlaybackInterval, trackPointMileageAvailable } from './track';
|
||||
import { buildTrackRailSelection, compactTrackWindowLabel, formatDuration, sampledEventIndex, trackAddressCoordinate, trackCsv, trackPlaybackInterval, trackPointMileageAvailable } from './track';
|
||||
|
||||
describe('track domain', () => {
|
||||
it('formats durations and maps original event indices to sampled points', () => {
|
||||
expect(formatDuration(3671)).toBe('01:01:11');
|
||||
expect(compactTrackWindowLabel('2026-07-19T00:00', '2026-07-19T23:59')).toBe('00:00–23:59');
|
||||
expect(compactTrackWindowLabel('2026-07-18T00:00', '2026-07-19T23:59')).toBe('07-18 00:00–07-19 23:59');
|
||||
expect(sampledEventIndex({ index: 50 } as never, 11, 101)).toBe(5);
|
||||
expect(sampledEventIndex({ index: 50, sampledIndex: 7 } as never, 11, 101)).toBe(7);
|
||||
});
|
||||
|
||||
@@ -26,6 +26,17 @@ export function formatDuration(seconds: number) {
|
||||
return [hours, minutes, remainder].map((value) => String(value).padStart(2, '0')).join(':');
|
||||
}
|
||||
|
||||
export function compactTrackWindowLabel(dateFrom: string, dateTo: string) {
|
||||
const from = dateFrom.replace('T', ' ');
|
||||
const to = dateTo.replace('T', ' ');
|
||||
const fromDate = from.slice(5, 10);
|
||||
const toDate = to.slice(5, 10);
|
||||
const fromTime = from.slice(11, 16);
|
||||
const toTime = to.slice(11, 16);
|
||||
if (fromDate && fromDate === toDate && fromTime && toTime) return `${fromTime}–${toTime}`;
|
||||
return `${from.slice(5, 16)}–${to.slice(5, 16)}`;
|
||||
}
|
||||
|
||||
export function sampledEventIndex(event: TrackPlaybackEvent, sampledCount: number, originalCount: number) {
|
||||
if (sampledCount <= 1 || originalCount <= 1) return 0;
|
||||
if (Number.isInteger(event.sampledIndex) && event.sampledIndex >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user