Write docs!

This commit is contained in:
nemunaire 2018-03-09 19:07:08 +01:00
commit bcc598ebd5
37 changed files with 478 additions and 188 deletions

View file

@ -6,7 +6,10 @@ import (
"time"
)
// FirstBlood is the coefficient added to the challenge coefficient when a Team is the first to solve a challenge.
var FirstBlood = 0.12
// SubmissionCostBase is the basis amount of point lost per submission
var SubmissionCostBase = 0.5
func exoptsQuery(whereExo string) string {
@ -19,6 +22,7 @@ func rankQuery(whereTeam string) string {
// Points
// EstimateGain calculates the amount of point the Team has (or could have, if not already solved) won.
func (e Exercice) EstimateGain(t Team, solved bool) (float64, error) {
var pts float64
err := DBQueryRow("SELECT SUM(A.points * A.coeff) AS score FROM (" + exoptsQuery("WHERE S.id_team = ? AND S.id_exercice = ?") + ") A GROUP BY id_team", t.Id, e.Id, t.Id, e.Id).Scan(&pts)
@ -33,6 +37,7 @@ func (e Exercice) EstimateGain(t Team, solved bool) (float64, error) {
}
}
// GetPoints returns the score for the Team.
func (t Team) GetPoints() (float64, error) {
var tid *int64
var nb *float64
@ -45,6 +50,7 @@ func (t Team) GetPoints() (float64, error) {
}
}
// GetRank returns a map which associates team ID their rank.
func GetRank() (map[int64]int, error) {
if rows, err := DBQuery(rankQuery("")); err != nil {
return nil, err
@ -72,11 +78,11 @@ func GetRank() (map[int64]int, error) {
}
// Tries
// Attempts
func GetTries(t *Team, e *Exercice) ([]time.Time, error) {
// GetTries retrieves all attempts made by the matching Team or challenge (both can be nil to not filter).
func GetTries(t *Team, e *Exercice) (times []time.Time, err error) {
var rows *sql.Rows
var err error
if t == nil {
if e == nil {
@ -93,26 +99,23 @@ func GetTries(t *Team, e *Exercice) ([]time.Time, error) {
}
if err != nil {
return nil, err
return
} 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
if err = rows.Scan(&tm); err != nil {
return
}
times = append(times, tm)
}
if err := rows.Err(); err != nil {
return nil, err
}
return times, nil
err = rows.Err()
return
}
}
// GetTryRank generates a special rank based on number of attempts
func GetTryRank() ([]int64, error) {
if rows, err := DBQuery("SELECT id_team, COUNT(*) AS score FROM exercice_tries GROUP BY id_team HAVING score > 0 ORDER BY score DESC"); err != nil {
return nil, err