handle justified MCQ in interface and submission
This commit is contained in:
parent
01368dd6f4
commit
3dcb233c3f
|
@ -256,8 +256,12 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
angular.forEach(mcq["choices"], function(choice,cid) {
|
||||
this[cid] = {
|
||||
label: choice,
|
||||
value: false
|
||||
value: mcq["checks_solved"] !== undefined && mcq["checks_solved"][cid] !== undefined && mcq["checks_solved"][cid] > 0
|
||||
};
|
||||
if (mcq["checks_solved"] !== undefined) {
|
||||
this[cid].disabled = true;
|
||||
this[cid].solved = mcq["checks_solved"][cid] !== undefined && mcq["checks_solved"][cid] >= 2;
|
||||
}
|
||||
}, mcq["choices"]);
|
||||
}, $scope.mcqs);
|
||||
}
|
||||
|
@ -265,12 +269,11 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
waitMy();
|
||||
|
||||
$scope.ssubmit = function() {
|
||||
var resp = {}
|
||||
var resp = {"flags":{}}
|
||||
var check = undefined
|
||||
|
||||
if ($scope.my.exercices[$rootScope.current_exercice].flags && Object.keys($scope.my.exercices[$rootScope.current_exercice].flags).length)
|
||||
{
|
||||
resp["flags"] = {};
|
||||
angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) {
|
||||
if (flag.found == null) {
|
||||
if (flag.soluce !== undefined) {
|
||||
|
@ -291,6 +294,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
var soluce = "";
|
||||
resp["mcqs"] = {};
|
||||
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq) {
|
||||
var nid = 0;
|
||||
if (mcq.solved == null) {
|
||||
angular.forEach(mcq.choices, function(choice, cid) {
|
||||
if (mcq.soluce !== undefined) {
|
||||
|
@ -298,7 +302,15 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
|
|||
|
||||
soluce += choice.value ? "t" : "f";
|
||||
} else {
|
||||
if (choice.value) resp["mcqs"][cid] = choice.value;
|
||||
if (choice.value) {
|
||||
resp["mcqs"][cid] = choice.value;
|
||||
if (mcq.justify !== undefined) {
|
||||
if (choice.justify)
|
||||
resp["flags"][mcq.justify[nid++]] = choice.justify;
|
||||
else if (!choice.solved)
|
||||
nid++;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (mcq.soluce !== undefined) {
|
||||
|
|
|
@ -92,8 +92,10 @@
|
|||
<div class="form-check" ng-repeat="(k,mcq) in my.exercices[current_exercice].mcqs">
|
||||
<p ng-if="mcq.title">{{ mcq.title }} <span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="mcq.solved" title="QCM réussi à {{ mcq.solved | date:'mediumTime'}}"></span></p>
|
||||
<div class="custom-control custom-checkbox" ng-repeat="(cid,choice) in mcq.choices" ng-if="!mcq.solved">
|
||||
<input class="custom-control-input" type="checkbox" id="mcq_{{k}}_{{cid}}" name="mcq_{{k}}_{{cid}}" ng-model="choice.value">
|
||||
<input class="custom-control-input" type="checkbox" id="mcq_{{k}}_{{cid}}" name="mcq_{{k}}_{{cid}}" ng-model="choice.value" ng-disabled="choice.disabled">
|
||||
<label class="custom-control-label" for="mcq_{{k}}_{{cid}}" ng-bind="choice.label"></label>
|
||||
<input type="text" class="form-control" autocomplete="off" placeholder="Flag correspondant" name="sol_{{ cid }}" ng-model="choice.justify" ng-if="choice.value && mcq.justify.length && !choice.solved">
|
||||
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="choice.solved" title="Flag trouvé !"></span>
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
|
|
|
@ -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 {
|
||||
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[:])
|
||||
|
|
Loading…
Reference in New Issue
Block a user