admin: new route to get exercice stats
This commit is contained in:
parent
c2887a1812
commit
ee2f65aae7
3 changed files with 57 additions and 0 deletions
|
|
@ -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.
|
||||
func (e Exercice) TriedTeamCount() int64 {
|
||||
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.
|
||||
func (e Exercice) TriedCount() int64 {
|
||||
tries_table := "exercice_tries"
|
||||
|
|
|
|||
Reference in a new issue