Skip to content

Instantly share code, notes, and snippets.

@mugan86
Last active December 8, 2023 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mugan86/74fa524e74abf2061c56a80f07342577 to your computer and use it in GitHub Desktop.
Save mugan86/74fa524e74abf2061c56a80f07342577 to your computer and use it in GitHub Desktop.

To calculate the pacing needed to run the second half of a half marathon faster than the first, we need to consider the total time to complete the race and the percentage decrease in time per lap.

Given:

Total time to complete the race: 4620 seconds Decrease percentage per lap: 3% Distance of a half marathon: 21.0975 kilometers Assuming that the race is divided into two equal halves, the distance for each half would be 21.0975/2 = 10.54875 kilometers.

Let’s denote the time taken to run the first half as T1 and the time taken to run the second half as T2. Since the total time is 4620 seconds, we have:

T1 + T2 = 4620

Since the second half is run faster, T2 is less than T1. If we denote the decrease in time per lap as a percentage (in this case, 3%), we can express T2 as:

T2 = T1 - (0.03 * T1) = 0.97 * T1

Substituting T2 in the first equation, we get:

T1 + 0.97 * T1 = 4620

Solving this equation will give us the time taken to run the first half (T1), and substituting T1 in the equation for T2 will give us the time taken to run the second half.

Let’s calculate these values.


2345.17766497 sería el valor T1 y haciendo la sustitución T2 2274.82233503

Para calcular el ritmo necesario para correr la segunda mitad de una media maratón más rápido que la primera, necesitamos considerar el tiempo total para completar la carrera y el porcentaje de disminución de tiempo por vuelta.

Dado:

  • Tiempo total para completar la carrera: 4620 segundos
  • Porcentaje de disminución por vuelta: 3%
  • Distancia de una media maratón: 21.0975 kilómetros

Asumiendo que la carrera se divide en dos mitades iguales, la distancia para cada mitad sería 21.0975/2 = 10.54875 kilómetros.

Denotemos el tiempo que se tarda en correr la primera mitad como T1 y el tiempo que se tarda en correr la segunda mitad como T2. Como el tiempo total es de 4620 segundos, tenemos:

T1 + T2 = 4620

Como la segunda mitad se corre más rápido, T2 es menor que T1. Si denotamos la disminución de tiempo por vuelta como un porcentaje (en este caso, 3%), podemos expresar T2 como:

T2 = T1 - (0.03 * T1) = 0.97 * T1

Sustituyendo T2 en la primera ecuación, obtenemos:

T1 + 0.97 * T1 = 4620

Resolviendo esta ecuación nos dará el tiempo que se tarda en correr la primera mitad (T1), y sustituyendo T1 en la ecuación para T2 nos dará el tiempo que se tarda en correr la segunda mitad.

Vamos a calcular estos valores.


2345.17766497 sería el valor T1 y haciendo la sustitución T2 2274.82233503

// Note: please restart the page if syntax highlighting works bad.
const distances = [5, 10, 15, 12.3, 20, 21.0975, 42.195];
for (let i = 0; i < distances.length; i++) {
const distance = distances[i];
console.log("DISTANCE", distance)
console.log(Math.floor(distance % 2));
const checkIfOddDistance = Math.floor(distance % 2) === 1;
console.log(checkIfOddDistance);
const firstPartDistance = Math.floor(distance / 2);
const secondPartDistance =
distance % 2 > 0 ? firstPartDistance + 1 : firstPartDistance;
const lastMetres = distance % 1 > 0 ? distance % 1 : 0;
console.log(firstPartDistance, secondPartDistance)
}
/**
*
DISTANCE
5
1
true
2
3
DISTANCE
10
0
false
5
5
DISTANCE
15
1
true
7
8
DISTANCE
12.3
0
false
6
7
DISTANCE
20
0
false
10
10
DISTANCE
21.0975
1
true
10
11
DISTANCE
42.195
0
false
21
22
*/
// Redondear los valores intermedios al entero más cercano (arriba o abajo con Math.round) para ir obteniendo
function convertSecondsToTimeFormat(seconds, onlyMinSeconds = false) {
// Definir el número de segundos a convertir
const segundos = seconds;
// Calcular las horas, minutos y segundos
const horas = Math.floor(segundos / 3600);
const minutos = Math.floor((segundos - horas * 3600) / 60);
const segundosRestantes = segundos % 60;
// Crear la cadena de caracteres con formato "hh:mm:ss" y mostrar el resultado
return onlyMinSeconds
? `${minutos.toString().padStart(2, '0')}:${segundosRestantes
.toString()
.padStart(2, '0')}`
: `${horas.toString().padStart(2, '0')}:${minutos
.toString()
.padStart(2, '0')}:${segundosRestantes.toString().padStart(2, '0')}`; // 09:36:07
}
function convertoSecondsFromTime({ hours = 0, min = 0, seconds = 0 }) {
return hours * 3600 + min * 60 + seconds;
}
console.log('PRIMERA PARTE:');
const firstPartSplits = [
221.9545, 221.624, 221.2935, 220.963, 220.6325, 220.302, 219.9715, 219.641,
219.3105, 218.98,
];
for (let i = 0; i < firstPartSplits.length; i++) {
console.log(`${i + 1}: ${Math.round(firstPartSplits[i])}`);
console.log(
`${convertSecondsToTimeFormat(Math.round(firstPartSplits[i]), true)} min/km`
);
}
const secondsFirstTenKms = Math.round(
firstPartSplits.reduce((prev, accc) => prev + accc)
);
console.log(
secondsFirstTenKms,
` segundos primeros ${firstPartSplits.length} kms`
);
console.log(convertSecondsToTimeFormat(secondsFirstTenKms));
console.log('SEGUNDA PARTE:');
const secondPartSplits = [
218.6705, 218.361, 218.0515, 217.742, 217.4325, 217.123, 216.8135, 216.504,
216.1945, 215.885, 215.575,
];
for (let i = 0; i < secondPartSplits.length; i++) {
console.log(`${i + 11}: ${Math.round(secondPartSplits[i])}`);
console.log(
`${convertSecondsToTimeFormat(
Math.round(secondPartSplits[i]),
true
)} min/km`
);
}
const secondsSecondPartKms = Math.round(
secondPartSplits.reduce((prev, accc) => prev + accc)
);
console.log(
secondsSecondPartKms,
` segundos siguientes ${secondPartSplits.length} kms`
);
console.log(convertSecondsToTimeFormat(secondsSecondPartKms));
console.log(
'Parcial en el km 21',
convertSecondsToTimeFormat(secondsFirstTenKms + secondsSecondPartKms)
);
/*const lastStepsTimeSeconds = (4620 - (secondsFirstTenKms + secondsSecondPartKms));
console.log(lastStepsTimeSeconds)*/
const lastStepsTimeSeconds = 218.98 * 0.0975;
console.log(`Tiempo final de los 0.0975m restantes: ${lastStepsTimeSeconds}`);
console.log(
`Tiempo final: `,
convertSecondsToTimeFormat(
Math.round(secondsFirstTenKms + secondsSecondPartKms + lastStepsTimeSeconds)
)
);
@mugan86
Copy link
Author

mugan86 commented Dec 3, 2023

Captura de pantalla 2023-12-02 a las 20 13 49

@mugan86
Copy link
Author

mugan86 commented Dec 3, 2023

Captura de pantalla 2023-12-02 a las 19 28 59

@anartzdev
Copy link

anartzdev commented Dec 4, 2023

// Import stylesheets
import './style.css';

function convertSecondsToTimePaceFormat(seconds: number) {
const paceMins = Math.floor(seconds);
const paceSeconds = Math.round((seconds - paceMins) * 60);
return {
min: paceMins,
seconds: paceSeconds,
};
}

function convertSecondsToTimeFormat(seconds: number) {
// Definir el número de segundos a convertir
const segundos = seconds;

// Calcular las horas, minutos y segundos
const horas = Math.floor(segundos / 3600);
const minutos = Math.floor((segundos - horas * 3600) / 60);
const segundosRestantes = segundos % 60;

// Crear la cadena de caracteres con formato "hh:mm:ss"
const tiempo = ${horas.toString().padStart(2, '0')}:${minutos .toString() .padStart(2, '0')}:${segundosRestantes.toString().padStart(2, '0')};

// Mostrar el resultado
return tiempo; // 09:36:07
}

function convertoSecondsFromTime({ hours = 0, min = 0, seconds = 0 }) {
return hours * 3600 + min * 60 + seconds;
}

// Write TypeScript code!
const appDiv: HTMLElement = document.getElementById('app');
appDiv.innerHTML = <h1>TypeScript Starter</h1>;

// Definir el tiempo total como un string en formato hh:mm:ss
const tiempo = '01:15:50';

// Dividir el tiempo total en horas, minutos y segundos
const tiempoPorPartes = tiempo.split(':');
const horas = parseInt(tiempoPorPartes[0]);
const minutos = parseInt(tiempoPorPartes[1]);
const segundos = parseInt(tiempoPorPartes[2]);

// Calcular el tiempo total en horas
const tiempoTotalEnHoras = horas + minutos / 60 + segundos / 3600;

// Calcular el ritmo medio en minutos por kilómetro
const paceMinutesSeconds = (tiempoTotalEnHoras / 21.0975) * 60;

console.log(paceMinutesSeconds);

// Convertir el resultado a minutos y segundos
const timePaceMinKm = convertSecondsToTimePaceFormat(paceMinutesSeconds);

// Mostrar el resultado en formato mm:ss
console.log(
El ritmo medio es ${timePaceMinKm.min}:${timePaceMinKm.seconds .toString() .padStart(2, '0')} min/km
);

// Parciales que debería de llevar

for (let selectKm = 1; selectKm <= 21; selectKm++) {
// console.log((selectKm + 1) * convertoSecondsFromTime(timePaceMinKm), ' total seconds');
console.log(
'KM: ',
selectKm.toString().padStart(2, '0'),
'====>',
convertSecondsToTimeFormat(
selectKm * convertoSecondsFromTime(timePaceMinKm)
)
);
}

// Calcular el tiempo total en secgundos
const tiempoTotalEnSegundos = horas * 3600 + minutos * 60 + segundos;

/console.log(
tiempoTotalEnSegundos - 21 * convertoSecondsFromTime(timePaceMinKm)
);
/
console.log('FINAL (MM) ==>', tiempo);
console.log(tiempoTotalEnSegundos);

@anartzdev
Copy link

Como ir calculando los ritmos parcial a parcial: https://chat.openai.com/share/fd1ec2f3-1bd4-4142-9a56-7b6c0824f856

@anartzdev
Copy link

Resultado del calculador con split negativo:

https://stackblitz.com/edit/typescript-iwbzvp?file=index.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment