Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/components/Details.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" module>
import { Units, type RowWithIndex } from '../lib/parse/types';
import { RowKey, Units, type RowWithIndex } from '../lib/parse/types';
import type { RideStats } from './View';

export interface Props {
Expand All @@ -20,7 +20,7 @@
import Button from './Button.svelte';
import { ChartColours } from './Chart';
import { empty, State } from '../lib/parse/types';
import { formatFloat, formatInt } from '../lib/misc';
import { formatFloat, formatInt, formatTime } from '../lib/misc';
import { globalState } from '../lib/global.svelte';

let { data = empty, stats, batterySpecs, units, hasAdcTelemetry }: Props = $props();
Expand Down Expand Up @@ -137,9 +137,10 @@
{ label: 'Total Distance', value: `${formatFloat(stats.totalDistanceMeters)} m` },
'-',
{
label: 'Index',
value: formatInt(data.index + 1),
htmlTitle: 'Line number from the CSV file, or the specific log from the JSON file',
label: 'Time (index)',
value: `${formatTime(data[RowKey.Time])} (${formatInt(data.index + 1)})`,
htmlTitle:
'Time from log (index is the line number from the CSV file, or the specific log from the JSON file)',
},
{ value: swapDetailsButton },
]}
Expand All @@ -156,9 +157,10 @@
'-',
{ label: 'State', value: data.state.toUpperCase(), color: getStateColor(data.state) },
{
label: 'Index',
value: formatInt(data.index + 1),
htmlTitle: 'Line number from the CSV file, or the specific log from the JSON file',
label: 'Time (index)',
value: `${formatTime(data[RowKey.Time])} (${formatInt(data.index + 1)})`,
htmlTitle:
'Time from log (index is the line number from the CSV file, or the specific log from the JSON file)',
},
{ value: swapDetailsButton },
]}
Expand Down
9 changes: 9 additions & 0 deletions src/lib/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ export const formatInt = (n: number | undefined, allowInt = false) => {
if (typeof n !== 'number' || Number.isNaN(n)) return '??';
return n.toString();
};

// formats seconds into "[__h] [__m] __s"
export const formatTime = (seconds: number) => {
if (typeof seconds !== 'number' || Number.isNaN(seconds)) return '??';
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = Math.floor(seconds % 60);
return `${h > 0 ? `${h}h ` : ''}${m > 0 ? `${m}m ` : ''}${s}s`;
};
Loading