Change exported flags format in my.json

This commit is contained in:
nemunaire 2018-11-28 02:27:51 +01:00
parent d6ae1551ba
commit 195490484c
5 changed files with 44 additions and 55 deletions

View File

@ -17,8 +17,8 @@ import (
)
type ResponsesUpload struct {
Keys map[string]string `json:"flags"`
MCQs map[int64]bool `json:"mcqs"`
Keys map[int64]string `json:"flags"`
MCQs map[int64]bool `json:"mcqs"`
}
func treatSubmission(pathname string, team fic.Team, exercice_id string) {

View File

@ -245,7 +245,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
};
})
.controller("SubmissionController", function($scope, $http, $rootScope, $timeout) {
$scope.flags = [];
$rootScope.sberr = "";
var waitMy = function() {
@ -253,34 +252,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$timeout.cancel($scope.cbs);
$scope.cbs = $timeout(waitMy, 420);
} else {
$scope.flags = [];
angular.forEach($scope.my.exercices[$rootScope.current_exercice].keys, function(key,kid) {
var o = {
id: kid,
name: key,
help: "#help goes here#not yet implemented#",
value: ""
};
if ($scope.my.exercices[$rootScope.current_exercice].solved_matrix != null)
o.found = $scope.my.exercices[$rootScope.current_exercice].solved_matrix[kid];
this.push(o);
}, $scope.flags);
$scope.mcqs = [];
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq,qid) {
var o = {
title: mcq.title,
kind: mcq.kind,
solved: mcq.solved,
choices: {}
};
angular.forEach(mcq["choices"], function(choice,cid) {
this[cid] = {
label: choice,
value: false
};
}, o["choices"]);
this.push(o);
}, mcq["choices"]);
}, $scope.mcqs);
}
}
@ -289,18 +267,18 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$scope.ssubmit = function() {
var resp = {}
if ($scope.flags && $scope.flags.length)
if ($scope.my.exercices[$rootScope.current_exercice].flags && Object.keys($scope.my.exercices[$rootScope.current_exercice].flags).length)
{
resp["flags"] = {};
angular.forEach($scope.flags, function(flag,kid) {
resp["flags"][flag.name] = flag.value;
angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) {
resp["flags"][kid] = flag.value;
});
}
if ($scope.mcqs && $scope.mcqs.length)
if ($scope.my.exercices[$rootScope.current_exercice].mcqs && Object.keys($scope.my.exercices[$rootScope.current_exercice].mcqs).length)
{
resp["mcqs"] = {};
angular.forEach($scope.mcqs, function(mcq) {
angular.forEach($scope.my.exercices[$rootScope.current_exercice].mcqs, function(mcq) {
angular.forEach(mcq.choices, function(choice, cid) {
if (choice.value) resp["mcqs"][cid] = choice.value;
})

View File

@ -5,7 +5,7 @@
<a ng-href="/{{ themes[current_theme].urlid }}/{{ themes[current_theme].exercices[k].urlid }}" ng-if="(k != current_exercice && my.exercices[k])">
{{ exercice.title }}
<span class="glyphicon glyphicon-gift" aria-hidden="true" ng-if="themes[current_theme].exercices[k].curcoeff > 1.0"></span>
<span class="glyphicon glyphicon-ok" aria-hidden="true" ng-if="(my.team_id && my.exercices[k].solved)"></span>
<span class="glyphicon glyphicon-ok text-success" aria-hidden="true" ng-if="(my.team_id && my.exercices[k].solved)"></span>
</a>
<strong ng-if="k == current_exercice" class="text-info">{{ exercice.title }}</strong>
</li>
@ -77,16 +77,16 @@
</ul>
<div class="card-body" ng-if="!my.exercices[current_exercice].submitted || sberr">
<form ng-controller="SubmissionController" ng-submit="ssubmit()">
<div class="form-group" ng-repeat="key in flags">
<label for="sol_{{ key.id }}">{{ key.name }}&nbsp;:</label>
<input type="text" class="form-control" id="sol_{{ key.id }}" autocomplete="off" name="sol_{{ key.id }}" ng-model="key.value" ng-if="!key.found">
<div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
<label for="sol_{{ kid }}">{{ key.label }}&nbsp;:</label>
<input type="text" class="form-control" id="sol_{{ kid }}" autocomplete="off" name="sol_{{ kid }}" ng-model="key.value" ng-if="!key.found">
<small class="form-text text-muted" ng-if="key.help.length > 0" ng-bind="key.help"></small>
<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" ng-if="key.found"></span>
<span class="glyphicon glyphicon-ok form-control-feedback text-success" aria-hidden="true" ng-if="key.found" title="Flag trouvé à {{ key.found | date:'mediumTime'}}"></span>
</div>
<div class="form-check" ng-repeat="(k,mcq) in mcqs">
<p ng-if="mcq.title" ng-bind="mcq.title"></p>
<div class="custom-control custom-checkbox" ng-repeat="(cid,choice) in mcq.choices">
<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">
<label class="custom-control-label" for="mcq_{{k}}_{{cid}}" ng-bind="choice.label"></label>
</div>

View File

@ -264,7 +264,7 @@ func (e Exercice) TriedCount() 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[string]string, respmcq map[int64]bool, t Team) (bool, error) {
func (e Exercice) CheckResponse(cksum []byte, respflags map[int64]string, respmcq map[int64]bool, t Team) (bool, error) {
if err := e.NewTry(t, cksum); err != nil {
return false, err
} else if flags, err := e.GetFlags(); err != nil {
@ -298,7 +298,7 @@ func (e Exercice) CheckResponse(cksum []byte, respflags map[string]string, respm
// Check flags
for _, flag := range flags {
if res, ok := respflags[flag.Label]; !ok {
if res, ok := respflags[flag.Id]; !ok {
valid = false
} else if !flag.Check([]byte(res)) {
if !PartialValidation || t.HasPartiallySolved(flag) == nil {

View File

@ -27,15 +27,19 @@ type myTeamMCQ struct {
Choices map[int64]string `json:"choices,omitempty"`
Solved *time.Time `json:"solved,omitempty"`
}
type myTeamFlag struct {
Label string `json:"label"`
Solved *time.Time `json:"found,omitempty"`
Soluce []byte `json:"soluce,omitempty"`
}
type myTeamExercice struct {
ThemeId int `json:"theme_id"`
Statement string `json:"statement"`
Hints []myTeamHint `json:"hints,omitempty"`
Gain int `json:"gain"`
Files []myTeamFile `json:"files,omitempty"`
Flags []string `json:"keys,omitempty"`
SolvedMat []bool `json:"solved_matrix,omitempty"`
MCQs []myTeamMCQ `json:"mcqs,omitempty"`
Flags map[int64]myTeamFlag `json:"flags,omitempty"`
MCQs map[int64]myTeamMCQ `json:"mcqs,omitempty"`
SolveDist int64 `json:"solve_dist,omitempty"`
SolvedTime time.Time `json:"solved_time,omitempty"`
SolvedRank int64 `json:"solved_rank,omitempty"`
@ -150,28 +154,32 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
// Expose exercice flags
var justifiedMCQ map[string]bool
exercice.Flags = []string{}
exercice.Flags = map[int64]myTeamFlag{}
if flags, err := e.GetFlags(); err != nil {
return nil, err
} else {
for _, k := range flags {
var flag myTeamFlag
if k.Label[0] == '%' {
justifiedMCQ[k.Label[1:]] = true
continue
} else if t == nil {
exercice.Flags = append(exercice.Flags, fmt.Sprintf("%x", k.Checksum)+k.Label)
} else {
exercice.Flags = append(exercice.Flags, k.Label)
if PartialValidation {
exercice.SolvedMat = append(exercice.SolvedMat, t.HasPartiallySolved(k) != nil)
}
flag.Soluce = k.Checksum
} else if PartialValidation {
flag.Solved = t.HasPartiallySolved(k)
}
flag.Label = k.Label
exercice.Flags[k.Id] = flag
}
}
// Expose exercice MCQs
exercice.MCQs = []myTeamMCQ{}
exercice.MCQs = map[int64]myTeamMCQ{}
if mcqs, err := e.GetMCQ(); err != nil {
return nil, err
@ -185,11 +193,14 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
justified = true
}
}
if t == nil {
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, justified, choices, nil})
} else {
exercice.MCQs = append(exercice.MCQs, myTeamMCQ{mcq.Title, justified, choices, t.HasPartiallyRespond(mcq)})
m := myTeamMCQ{mcq.Title, justified, choices, nil}
if t != nil {
m.Solved = t.HasPartiallyRespond(mcq)
}
exercice.MCQs[mcq.Id] = m
}
}