Coefficients transit and display on UI
This commit is contained in:
parent
5a37158f45
commit
cec3600a38
7 changed files with 64 additions and 20 deletions
|
|
@ -129,17 +129,23 @@ func (t Team) OpenHint(h EHint) (error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func (t Team) CountTries(e Exercice) (int64, time.Time) {
|
||||
var nb *int64
|
||||
var tm *time.Time
|
||||
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil {
|
||||
return 0, time.Unix(0, 0)
|
||||
} else if nb == nil {
|
||||
return 0, *tm
|
||||
} else {
|
||||
return *nb, *tm
|
||||
}
|
||||
}
|
||||
|
||||
func (t Team) HasSolved(e Exercice) (bool, time.Time, int64) {
|
||||
var nb *int64
|
||||
var tm *time.Time
|
||||
if DBQueryRow("SELECT MIN(time) FROM exercice_solved WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&tm); tm == nil {
|
||||
if DBQueryRow("SELECT COUNT(id_exercice), MAX(time) FROM exercice_tries WHERE id_team = ? AND id_exercice = ?", t.Id, e.Id).Scan(&nb, &tm); tm == nil {
|
||||
return false, time.Unix(0, 0), 0
|
||||
} else if nb == nil {
|
||||
return false, *tm, 0
|
||||
} else {
|
||||
return false, *tm, *nb
|
||||
}
|
||||
return false, time.Unix(0, 0), 0
|
||||
} else if DBQueryRow("SELECT COUNT(id_exercice) FROM exercice_solved WHERE id_exercice = ? AND time < ?", e.Id, tm).Scan(&nb); nb == nil {
|
||||
return true, *tm, 0
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package fic
|
|||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"path"
|
||||
)
|
||||
|
|
@ -24,13 +25,13 @@ type myTeamExercice struct {
|
|||
ThemeId int `json:"theme_id"`
|
||||
Statement string `json:"statement"`
|
||||
Hints []myTeamHint `json:"hints"`
|
||||
Gain int64 `json:"gain"`
|
||||
Gain float64 `json:"gain"`
|
||||
Files []myTeamFile `json:"files"`
|
||||
Keys []string `json:"keys"`
|
||||
Solved bool `json:"solved"`
|
||||
SolvedMat []bool `json:"solved_matrix"`
|
||||
SolvedTime time.Time `json:"solved_time"`
|
||||
SolvedNumber int64 `json:"solved_number"`
|
||||
SolvedRank int64 `json:"solved_rank"`
|
||||
Tries int64 `json:"tries"`
|
||||
VideoURI string `json:"video_uri"`
|
||||
}
|
||||
type myTeam struct {
|
||||
|
|
@ -72,10 +73,24 @@ func MyJSONTeam(t *Team, started bool) (interface{}, error) {
|
|||
exercice.Statement = e.Statement
|
||||
if t == nil {
|
||||
exercice.VideoURI = e.VideoURI
|
||||
exercice.Solved = true
|
||||
exercice.SolvedNumber = e.TriedCount()
|
||||
exercice.SolvedRank = 1
|
||||
exercice.Tries = e.TriedCount()
|
||||
exercice.Gain = float64(e.Gain) * e.Coefficient
|
||||
} else {
|
||||
exercice.Solved, exercice.SolvedTime, exercice.SolvedNumber = t.HasSolved(e)
|
||||
var solved bool
|
||||
solved, exercice.SolvedTime, exercice.SolvedRank = t.HasSolved(e)
|
||||
|
||||
if solved {
|
||||
exercice.Tries, _ = t.CountTries(e)
|
||||
} else {
|
||||
exercice.Tries, exercice.SolvedTime = t.CountTries(e)
|
||||
}
|
||||
|
||||
if gain, err := e.EstimateGain(*t, solved); err == nil {
|
||||
exercice.Gain = gain
|
||||
} else {
|
||||
log.Println("ERROR during gain estimation:", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Expose exercice files
|
||||
|
|
|
|||
Reference in a new issue