Add rank
This commit is contained in:
parent
0247c89b02
commit
3aafb15f19
4 changed files with 50 additions and 4 deletions
|
|
@ -81,6 +81,32 @@ func (t Team) GetPoints() (int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func GetRank() (map[int64]int, error) {
|
||||
if rows, err := DBQuery("SELECT id_team, SUM(E.gain) AS score, MAX(S.time) FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice GROUP BY id_team HAVING score > 0 ORDER BY score ASC, time ASC"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
rank := map[int64]int{}
|
||||
nteam := 0
|
||||
for rows.Next() {
|
||||
nteam += 1
|
||||
var tid int64
|
||||
var score int64
|
||||
var tzzz int64
|
||||
if err := rows.Scan(&tid, &score, &tzzz); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rank[tid] = nteam
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rank, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t Team) HasAccess(e Exercice) bool {
|
||||
if e.Depend == nil {
|
||||
return true
|
||||
|
|
|
|||
Reference in a new issue