Able to check MCQ

This commit is contained in:
nemunaire 2017-12-16 01:16:30 +01:00
commit 6903c91df2
6 changed files with 79 additions and 13 deletions

View file

@ -6,6 +6,7 @@ import (
)
var PartialValidation bool
var PartialMCQValidation bool
type Exercice struct {
Id int64 `json:"id"`
@ -202,19 +203,41 @@ func (e Exercice) TriedCount() int64 {
}
}
func (e Exercice) CheckResponse(resps map[string]string, t Team) (bool, error) {
func (e Exercice) CheckResponse(respkeys map[string]string, respmcq map[int64]bool, t Team) (bool, error) {
if err := e.NewTry(t); err != nil {
return false, err
} else if keys, err := e.GetKeys(); err != nil {
return false, err
} else if mcqs, err := e.GetMCQ(); err != nil {
return false, err
} else if len(keys) < 1 && len(mcqs) < 1 {
return true, errors.New("Exercice with no key registered")
} else {
if len(keys) < 1 {
return true, errors.New("Exercice with no key registered")
valid := true
diff := 0
// Check MCQs
for _, mcq := range mcqs {
if d := mcq.Check(respmcq); d > 0 {
if !PartialValidation || t.HasPartiallyRespond(mcq) == nil {
valid = false
diff += d
}
} else if !PartialMCQValidation {
mcq.FoundBy(t)
}
}
valid := true
// Validate MCQs if no error
if valid {
for _, mcq := range mcqs {
mcq.FoundBy(t)
}
}
// Check keys
for _, key := range keys {
if res, ok := resps[key.Label]; !ok {
if res, ok := respkeys[key.Label]; !ok {
valid = false
} else if !key.Check(res) {
if !PartialValidation || t.HasPartiallySolved(key) == nil {
@ -225,6 +248,10 @@ func (e Exercice) CheckResponse(resps map[string]string, t Team) (bool, error) {
}
}
if diff > 0 {
e.UpdateTry(t, diff)
}
return valid, nil
}
}