New rank and score calculation
This commit is contained in:
parent
184612a12c
commit
884e985357
@ -7,9 +7,9 @@ import (
|
||||
|
||||
// Points
|
||||
|
||||
func (t Team) GetPoints() (int64, error) {
|
||||
var nb *int64
|
||||
err := DBQueryRow("SELECT SUM(E.gain) AS gains FROM exercice_solved S INNER JOIN exercices E ON E.id_exercice = S.id_exercice WHERE id_team = ?", t.Id).Scan(&nb)
|
||||
func (t Team) GetPoints() (float64, error) {
|
||||
var nb *float64
|
||||
err := DBQueryRow("SELECT SUM(A.points * A.coeff) AS score FROM (SELECT S.id_team, E.gain AS points, coeff FROM (SELECT id_team, id_exercice, MIN(time) AS time, 0.12 AS coeff FROM exercice_solved GROUP BY id_exercice UNION SELECT id_team, id_exercice, time, 1 AS coeff FROM exercice_solved) S INNER JOIN exercices E ON S.id_exercice = E.id_exercice UNION ALL SELECT D.id_team, H.cost AS points, -1.0 AS coeff FROM team_hints D INNER JOIN exercice_hints H ON H.id_hint = D.id_hint UNION ALL SELECT id_team, ((FLOOR(COUNT(*)/10 - 1) * (FLOOR(COUNT(*)/10)))/0.2 + (FLOOR(COUNT(*)/10) * (COUNT(*)%10)))/2 AS points, -1 AS coeff FROM exercice_tries GROUP BY id_exercice HAVING points != 0) A WHERE A.id_team = ? GROUP BY A.id_team", t.Id).Scan(&nb)
|
||||
if nb != nil {
|
||||
return *nb, err
|
||||
} else {
|
||||
@ -18,7 +18,7 @@ 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 DESC, time ASC"); err != nil {
|
||||
if rows, err := DBQuery("SELECT A.id_team, SUM(A.points * A.coeff) AS score, MAX(A.time) AS time FROM (SELECT S.id_team, S.time, E.gain AS points, coeff FROM (SELECT id_team, id_exercice, MIN(time) AS time, 0.12 AS coeff FROM exercice_solved GROUP BY id_exercice UNION SELECT id_team, id_exercice, time, 1 AS coeff FROM exercice_solved) S INNER JOIN exercices E ON S.id_exercice = E.id_exercice UNION ALL SELECT D.id_team, D.time, H.cost AS points, -1.0 AS coeff FROM team_hints D INNER JOIN exercice_hints H ON H.id_hint = D.id_hint UNION ALL SELECT id_team, MAX(time) AS time, ((FLOOR(COUNT(*)/10 - 1) * (FLOOR(COUNT(*)/10)))/0.2 + (FLOOR(COUNT(*)/10) * (COUNT(*)%10)))/2 AS points, -1 AS coeff FROM exercice_tries GROUP BY id_exercice HAVING points != 0) A GROUP BY A.id_team ORDER BY score DESC, time ASC"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
@ -28,7 +28,7 @@ func GetRank() (map[int64]int, error) {
|
||||
for rows.Next() {
|
||||
nteam += 1
|
||||
var tid int64
|
||||
var score int64
|
||||
var score float64
|
||||
var tzzz time.Time
|
||||
if err := rows.Scan(&tid, &score, &tzzz); err != nil {
|
||||
return nil, err
|
||||
|
@ -8,7 +8,7 @@ type exportedTeam struct {
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
Rank int `json:"rank"`
|
||||
Points int64 `json:"score"`
|
||||
Points float64 `json:"score"`
|
||||
}
|
||||
|
||||
func ExportTeams() (interface{}, error) {
|
||||
@ -19,9 +19,7 @@ func ExportTeams() (interface{}, error) {
|
||||
} else {
|
||||
ret := map[string]exportedTeam{}
|
||||
for _, team := range teams {
|
||||
if points, err := team.GetPoints(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
points, _ := team.GetPoints()
|
||||
ret[fmt.Sprintf("%d", team.Id)] = exportedTeam{
|
||||
team.Name,
|
||||
fmt.Sprintf("#%x", team.Color),
|
||||
@ -29,7 +27,6 @@ func ExportTeams() (interface{}, error) {
|
||||
points,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
@ -50,7 +50,8 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
||||
} else {
|
||||
ret.Name = t.Name
|
||||
ret.Id = t.Id
|
||||
ret.Points, _ = t.GetPoints()
|
||||
points, _ := t.GetPoints()
|
||||
ret.Points = int64(points)
|
||||
if members, err := t.GetMembers(); err == nil {
|
||||
ret.Members = members
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user