mirror of
https://github.com/sharevb/it-tools.git
synced 2026-12-02 09:42:10 +03:00
feat(Running Pace): Presets + new Running Planner tool
Fix part of #598
This commit is contained in:
1 parent
4c721e3124
commit
941312ccc6
3 files changed
+388
No files matched your search
@@ -73,6 +73,21 @@ function calculateStuff() {
|
||||
<template>
|
||||
<div>
|
||||
<NForm label-placement="left" label-width="70px">
|
||||
<NFormItem label="Presets:">
|
||||
<n-space>
|
||||
<NButton size="small" @click="length = '100m'">100m</NButton>
|
||||
<NButton size="small" @click="length = '200m'">200m</NButton>
|
||||
<NButton size="small" @click="length = '400m'">400m</NButton>
|
||||
<NButton size="small" @click="length = '800m'">800m</NButton>
|
||||
<NButton size="small" @click="length = '1km'">1km</NButton>
|
||||
<NButton size="small" @click="length = '5km'">5km</NButton>
|
||||
<NButton size="small" @click="length = '10km'">10km</NButton>
|
||||
<NButton size="small" @click="length = '21.0975km'">Half Marathon</NButton>
|
||||
<NButton size="small" @click="length = '42.195km'">Marathon</NButton>
|
||||
<NButton size="small" @click="length = '50km'">50km</NButton>
|
||||
</n-space>
|
||||
</NFormItem>
|
||||
|
||||
<NFormItem :label="t('tools.running-pace-calculator.texts.label-length')">
|
||||
<NInput
|
||||
v-model:value="length"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Running Pace Planner',
|
||||
path: '/running-planner',
|
||||
description: 'Running pace planner tool to help you plan your running pace and training schedule.',
|
||||
keywords: ['running', 'pace', 'marathon', 'planner'],
|
||||
component: () => import('./running-planner.vue'),
|
||||
icon: defineAsyncComponent(() => import('@vicons/tabler/es/Run')),
|
||||
createdAt: new Date('2026-11-29'),
|
||||
category: 'Data',
|
||||
});
|
||||
@@ -0,0 +1,361 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-grid :cols="24" :x-gap="16">
|
||||
<n-grid-item :span="6">
|
||||
<n-form-item label="Unit:" label-placement="left">
|
||||
<n-select v-model:value="unit" :options="unitOptions" />
|
||||
</n-form-item>
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item :span="10">
|
||||
<n-form-item label="Race:" label-placement="left">
|
||||
<n-select :value="selectedRace" :options="raceOptions" clearable @update:value="onRaceSelect" />
|
||||
</n-form-item>
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item :span="8">
|
||||
<n-form-item :label="`Distance (${unit}):`" label-placement="left">
|
||||
<n-input-number v-model:value="distance" :min="1" :max="100" :step="0.1" style="width: 100%" />
|
||||
</n-form-item>
|
||||
</n-grid-item>
|
||||
</n-grid>
|
||||
|
||||
<n-grid :cols="24" :x-gap="16">
|
||||
<n-grid-item :span="12">
|
||||
<n-form-item :label="`Pace (${unitLabel}):`" label-placement="left">
|
||||
<n-grid :cols="2" :x-gap="8">
|
||||
<n-grid-item>
|
||||
<n-input-number
|
||||
v-model:value="paceMinutes"
|
||||
placeholder="Minutes"
|
||||
:min="0"
|
||||
:max="30"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item>
|
||||
<n-input-number
|
||||
v-model:value="paceSeconds"
|
||||
placeholder="Seconds"
|
||||
:min="0"
|
||||
:max="59"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</n-grid-item>
|
||||
</n-grid>
|
||||
</n-form-item>
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item :span="12">
|
||||
<n-form-item label="Checkpoints:" label-placement="left">
|
||||
<n-select v-model:value="splitInterval" :options="intervalOptions" />
|
||||
</n-form-item>
|
||||
</n-grid-item>
|
||||
</n-grid>
|
||||
|
||||
<n-space justify="center" mb-3>
|
||||
<n-button v-for="race in racePresets" :key="race.value" secondary @click="applyRace(race)">
|
||||
{{ race.label }}
|
||||
</n-button>
|
||||
</n-space>
|
||||
|
||||
<n-card>
|
||||
<n-grid :cols="2">
|
||||
<n-grid-item>
|
||||
<n-statistic label="Race" :value="distanceName" />
|
||||
</n-grid-item>
|
||||
|
||||
<n-grid-item>
|
||||
<n-statistic label="Estimated Finish Time" :value="estimatedFinishTime" />
|
||||
</n-grid-item>
|
||||
</n-grid>
|
||||
</n-card>
|
||||
|
||||
<n-card title="Projected Checkpoints">
|
||||
<n-data-table :columns="columns" :data="rows" :pagination="{ pageSize: 20 }" :bordered="false" />
|
||||
</n-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, h, ref } from 'vue';
|
||||
import { NTag, type DataTableColumns } from 'naive-ui';
|
||||
|
||||
type Unit = 'km' | 'mi';
|
||||
|
||||
const KM_PER_MILE = 1.609344;
|
||||
|
||||
const unit = ref<Unit>('km');
|
||||
|
||||
const paceMinutes = ref(5);
|
||||
const paceSeconds = ref(0);
|
||||
|
||||
const distance = ref(42.195);
|
||||
|
||||
const splitInterval = ref(5);
|
||||
|
||||
const selectedRace = ref<string | null>('marathon');
|
||||
|
||||
const unitOptions = [
|
||||
{
|
||||
label: 'Kilometers',
|
||||
value: 'km',
|
||||
},
|
||||
{
|
||||
label: 'Miles',
|
||||
value: 'mi',
|
||||
},
|
||||
];
|
||||
|
||||
const racePresets = [
|
||||
{
|
||||
label: '5K',
|
||||
value: '5k',
|
||||
distanceKm: 5,
|
||||
},
|
||||
{
|
||||
label: '10K',
|
||||
value: '10k',
|
||||
distanceKm: 10,
|
||||
},
|
||||
{
|
||||
label: '15K',
|
||||
value: '15k',
|
||||
distanceKm: 15,
|
||||
},
|
||||
{
|
||||
label: '10 Mile',
|
||||
value: '10mile',
|
||||
distanceKm: 16.09344,
|
||||
},
|
||||
{
|
||||
label: '20K',
|
||||
value: '20k',
|
||||
distanceKm: 20,
|
||||
},
|
||||
{
|
||||
label: 'Half Marathon',
|
||||
value: 'half',
|
||||
distanceKm: 21.0975,
|
||||
},
|
||||
{
|
||||
label: '25K',
|
||||
value: '25k',
|
||||
distanceKm: 25,
|
||||
},
|
||||
{
|
||||
label: '30K',
|
||||
value: '30k',
|
||||
distanceKm: 30,
|
||||
},
|
||||
{
|
||||
label: 'Marathon',
|
||||
value: 'marathon',
|
||||
distanceKm: 42.195,
|
||||
},
|
||||
{
|
||||
label: '50K Ultra',
|
||||
value: '50k',
|
||||
distanceKm: 50,
|
||||
},
|
||||
];
|
||||
|
||||
const raceOptions = racePresets.map((r) => ({
|
||||
label: r.label,
|
||||
value: r.value,
|
||||
}));
|
||||
|
||||
const unitLabel = computed(() => (unit.value === 'km' ? 'min/km' : 'min/mi'));
|
||||
|
||||
function kmToMiles(km: number) {
|
||||
return km / KM_PER_MILE;
|
||||
}
|
||||
|
||||
function milesToKm(mi: number) {
|
||||
return mi * KM_PER_MILE;
|
||||
}
|
||||
|
||||
function formatDuration(totalSeconds: number) {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
|
||||
const seconds = Math.round(totalSeconds % 60);
|
||||
|
||||
return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
function paceToLabel(seconds: number) {
|
||||
const m = Math.floor(seconds / 60);
|
||||
const s = seconds % 60;
|
||||
|
||||
return `${m}:${String(s).padStart(2, '0')}/${unit.value}`;
|
||||
}
|
||||
|
||||
function applyRace(race: (typeof racePresets)[number]) {
|
||||
selectedRace.value = race.value;
|
||||
|
||||
distance.value = unit.value === 'km' ? race.distanceKm : kmToMiles(race.distanceKm);
|
||||
}
|
||||
|
||||
function onRaceSelect(value: string | null) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const found = racePresets.find((r) => r.value === value);
|
||||
|
||||
if (found) {
|
||||
applyRace(found);
|
||||
}
|
||||
}
|
||||
|
||||
const intervalOptions = computed(() => {
|
||||
return unit.value === 'km'
|
||||
? [
|
||||
{
|
||||
label: 'Every 1 km',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: 'Every 2 km',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: 'Every 5 km',
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: 'Every 10 km',
|
||||
value: 10,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
label: 'Every 1 mile',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: 'Every 2 miles',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: 'Every 5 miles',
|
||||
value: 5,
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
const paceInSeconds = computed(() => paceMinutes.value * 60 + paceSeconds.value);
|
||||
|
||||
const distanceName = computed(() => {
|
||||
const currentKm = unit.value === 'km' ? distance.value : milesToKm(distance.value);
|
||||
|
||||
const found = racePresets.find((race) => Math.abs(race.distanceKm - currentKm) < 0.1);
|
||||
|
||||
return found?.label ?? 'Custom Distance';
|
||||
});
|
||||
|
||||
const paceVariants = computed(() => [
|
||||
{
|
||||
key: 'minus60',
|
||||
title: '-1:00',
|
||||
seconds: Math.max(60, paceInSeconds.value - 60),
|
||||
},
|
||||
{
|
||||
key: 'minus30',
|
||||
title: '-0:30',
|
||||
seconds: Math.max(60, paceInSeconds.value - 30),
|
||||
},
|
||||
{
|
||||
key: 'target',
|
||||
title: 'Target',
|
||||
seconds: paceInSeconds.value,
|
||||
},
|
||||
{
|
||||
key: 'plus30',
|
||||
title: '+0:30',
|
||||
seconds: paceInSeconds.value + 30,
|
||||
},
|
||||
{
|
||||
key: 'plus60',
|
||||
title: '+1:00',
|
||||
seconds: paceInSeconds.value + 60,
|
||||
},
|
||||
]);
|
||||
|
||||
const estimatedFinishTime = computed(() => formatDuration(distance.value * paceInSeconds.value));
|
||||
|
||||
const rows = computed(() => {
|
||||
const data: Record<string, any>[] = [];
|
||||
|
||||
let current = splitInterval.value;
|
||||
|
||||
while (current < distance.value) {
|
||||
const row: Record<string, any> = {
|
||||
distance: current,
|
||||
finish: false,
|
||||
};
|
||||
|
||||
paceVariants.value.forEach((variant) => {
|
||||
row[variant.key] = formatDuration(current * variant.seconds);
|
||||
});
|
||||
|
||||
data.push(row);
|
||||
|
||||
current += splitInterval.value;
|
||||
}
|
||||
|
||||
const finishRow: Record<string, any> = {
|
||||
distance: distance.value,
|
||||
finish: true,
|
||||
};
|
||||
|
||||
paceVariants.value.forEach((variant) => {
|
||||
finishRow[variant.key] = formatDuration(distance.value * variant.seconds);
|
||||
});
|
||||
|
||||
data.push(finishRow);
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
const columns = computed<DataTableColumns<any>>(() => {
|
||||
const result: DataTableColumns<any> = [
|
||||
{
|
||||
title: `Distance (${unit.value})`,
|
||||
key: 'distance',
|
||||
width: 160,
|
||||
fixed: 'left',
|
||||
render(row) {
|
||||
if (row.finish) {
|
||||
return h(
|
||||
NTag,
|
||||
{
|
||||
type: 'success',
|
||||
},
|
||||
{
|
||||
default: () => `${row.distance.toFixed(2)} ${unit.value}`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return `${row.distance.toFixed(1)} ${unit.value}`;
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
paceVariants.value.forEach((variant) => {
|
||||
result.push({
|
||||
title:
|
||||
variant.title === 'Target'
|
||||
? paceToLabel(variant.seconds)
|
||||
: `${variant.title} (${paceToLabel(variant.seconds)})`,
|
||||
key: variant.key,
|
||||
});
|
||||
});
|
||||
|
||||
return result;
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user