admin: Start compute flag stats
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
57c3cd8fd6
commit
a5fd04672b
3 changed files with 52 additions and 1 deletions
|
|
@ -62,6 +62,7 @@ func declareExercicesRoutes(router *gin.RouterGroup) {
|
|||
apiFlagsRoutes.POST("/try", tryExerciceFlag)
|
||||
apiFlagsRoutes.DELETE("/", deleteExerciceFlag)
|
||||
apiFlagsRoutes.GET("/dependancies", showExerciceFlagDeps)
|
||||
apiFlagsRoutes.GET("/statistics", showExerciceFlagStats)
|
||||
apiFlagsRoutes.GET("/choices/", listFlagChoices)
|
||||
apiFlagsChoicesRoutes := apiExercicesRoutes.Group("/choices/:cid")
|
||||
apiFlagsChoicesRoutes.Use(FlagChoiceHandler)
|
||||
|
|
@ -852,6 +853,34 @@ func showExerciceFlagDeps(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, deps)
|
||||
}
|
||||
|
||||
func showExerciceFlagStats(c *gin.Context) {
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
flag := c.MustGet("flag-key").(*fic.FlagKey)
|
||||
|
||||
history, err := exercice.GetHistory()
|
||||
if err != nil {
|
||||
log.Println("Unable to getExerciceHistory:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when retrieving exercice history"})
|
||||
return
|
||||
}
|
||||
|
||||
var completed, tries, nteams int64
|
||||
|
||||
for _, hline := range history {
|
||||
if hline["kind"].(string) == "flag_found" {
|
||||
if *hline["secondary"].(*int) == flag.Id {
|
||||
completed += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"completed": completed,
|
||||
"tries": tries,
|
||||
"nteams": nteams,
|
||||
})
|
||||
}
|
||||
|
||||
func tryExerciceFlag(c *gin.Context) {
|
||||
flag := c.MustGet("flag-key").(*fic.FlagKey)
|
||||
|
||||
|
|
@ -1048,7 +1077,11 @@ func updateExerciceQuiz(c *gin.Context) {
|
|||
if cur.Id == next.Id {
|
||||
seen = true
|
||||
|
||||
log.Println("ici", cur.Label, cur.Response, next.Response)
|
||||
|
||||
if cur.Label != next.Label || cur.Response != next.Response {
|
||||
log.Println("1", cur.Label, cur.Response, next.Response)
|
||||
|
||||
cur.Label = next.Label
|
||||
cur.Response = next.Response
|
||||
if _, err := cur.Update(); err != nil {
|
||||
|
|
|
|||
Reference in a new issue