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,7 +17,7 @@ import (
) )
type ResponsesUpload struct { type ResponsesUpload struct {
Keys map[string]string `json:"flags"` Keys map[int64]string `json:"flags"`
MCQs map[int64]bool `json:"mcqs"` MCQs map[int64]bool `json:"mcqs"`
} }

View File

@ -245,7 +245,6 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
}; };
}) })
.controller("SubmissionController", function($scope, $http, $rootScope, $timeout) { .controller("SubmissionController", function($scope, $http, $rootScope, $timeout) {
$scope.flags = [];
$rootScope.sberr = ""; $rootScope.sberr = "";
var waitMy = function() { var waitMy = function() {
@ -253,34 +252,13 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$timeout.cancel($scope.cbs); $timeout.cancel($scope.cbs);
$scope.cbs = $timeout(waitMy, 420); $scope.cbs = $timeout(waitMy, 420);
} else { } 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) { 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) { angular.forEach(mcq["choices"], function(choice,cid) {
this[cid] = { this[cid] = {
label: choice, label: choice,
value: false value: false
}; };
}, o["choices"]); }, mcq["choices"]);
this.push(o);
}, $scope.mcqs); }, $scope.mcqs);
} }
} }
@ -289,18 +267,18 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$scope.ssubmit = function() { $scope.ssubmit = function() {
var resp = {} 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"] = {}; resp["flags"] = {};
angular.forEach($scope.flags, function(flag,kid) { angular.forEach($scope.my.exercices[$rootScope.current_exercice].flags, function(flag,kid) {
resp["flags"][flag.name] = flag.value; 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"] = {}; 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) { angular.forEach(mcq.choices, function(choice, cid) {
if (choice.value) resp["mcqs"][cid] = choice.value; 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])"> <a ng-href="/{{ themes[current_theme].urlid }}/{{ themes[current_theme].exercices[k].urlid }}" ng-if="(k != current_exercice && my.exercices[k])">
{{ exercice.title }} {{ 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-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> </a>
<strong ng-if="k == current_exercice" class="text-info">{{ exercice.title }}</strong> <strong ng-if="k == current_exercice" class="text-info">{{ exercice.title }}</strong>
</li> </li>
@ -77,16 +77,16 @@
</ul> </ul>
<div class="card-body" ng-if="!my.exercices[current_exercice].submitted || sberr"> <div class="card-body" ng-if="!my.exercices[current_exercice].submitted || sberr">
<form ng-controller="SubmissionController" ng-submit="ssubmit()"> <form ng-controller="SubmissionController" ng-submit="ssubmit()">
<div class="form-group" ng-repeat="key in flags"> <div class="form-group" ng-repeat="(kid,key) in my.exercices[current_exercice].flags">
<label for="sol_{{ key.id }}">{{ key.name }}&nbsp;:</label> <label for="sol_{{ kid }}">{{ key.label }}&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"> <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> <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>
<div class="form-check" ng-repeat="(k,mcq) in mcqs"> <div class="form-check" ng-repeat="(k,mcq) in my.exercices[current_exercice].mcqs">
<p ng-if="mcq.title" ng-bind="mcq.title"></p> <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"> <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">
<label class="custom-control-label" for="mcq_{{k}}_{{cid}}" ng-bind="choice.label"></label> <label class="custom-control-label" for="mcq_{{k}}_{{cid}}" ng-bind="choice.label"></label>
</div> </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). // 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). // 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 { if err := e.NewTry(t, cksum); err != nil {
return false, err return false, err
} else if flags, err := e.GetFlags(); err != nil { } 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 // Check flags
for _, flag := range flags { for _, flag := range flags {
if res, ok := respflags[flag.Label]; !ok { if res, ok := respflags[flag.Id]; !ok {
valid = false valid = false
} else if !flag.Check([]byte(res)) { } else if !flag.Check([]byte(res)) {
if !PartialValidation || t.HasPartiallySolved(flag) == nil { if !PartialValidation || t.HasPartiallySolved(flag) == nil {

View File

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