feat(web): finish Semi UI track workspace

This commit is contained in:
lingniu
2026-07-19 23:33:53 +08:00
parent 4c64c4c738
commit 1c18941980
8 changed files with 52 additions and 18 deletions

View File

@@ -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:0023:59');
expect(compactTrackWindowLabel('2026-07-18T00:00', '2026-07-19T23:59')).toBe('07-18 00:0007-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);
});

View File

@@ -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) {