handle justified MCQ in interface and submission
This commit is contained in:
parent
01368dd6f4
commit
3dcb233c3f
4 changed files with 63 additions and 10 deletions
|
|
@ -298,7 +298,7 @@ func (e Exercice) CheckResponse(cksum []byte, respflags map[int64]string, respmc
|
|||
|
||||
// Check flags
|
||||
for _, flag := range flags {
|
||||
if res, ok := respflags[flag.Id]; !ok {
|
||||
if res, ok := respflags[flag.Id]; !ok && (!PartialValidation || t.HasPartiallySolved(flag) == nil) {
|
||||
valid = false
|
||||
} else if !flag.Check([]byte(res)) {
|
||||
if !PartialValidation || t.HasPartiallySolved(flag) == nil {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ type myTeamHint struct {
|
|||
}
|
||||
type myTeamMCQ struct {
|
||||
Title string `json:"title"`
|
||||
Justify bool `json:"justify,omitempty"`
|
||||
Justify []int64 `json:"justify,omitempty"`
|
||||
Choices map[int64]string `json:"choices,omitempty"`
|
||||
Solved *time.Time `json:"solved,omitempty"`
|
||||
PSolved map[int64]int `json:"checks_solved,omitempty"`
|
||||
Soluce string `json:"soluce,omitempty"`
|
||||
}
|
||||
type myTeamFlag struct {
|
||||
|
|
@ -155,7 +156,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
|
||||
// Expose exercice flags
|
||||
|
||||
var justifiedMCQ map[string][]byte
|
||||
justifiedMCQ := map[string][]byte{}
|
||||
justifiedMCQ_ids := map[string]int64{}
|
||||
exercice.Flags = map[int64]myTeamFlag{}
|
||||
|
||||
if flags, err := e.GetFlags(); err != nil {
|
||||
|
|
@ -166,6 +168,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
|
||||
if k.Label[0] == '%' {
|
||||
justifiedMCQ[k.Label[1:]] = k.Checksum
|
||||
if t == nil || t.HasPartiallySolved(k) == nil {
|
||||
justifiedMCQ_ids[k.Label[1:]] = k.Id
|
||||
}
|
||||
continue
|
||||
} else if t == nil {
|
||||
flag.Soluce = hex.EncodeToString(k.Checksum)
|
||||
|
|
@ -205,6 +210,9 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
}
|
||||
|
||||
soluce := ""
|
||||
solved_justify := true
|
||||
var nb_gen_justify_id int64
|
||||
var max_justify_id int64
|
||||
|
||||
for _, e := range mcq.Entries {
|
||||
m.Choices[e.Id] = e.Label
|
||||
|
|
@ -214,15 +222,46 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
soluce += "f"
|
||||
}
|
||||
if v, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok {
|
||||
m.Justify = true
|
||||
if m.Justify == nil {
|
||||
m.Justify = []int64{}
|
||||
}
|
||||
|
||||
if t == nil {
|
||||
soluce += hex.EncodeToString(v)
|
||||
}
|
||||
|
||||
if v, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; ok {
|
||||
solved_justify = false
|
||||
m.Justify = append(m.Justify, v)
|
||||
if v > max_justify_id {
|
||||
max_justify_id = v
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nb_gen_justify_id += 1
|
||||
}
|
||||
}
|
||||
|
||||
// Fill the rest of the array with factice values in order to hide number of valid choices
|
||||
for i := int64(0); i < nb_gen_justify_id; i++ {
|
||||
m.Justify = append(m.Justify, max_justify_id + 1 + i)
|
||||
}
|
||||
|
||||
if t != nil {
|
||||
m.Solved = t.HasPartiallyRespond(mcq)
|
||||
if solved_justify {
|
||||
m.Solved = t.HasPartiallyRespond(mcq)
|
||||
} else if PartialValidation && t.HasPartiallyRespond(mcq) != nil {
|
||||
m.PSolved = map[int64]int{}
|
||||
for _, e := range mcq.Entries {
|
||||
if _, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok {
|
||||
if _, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; !ok {
|
||||
m.PSolved[e.Id] = 2
|
||||
} else if e.Response {
|
||||
m.PSolved[e.Id] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
h := getHashedFlag([]byte(soluce))
|
||||
m.Soluce = hex.EncodeToString(h[:])
|
||||
|
|
|
|||
Reference in a new issue