admin: Better identify tries on exercice page
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2025-03-30 15:20:11 +02:00
parent 38e3a4efdf
commit f6713c768b
6 changed files with 177 additions and 3 deletions

View file

@ -11,7 +11,7 @@ import (
func (e *Exercice) GetHistory() ([]map[string]interface{}, error) {
hist := make([]map[string]interface{}, 0)
if rows, err := DBQuery(`SELECT id_team, U.name, U.color, "tries" AS kind, time, 0, id_exercice, NULL, NULL FROM exercice_tries NATURAL JOIN teams U WHERE id_exercice = ? UNION
if rows, err := DBQuery(`SELECT id_team, U.name, U.color, "tries" AS kind, time, 0, id_exercice, id_try, NULL FROM exercice_tries NATURAL JOIN teams U WHERE id_exercice = ? UNION
SELECT id_team, U.name, U.color, "solved" AS kind, time, coefficient, id_exercice, NULL, NULL FROM exercice_solved S NATURAL JOIN teams U WHERE id_exercice = ? UNION
SELECT id_team, U.name, U.color, "hint" AS kind, time, coefficient, id_exercice, H.id_hint, H.title FROM team_hints T INNER JOIN exercice_hints H ON H.id_hint = T.id_hint NATURAL JOIN teams U WHERE id_exercice = ? UNION
SELECT id_team, U.name, U.color, "wchoices" AS kind, time, coefficient, id_exercice, F.id_flag, F.type FROM team_wchoices W INNER JOIN exercice_flags F ON F.id_flag = W.id_flag NATURAL JOIN teams U WHERE id_exercice = ? UNION

102
libfic/exercice_tries.go Normal file
View file

@ -0,0 +1,102 @@
package fic
import (
"time"
)
type ExerciceTryDetail struct {
Kind string `json:"kind"`
RelatedId int64 `json:"related"`
}
type ExerciceTry struct {
Id int64 `json:"id"`
IdTeam int64 `json:"id_team"`
Time time.Time `json:"time"`
Checksum []byte `json:"checksum"`
NbDiff int64 `json:"nb_diff"`
OneGood bool `json:"one_good"`
Details []ExerciceTryDetail `json:"details,omitempty"`
}
// TriesList returns a list of tries related to the exercice.
func (e *Exercice) TriesList() ([]*ExerciceTry, error) {
tries_table := "exercice_tries"
if SubmissionUniqueness {
tries_table = "exercice_distinct_tries"
}
if rows, err := DBQuery("SELECT id_try, id_team, time, cksum, nbdiff, onegood FROM "+tries_table+" WHERE id_exercice = ?", e.Id); err != nil {
return nil, err
} else {
defer rows.Close()
var tries []*ExerciceTry
for rows.Next() {
var try ExerciceTry
if err := rows.Scan(&try.Id, &try.IdTeam, &try.Time, &try.Checksum, &try.NbDiff, &try.OneGood); err != nil {
return nil, err
}
tries = append(tries, &try)
}
return tries, nil
}
}
func (e *Exercice) GetTry(id int64) (try *ExerciceTry, err error) {
try = &ExerciceTry{}
err = DBQueryRow("SELECT id_try, id_team, time, cksum, nbdiff, onegood FROM exercice_tries WHERE id_exercice = ? AND id_try = ?", e.Id, id).Scan(&try.Id, &try.IdTeam, &try.Time, &try.Checksum, &try.NbDiff, &try.OneGood)
return
}
func (try *ExerciceTry) FillDetails() error {
if rows, err := DBQuery("SELECT id_flag FROM exercice_tries_flags WHERE id_try = ?", try.Id); err != nil {
return err
} else {
defer rows.Close()
for rows.Next() {
var relatedid int64
if err := rows.Scan(&relatedid); err != nil {
return err
}
try.Details = append(try.Details, ExerciceTryDetail{
Kind: "flag",
RelatedId: relatedid,
})
}
}
if rows, err := DBQuery("SELECT id_mcq FROM exercice_tries_mcq WHERE id_try = ?", try.Id); err != nil {
return err
} else {
defer rows.Close()
for rows.Next() {
var relatedid int64
if err := rows.Scan(&relatedid); err != nil {
return err
}
try.Details = append(try.Details, ExerciceTryDetail{
Kind: "mcq",
RelatedId: relatedid,
})
}
}
return nil
}
func (try *ExerciceTry) Delete() (int64, error) {
if res, err := DBExec("DELETE FROM exercice_tries WHERE id_try = ?", try.Id); err != nil {
return 0, err
} else if nb, err := res.RowsAffected(); err != nil {
return 0, err
} else {
return nb, err
}
}