New settings to only count bad submissions

This commit is contained in:
nemunaire 2021-09-08 03:34:48 +02:00
commit cd73622cae
9 changed files with 61 additions and 18 deletions

View file

@ -247,9 +247,21 @@ 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.
func (t Team) CountTries(e Exercice) (int64, time.Time) {
table := "exercice_tries"
if CountOnlyNotGoodTries {
table += "_notgood"
}
var nb *int64
var tm *time.Time
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 {
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 {
if 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 {
return 0, time.Unix(0, 0)
} else {
return 0, *tm
}
}
return 0, time.Unix(0, 0)
} else if nb == nil {
return 0, *tm