From 195490484c7820187ee75d939f320a5772138477 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 28 Nov 2018 02:27:51 +0100 Subject: [PATCH] Change exported flags format in my.json --- backend/submission.go | 4 ++-- frontend/static/js/challenge.js | 34 +++++---------------------- frontend/static/views/defi.html | 16 ++++++------- libfic/exercice.go | 4 ++-- libfic/team_my.go | 41 +++++++++++++++++++++------------ 5 files changed, 44 insertions(+), 55 deletions(-) diff --git a/backend/submission.go b/backend/submission.go index c5bb1eb1..12f9c1fa 100644 --- a/backend/submission.go +++ b/backend/submission.go @@ -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) { diff --git a/frontend/static/js/challenge.js b/frontend/static/js/challenge.js index 24988c47..2f5ee85a 100644 --- a/frontend/static/js/challenge.js +++ b/frontend/static/js/challenge.js @@ -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; }) diff --git a/frontend/static/views/defi.html b/frontend/static/views/defi.html index b7218a13..de785142 100644 --- a/frontend/static/views/defi.html +++ b/frontend/static/views/defi.html @@ -5,7 +5,7 @@ {{ exercice.title }} - + {{ exercice.title }} @@ -77,16 +77,16 @@
-
- - +
+ + - +
-
-

-
+
+

{{ mcq.title }}

+
diff --git a/libfic/exercice.go b/libfic/exercice.go index 8ec7f32e..bb05c879 100644 --- a/libfic/exercice.go +++ b/libfic/exercice.go @@ -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 { diff --git a/libfic/team_my.go b/libfic/team_my.go index 5881b313..3db03e23 100644 --- a/libfic/team_my.go +++ b/libfic/team_my.go @@ -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 } }