admin: add some stats about exercices
This commit is contained in:
parent
007efc6118
commit
5df1cc6e93
5 changed files with 104 additions and 8 deletions
|
@ -23,6 +23,7 @@ func init() {
|
|||
router.DELETE("/api/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
|
||||
|
||||
router.GET("/api/exercices/:eid/stats.json", apiHandler(exerciceHandler(getExerciceStats)))
|
||||
router.GET("/api/exercices_stats.json", apiHandler(getExercicesStats))
|
||||
|
||||
router.GET("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(getExerciceHistory)))
|
||||
router.PATCH("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(updateExerciceHistory)))
|
||||
|
@ -170,9 +171,12 @@ func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error)
|
|||
}
|
||||
|
||||
type exerciceStats struct {
|
||||
TeamTries int64 `json:"team_tries"`
|
||||
TotalTries int64 `json:"total_tries"`
|
||||
SolvedCount int64 `json:"solved_count"`
|
||||
IdExercice int64 `json:"id_exercice,omitempty"`
|
||||
TeamTries int64 `json:"team_tries"`
|
||||
TotalTries int64 `json:"total_tries"`
|
||||
SolvedCount int64 `json:"solved_count"`
|
||||
FlagSolved []int64 `json:"flag_solved"`
|
||||
MCQSolved []int64 `json:"mcq_solved"`
|
||||
}
|
||||
|
||||
func getExerciceStats(e fic.Exercice, body []byte) (interface{}, error) {
|
||||
|
@ -180,9 +184,30 @@ func getExerciceStats(e fic.Exercice, body []byte) (interface{}, error) {
|
|||
TeamTries: e.TriedTeamCount(),
|
||||
TotalTries: e.TriedCount(),
|
||||
SolvedCount: e.SolvedCount(),
|
||||
FlagSolved: e.FlagSolved(),
|
||||
MCQSolved: e.MCQSolved(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getExercicesStats(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
if exercices, err := fic.GetExercices(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
ret := []exerciceStats{}
|
||||
for _, e := range exercices {
|
||||
ret = append(ret, exerciceStats{
|
||||
IdExercice: e.Id,
|
||||
TeamTries: e.TriedTeamCount(),
|
||||
TotalTries: e.TriedCount(),
|
||||
SolvedCount: e.SolvedCount(),
|
||||
FlagSolved: e.FlagSolved(),
|
||||
MCQSolved: e.MCQSolved(),
|
||||
})
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
|
||||
type uploadedExerciceHistory struct {
|
||||
IdTeam int64 `json:"team_id"`
|
||||
Kind string
|
||||
|
|
Reference in a new issue