admin: add some stats about exercices

This commit is contained in:
nemunaire 2020-01-29 15:57:34 +01:00
commit 5df1cc6e93
5 changed files with 104 additions and 8 deletions

View file

@ -360,6 +360,42 @@ func (e Exercice) TriedCount() int64 {
}
}
// FlagSolved returns the list of flags solved.
func (e Exercice) FlagSolved() (res []int64) {
if rows, err := DBQuery("SELECT F.id_flag FROM flag_found F INNER JOIN exercice_flags E ON E.id_flag = F.id_flag WHERE E.id_exercice = ? GROUP BY id_flag", e.Id); err != nil {
return
} else {
defer rows.Close()
for rows.Next() {
var n int64
if err := rows.Scan(&n); err != nil {
return
}
res = append(res, n)
}
return
}
}
// MCQSolved returns the list of mcqs solved.
func (e Exercice) MCQSolved() (res []int64) {
if rows, err := DBQuery("SELECT F.id_mcq FROM mcq_found F INNER JOIN exercice_mcq E ON E.id_mcq = F.id_mcq WHERE E.id_exercice = ? GROUP BY id_mcq", e.Id); err != nil {
return
} else {
defer rows.Close()
for rows.Next() {
var n int64
if err := rows.Scan(&n); err != nil {
return
}
res = append(res, n)
}
return
}
}
// CheckResponse, given both flags and MCQ responses, figures out if thoses are correct (or if they are previously solved).
// In the meanwhile, CheckResponse registers good answers given (but it does not mark the challenge as solved at the end).
func (e Exercice) CheckResponse(cksum []byte, respflags map[int64]string, respmcq map[int64]bool, t Team) (bool, error) {