Add new helper string related to justified MCQ flag
This commit is contained in:
parent
11e0b46034
commit
c5b65289d3
10 changed files with 121 additions and 69 deletions
|
|
@ -21,13 +21,19 @@ type myTeamHint struct {
|
|||
File string `json:"file,omitempty"`
|
||||
Cost int64 `json:"cost"`
|
||||
}
|
||||
type myTeamMCQJustifiedChoice struct {
|
||||
Label string `json:"label"`
|
||||
Solved bool `json:"solved,omitempty"`
|
||||
Value bool `json:"value,omitempty"`
|
||||
Help string `json:"help,omitempty"`
|
||||
}
|
||||
type myTeamMCQ struct {
|
||||
Title string `json:"title"`
|
||||
Justify bool `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"`
|
||||
Title string `json:"title"`
|
||||
Justify bool `json:"justify,omitempty"`
|
||||
Choices map[int64]interface{} `json:"choices,omitempty"`
|
||||
Solved *time.Time `json:"solved,omitempty"`
|
||||
PSolved *time.Time `json:"part_solved,omitempty"`
|
||||
Soluce string `json:"soluce,omitempty"`
|
||||
}
|
||||
type myTeamFlag struct {
|
||||
Label string `json:"label"`
|
||||
|
|
@ -156,8 +162,7 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
|
||||
// Expose exercice flags
|
||||
|
||||
justifiedMCQ := map[string][]byte{}
|
||||
justifiedMCQ_ids := map[string]int64{}
|
||||
justifiedMCQ := map[int64]FlagLabel{}
|
||||
exercice.Flags = map[int64]myTeamFlag{}
|
||||
|
||||
if flags, err := e.GetFlags(); err != nil {
|
||||
|
|
@ -166,11 +171,12 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
for _, k := range flags {
|
||||
var flag myTeamFlag
|
||||
|
||||
if k.Label[0] == '%' {
|
||||
justifiedMCQ[k.Label[1:]] = k.Checksum
|
||||
if t == nil || t.HasPartiallySolved(k) == nil {
|
||||
justifiedMCQ_ids[k.Label[1:]] = k.Id
|
||||
if fl, err := k.GetMCQJustification(); err == nil {
|
||||
fl.Checksum = k.Checksum
|
||||
if t != nil && t.HasPartiallySolved(k) != nil {
|
||||
fl.Solved = true
|
||||
}
|
||||
justifiedMCQ[fl.IdChoice] = fl
|
||||
continue
|
||||
} else if t == nil {
|
||||
flag.Soluce = hex.EncodeToString(k.Checksum)
|
||||
|
|
@ -206,65 +212,64 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
for _, mcq := range mcqs {
|
||||
m := myTeamMCQ{
|
||||
Title: mcq.Title,
|
||||
Choices: map[int64]string{},
|
||||
Choices: map[int64]interface{}{},
|
||||
}
|
||||
|
||||
soluce := ""
|
||||
solved_justify := true
|
||||
fullySolved := true
|
||||
if t != nil {
|
||||
m.PSolved = t.HasPartiallyRespond(mcq)
|
||||
}
|
||||
|
||||
for _, e := range mcq.Entries {
|
||||
m.Choices[e.Id] = e.Label
|
||||
if e.Response {
|
||||
soluce += "t"
|
||||
} else {
|
||||
soluce += "f"
|
||||
}
|
||||
if v, ok := justifiedMCQ[m.Title + "%" + e.Label]; ok {
|
||||
|
||||
if v, ok := justifiedMCQ[e.Id]; ok {
|
||||
m.Justify = true
|
||||
|
||||
if t == nil {
|
||||
soluce += hex.EncodeToString(v)
|
||||
soluce += hex.EncodeToString(v.Checksum)
|
||||
}
|
||||
|
||||
if _, ok := justifiedMCQ_ids[m.Title + "%" + e.Label]; ok {
|
||||
solved_justify = false
|
||||
if m.PSolved != nil || v.Solved {
|
||||
jc := myTeamMCQJustifiedChoice{
|
||||
Label: e.Label,
|
||||
Solved: v.Solved,
|
||||
Value: v.Solved,
|
||||
Help: v.Label,
|
||||
}
|
||||
|
||||
if !v.Solved {
|
||||
fullySolved = false
|
||||
}
|
||||
|
||||
if PartialValidation && m.PSolved != nil {
|
||||
jc.Value = e.Response
|
||||
}
|
||||
|
||||
m.Choices[e.Id] = jc
|
||||
} else {
|
||||
m.Choices[e.Id] = e.Label
|
||||
}
|
||||
} else {
|
||||
m.Choices[e.Id] = e.Label
|
||||
}
|
||||
}
|
||||
|
||||
if t != nil {
|
||||
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 if PartialValidation {
|
||||
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 {
|
||||
m.PSolved[e.Id] = -1
|
||||
}
|
||||
} else {
|
||||
m.PSolved[e.Id] = -1
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if t == nil {
|
||||
h := getHashedFlag([]byte(soluce))
|
||||
m.Soluce = hex.EncodeToString(h[:])
|
||||
}
|
||||
|
||||
if fullySolved {
|
||||
m.Solved = m.PSolved
|
||||
m.PSolved = nil
|
||||
}
|
||||
|
||||
exercice.MCQs[mcq.Id] = m
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue