getWorstTimeBySession method
- List<
TimeTraining> timesList, - bool isDnf
Método para obtener el peor tiempo registrado en una sesión.
Este método recorre la lista de tiempos de la sesión y devuelve el peor tiempo en formato "minutos:segundos.decimal". Se valida que el mejor tiempo no contenga una penalización DNF.
Parámetros:
timesList
: Lista de tiempos TimeTraining para los cuales se calcula el peor tiempo.
Retorna:
String
: El peor tiempo en formato "minutos:segundos.decimal".- "0:00.00": Si no hay tiempos antes o si los anteriores tiempos tienen una penalizacion de DNF entonces retornará el tiempo en formato "0:00.00".
Implementation
Future<String> getWorstTimeBySession(
List<TimeTraining> timesList, bool isDnf) async {
var worstTime = 0.0; // INICIALIZAR EL PEOR TIEMPO
int minutes = 0;
// ATRIBUTO PARA SABER SSI TODOS LOS TIEMPOS SON DNF
bool isDnfAll = false;
// CONTADOR PARA SABER CUANDOS TIEMPOS SON DNF
int cont = 0;
for (var tim in timesList) {
// SI EL TIEMPO TIENE UNA PENALIZACION DE 'DNF' SUBE EL CONTADOR
if (tim.penalty == "DNF") cont++;
} // SE RECORRE LA LSITA
// CUENTA EL ULTIMO TIEMPO SI LE PONE UN DNF
if (isDnf == true) cont++;
// SI EL CONTADOR Y EL NUMERO TOTAL DE TIEMPOS ES EL MISMO SIGNIFICA QUE
// TODOS LOS TIEMPOS TIENEN DNF
if (cont == timesList.length) isDnfAll = true;
// SI HA PUESTO DNF Y TODA LA LISTA TIENE DNF
if (isDnfAll == true) return "0:00.00";
if (isDnf) {
// SI EL TIEMPO ACTUAL SE LE AÑADE UN DNF, ENTONCES SE RECORRE TODOS LOS TIEMPOS
// MENOS EL ACTUAL, PARA SABER QUE TIEMPO ES EL PEOR Y SIN DNF
for (int index = 0; index <= (timesList.length - 2); index++) {
if (timesList[index].timeInSeconds > worstTime &&
timesList[index].penalty != "DNF") {
worstTime = timesList[index].timeInSeconds;
} // SI EL TIEMPO ES MENOR AL PEOR TIEMPO SE ESTABLECE
}
} else {
for (var times in timesList) {
if (times.timeInSeconds > worstTime && times.penalty != "DNF") {
worstTime = times.timeInSeconds;
} // SI EL TIEMPO ES MENOR AL PEOR TIEMPO SE ESTABLECE
} // SE RECORRE TODOS LOS TIEMPOS BUSCANDO EL PEOR TIEMPO DE LA SESION
}
while (worstTime >= 60) {
minutes++;
worstTime -= 60; // RESTANIS 60 SEGUNDO CUANDO PASE UN MINUTO
} // RECORREMOS EL TIEMPO MIENTRAS TENGA MINUTOS
if (worstTime < 10) {
return "$minutes:0${worstTime.toStringAsFixed(2)}";
} else {
return "$minutes:${worstTime.toStringAsFixed(2)}";
} // DEVUELVE EL PEOR TIEMPO FORMATEADO
}