Coefficients transit and display on UI

This commit is contained in:
nemunaire 2017-01-16 13:09:31 +01:00
commit b42016c74a
7 changed files with 64 additions and 20 deletions

View file

@ -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