fic: Refactor CountTries function to fix timeouted submission
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-02-04 17:33:11 +01:00
parent 40a9b0d187
commit 7a7f90eeda

View file

@ -246,28 +246,23 @@ func (t *Team) DisplayChoices(k *FlagKey) error {
} }
// CountTries gets the amount of attempts made by the Team and retrieves the time of the latest attempt. // CountTries gets the amount of attempts made by the Team and retrieves the time of the latest attempt.
func (t *Team) CountTries(e *Exercice) (int64, *time.Time) { func (t *Team) CountTries(e *Exercice) (nb int64, tm *time.Time) {
table := "exercice_tries" table := "exercice_tries"
if SubmissionUniqueness {
table = "exercice_distinct_tries"
}
if CountOnlyNotGoodTries { if CountOnlyNotGoodTries {
table += "_notgood" table += "_notgood"
} }
var nb *int64 DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM "+table+" WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm)
var tm *time.Time
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM "+table+" WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil { // time is not accurate in distinct nor _notgood tables as it only considers notgood or distincts answers, so the last try is not count
if CountOnlyNotGoodTries { if SubmissionUniqueness || CountOnlyNotGoodTries {
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil { DBQueryRow("SELECT MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&tm)
return 0, nil
} else {
return 0, tm
}
}
return 0, nil
} else if nb == nil {
return 0, tm
} else {
return *nb, tm
} }
return
} }
// LastTryDist retrieves the distance to the correct answers, for the given challenge. // LastTryDist retrieves the distance to the correct answers, for the given challenge.