|
// 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) |
|
) |
|
); |
// 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);