admin: Retrieve stats on exercices
This commit is contained in:
parent
63b4cdc622
commit
b409fa6806
10 changed files with 241 additions and 19 deletions
|
|
@ -3,6 +3,7 @@ package fic
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -444,11 +445,25 @@ func (e *Exercice) GetOrdinal() (int, error) {
|
|||
}
|
||||
|
||||
// NewTry registers a solving attempt for the given Team.
|
||||
func (e *Exercice) NewTry(t *Team, cksum []byte) error {
|
||||
if _, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time, cksum) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), cksum); err != nil {
|
||||
return err
|
||||
func (e *Exercice) NewTry(t *Team, cksum []byte, flags ...Flag) (int64, error) {
|
||||
if res, err := DBExec("INSERT INTO exercice_tries (id_exercice, id_team, time, cksum) VALUES (?, ?, ?, ?)", e.Id, t.Id, time.Now(), cksum); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
return nil
|
||||
return res.LastInsertId()
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Exercice) NewTryFlag(tryid int64, flags ...Flag) {
|
||||
for _, flag := range flags {
|
||||
if fk, ok := flag.(*FlagKey); ok {
|
||||
if _, err := DBExec("INSERT INTO exercice_tries_flags (id_try, id_flag) VALUES (?, ?)", tryid, fk.Id); err != nil {
|
||||
log.Println("Unable to add detailed try: ", err.Error())
|
||||
}
|
||||
} else if fm, ok := flag.(*MCQ); ok {
|
||||
if _, err := DBExec("INSERT INTO exercice_tries_mcq (id_try, id_mcq) VALUES (?, ?)", tryid, fm.Id); err != nil {
|
||||
log.Println("Unable to add detailed try: ", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -550,7 +565,7 @@ func (e *Exercice) MCQSolved() (res []int64) {
|
|||
// 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[int]string, respmcq map[int]bool, t *Team) (bool, error) {
|
||||
if err := e.NewTry(t, cksum); err != nil {
|
||||
if tryId, err := e.NewTry(t, cksum); err != nil {
|
||||
return false, err
|
||||
} else if flags, err := e.GetFlagKeys(); err != nil {
|
||||
return false, err
|
||||
|
|
@ -565,6 +580,10 @@ func (e *Exercice) CheckResponse(cksum []byte, respflags map[int]string, respmcq
|
|||
|
||||
// Check MCQs
|
||||
for _, mcq := range mcqs {
|
||||
if mcq.HasOneEntry(respmcq) {
|
||||
e.NewTryFlag(tryId, mcq)
|
||||
}
|
||||
|
||||
if d := mcq.Check(respmcq); d > 0 {
|
||||
if !PartialValidation || t.HasPartiallySolved(mcq) == nil {
|
||||
valid = false
|
||||
|
|
@ -589,15 +608,21 @@ func (e *Exercice) CheckResponse(cksum []byte, respflags map[int]string, respmcq
|
|||
for _, flag := range flags {
|
||||
if res, ok := respflags[flag.Id]; !ok && (!PartialValidation || t.HasPartiallySolved(flag) == nil) {
|
||||
valid = valid && flag.IsOptionnal()
|
||||
} else if flag.Check([]byte(res)) != 0 {
|
||||
if !PartialValidation || t.HasPartiallySolved(flag) == nil {
|
||||
valid = valid && flag.IsOptionnal()
|
||||
} else if ok {
|
||||
if len(res) > 0 {
|
||||
e.NewTryFlag(tryId, flag)
|
||||
}
|
||||
} else {
|
||||
err := flag.FoundBy(t)
|
||||
if err == nil {
|
||||
// err is unicity issue, probably flag already found
|
||||
goodResponses += 1
|
||||
|
||||
if flag.Check([]byte(res)) != 0 {
|
||||
if !PartialValidation || t.HasPartiallySolved(flag) == nil {
|
||||
valid = valid && flag.IsOptionnal()
|
||||
}
|
||||
} else {
|
||||
err := flag.FoundBy(t)
|
||||
if err == nil {
|
||||
// err is unicity issue, probably flag already found
|
||||
goodResponses += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue