admin: Retrieve stats on exercices
This commit is contained in:
parent
63b4cdc622
commit
b409fa6806
10 changed files with 241 additions and 19 deletions
|
@ -78,6 +78,7 @@ func declareExercicesRoutes(router *gin.RouterGroup) {
|
|||
apiQuizRoutes.PUT("", updateExerciceQuiz)
|
||||
apiQuizRoutes.DELETE("", deleteExerciceQuiz)
|
||||
apiQuizRoutes.GET("/dependancies", showExerciceQuizDeps)
|
||||
apiQuizRoutes.GET("/statistics", showExerciceQuizStats)
|
||||
|
||||
apiExercicesRoutes.GET("/tags", listExerciceTags)
|
||||
apiExercicesRoutes.POST("/tags", addExerciceTag)
|
||||
|
@ -864,7 +865,7 @@ func showExerciceFlagStats(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
var completed, tries, nteams int64
|
||||
var completed int64
|
||||
|
||||
for _, hline := range history {
|
||||
if hline["kind"].(string) == "flag_found" {
|
||||
|
@ -874,10 +875,24 @@ func showExerciceFlagStats(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
tries, err := flag.NbTries()
|
||||
if err != nil {
|
||||
log.Println("Unable to nbTries:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when retrieving flag tries"})
|
||||
return
|
||||
}
|
||||
|
||||
teams, err := flag.TeamsOnIt()
|
||||
if err != nil {
|
||||
log.Println("Unable to teamsOnIt:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when retrieving flag related teams"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"completed": completed,
|
||||
"tries": tries,
|
||||
"nteams": nteams,
|
||||
"teams": teams,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1051,6 +1066,48 @@ func showExerciceQuizDeps(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, deps)
|
||||
}
|
||||
|
||||
func showExerciceQuizStats(c *gin.Context) {
|
||||
exercice := c.MustGet("exercice").(*fic.Exercice)
|
||||
quiz := c.MustGet("flag-quiz").(*fic.MCQ)
|
||||
|
||||
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 int64
|
||||
|
||||
for _, hline := range history {
|
||||
if hline["kind"].(string) == "mcq_found" {
|
||||
if *hline["secondary"].(*int) == quiz.Id {
|
||||
completed += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tries, err := quiz.NbTries()
|
||||
if err != nil {
|
||||
log.Println("Unable to nbTries:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when retrieving flag tries"})
|
||||
return
|
||||
}
|
||||
|
||||
teams, err := quiz.TeamsOnIt()
|
||||
if err != nil {
|
||||
log.Println("Unable to teamsOnIt:", err.Error())
|
||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs when retrieving flag related teams"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"completed": completed,
|
||||
"tries": tries,
|
||||
"teams": teams,
|
||||
})
|
||||
}
|
||||
|
||||
func updateExerciceQuiz(c *gin.Context) {
|
||||
quiz := c.MustGet("flag-quiz").(*fic.MCQ)
|
||||
|
||||
|
|
Reference in a new issue