[admin] Can retrieves tries rate

This commit is contained in:
nemunaire 2016-10-13 19:52:13 +02:00
parent b618d4f886
commit e11cd88ee2
2 changed files with 60 additions and 0 deletions

View File

@ -85,6 +85,8 @@ func listTeam(args []string, body []byte) (interface{}, error) {
return fic.MyJSONTeam(team, true)
} else if args[1] == "wait.json" {
return fic.MyJSONTeam(team, false)
} else if args[1] == "tries" {
return fic.GetTries(team, nil)
} else if team != nil && args[1] == "members" {
return team.GetMembers()
} else if args[1] == "certificate" && team != nil {
@ -95,6 +97,8 @@ func listTeam(args []string, body []byte) (interface{}, error) {
} else if len(args) == 1 {
if args[0] == "teams.json" {
return fic.ExportTeams()
} else if args[0] == "tries" {
return fic.GetTries(nil, nil)
} else if args[0] == "nginx" {
return nginxGenTeam()
} else if args[0] == "binding" {

View File

@ -1,6 +1,7 @@
package fic
import (
"database/sql"
"fmt"
"time"
)
@ -152,6 +153,61 @@ func (t Team) HasAccess(e Exercice) bool {
}
}
func NbTry(t *Team, e Exercice) int {
var cnt *int
if t != nil {
DBQueryRow("SELECT COUNT(*) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&cnt)
} else {
DBQueryRow("SELECT COUNT(*) FROM exercice_tries WHERE id_exercice = ?", e.Id).Scan(&cnt)
}
if cnt == nil {
return 0
} else {
return *cnt
}
}
func GetTries(t *Team, e *Exercice) ([]time.Time, error) {
var rows *sql.Rows
var err error
if t == nil {
if e == nil {
rows, err = DBQuery("SELECT time FROM exercice_tries ORDER BY time ASC")
} else {
rows, err = DBQuery("SELECT time FROM exercice_tries WHERE id_exercice = ? ORDER BY time ASC", e.Id)
}
} else {
if e == nil {
rows, err = DBQuery("SELECT time FROM exercice_tries WHERE id_team = ? ORDER BY time ASC", t.Id)
} else {
rows, err = DBQuery("SELECT time FROM exercice_tries WHERE id_team = ? AND id_exercice = ? ORDER BY time ASC", t.Id, e.Id)
}
}
if err != nil {
return nil, err
} else {
defer rows.Close()
times := make([]time.Time, 0)
for rows.Next() {
var tm time.Time
if err := rows.Scan(&tm); err != nil {
return nil, err
}
times = append(times, tm)
}
if err := rows.Err(); err != nil {
return nil, err
}
return times, nil
}
}
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
var nb *int64
var tm *time.Time