admin: Add stats about submissions rate
This commit is contained in:
parent
116c061715
commit
329bd246c7
4 changed files with 144 additions and 1 deletions
|
|
@ -179,6 +179,41 @@ func GetTries(t *Team, e *Exercice) (times []time.Time, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetValidations retrieves all flag validation made by the matching Team or challenge (both can be nil to not filter).
|
||||
func GetValidations(t *Team, e *Exercice) (times []time.Time, err error) {
|
||||
var rows *sql.Rows
|
||||
|
||||
if t == nil {
|
||||
if e == nil {
|
||||
rows, err = DBQuery("SELECT time FROM flag_found UNION SELECT time FROM mcq_found ORDER BY time ASC")
|
||||
} else {
|
||||
rows, err = DBQuery("SELECT time FROM flag_found WHERE id_exercice = ? UNION SELECT time FROM mcq_found WHERE id_exercice = ? ORDER BY time ASC", e.Id, e.Id)
|
||||
}
|
||||
} else {
|
||||
if e == nil {
|
||||
rows, err = DBQuery("SELECT time FROM flag_found WHERE id_team = ? UNION SELECT time FROM mcq_found WHERE id_team = ? ORDER BY time ASC", t.Id, t.Id)
|
||||
} else {
|
||||
rows, err = DBQuery("SELECT time FROM flag_found WHERE id_team = ? AND id_exercice = ? UNION SELECT time FROM mcq_found WHERE id_team = ? AND id_exercice = ? ORDER BY time ASC", t.Id, e.Id, t.Id, e.Id)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var tm time.Time
|
||||
if err = rows.Scan(&tm); err != nil {
|
||||
return
|
||||
}
|
||||
times = append(times, tm)
|
||||
}
|
||||
err = rows.Err()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// GetTryRank generates a special rank based on number of attempts
|
||||
func GetTryRank() ([]int64, error) {
|
||||
if rows, err := DBQuery("SELECT id_team, COUNT(*) AS score FROM exercice_tries GROUP BY id_team HAVING score > 0 ORDER BY score DESC"); err != nil {
|
||||
|
|
|
|||
Reference in a new issue