admin: new route to get exercice stats
This commit is contained in:
parent
c2887a1812
commit
ee2f65aae7
|
@ -22,6 +22,7 @@ func init() {
|
||||||
router.PATCH("/api/exercices/:eid", apiHandler(exerciceHandler(partUpdateExercice)))
|
router.PATCH("/api/exercices/:eid", apiHandler(exerciceHandler(partUpdateExercice)))
|
||||||
router.DELETE("/api/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
|
router.DELETE("/api/exercices/:eid", apiHandler(exerciceHandler(deleteExercice)))
|
||||||
|
|
||||||
|
router.GET("/api/exercices/:eid/stats", apiHandler(exerciceHandler(getExerciceStats)))
|
||||||
router.GET("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(getExerciceHistory)))
|
router.GET("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(getExerciceHistory)))
|
||||||
router.DELETE("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(delExerciceHistory)))
|
router.DELETE("/api/exercices/:eid/history.json", apiHandler(exerciceHandler(delExerciceHistory)))
|
||||||
|
|
||||||
|
@ -136,6 +137,15 @@ func showExercice(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||||
return exercice, nil
|
return exercice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getExerciceStats(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||||
|
team_tries, tries := exercice.TriesByTeam()
|
||||||
|
return map[string]interface{}{
|
||||||
|
"solved": exercice.SolvedTeams(),
|
||||||
|
"total_tried": tries,
|
||||||
|
"team_tries": team_tries,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
func getExerciceHistory(exercice fic.Exercice, body []byte) (interface{}, error) {
|
||||||
return exercice.GetHistory()
|
return exercice.GetHistory()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1197,6 +1197,12 @@ angular.module("FICApp")
|
||||||
} else {
|
} else {
|
||||||
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
|
$scope.exercice = Exercice.get({ exerciceId: $routeParams.exerciceId });
|
||||||
}
|
}
|
||||||
|
$http({
|
||||||
|
url: "/api/exercices/" + $routeParams.exerciceId + "/stats",
|
||||||
|
method: "GET"
|
||||||
|
}).then(function(response) {
|
||||||
|
$scope.stats = response.data;
|
||||||
|
});
|
||||||
$http({
|
$http({
|
||||||
url: "/api/themes.json",
|
url: "/api/themes.json",
|
||||||
method: "GET"
|
method: "GET"
|
||||||
|
|
|
@ -330,6 +330,21 @@ func (e Exercice) SolvedCount() int64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SolvedTeams returns the list of Team that already have solved the challenge.
|
||||||
|
func (e Exercice) SolvedTeams() (teams []int64) {
|
||||||
|
if rows, err := DBQuery("SELECT id_team FROM exercice_solved WHERE id_exercice = ?", e.Id); err == nil {
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var tid int64
|
||||||
|
if err := rows.Scan(&tid); err == nil {
|
||||||
|
teams = append(teams, tid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// TriedTeamCount returns the number of Team that attempted to solve the exercice.
|
// TriedTeamCount returns the number of Team that attempted to solve the exercice.
|
||||||
func (e Exercice) TriedTeamCount() int64 {
|
func (e Exercice) TriedTeamCount() int64 {
|
||||||
tries_table := "exercice_tries"
|
tries_table := "exercice_tries"
|
||||||
|
@ -345,6 +360,32 @@ func (e Exercice) TriedTeamCount() int64 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TbT struct {
|
||||||
|
IdTeam int64 `json:"id_team"`
|
||||||
|
Tries int64 `json:"tries"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// TriesByTeam returns the number of tries by Team.
|
||||||
|
func (e Exercice) TriesByTeam() (ts []TbT, sum int64) {
|
||||||
|
tries_table := "exercice_tries"
|
||||||
|
if SubmissionUniqueness {
|
||||||
|
tries_table = "exercice_distinct_tries"
|
||||||
|
}
|
||||||
|
|
||||||
|
if rows, err := DBQuery("SELECT id_team, COUNT(id_team) FROM " + tries_table + " WHERE id_exercice = ? GROUP BY id_team", e.Id); err == nil {
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var tbt TbT
|
||||||
|
if err := rows.Scan(&tbt.IdTeam, &tbt.Tries); err == nil {
|
||||||
|
sum += tbt.Tries
|
||||||
|
ts = append(ts, tbt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// TriedCount returns the number of cumulative attempts, all Team combined, for the exercice.
|
// TriedCount returns the number of cumulative attempts, all Team combined, for the exercice.
|
||||||
func (e Exercice) TriedCount() int64 {
|
func (e Exercice) TriedCount() int64 {
|
||||||
tries_table := "exercice_tries"
|
tries_table := "exercice_tries"
|
||||||
|
|
Loading…
Reference in New Issue