Documentation ¶
Index ¶
- Variables
- func AddCompetitorToEvent(competitorID, eventID int) (err error)
- func AddRing(ring *Ring)
- func AdjustedAverage(scores []*Score) float64
- func CalculateDifficulty(nandu []Nandu) float64
- func ChangeEventRing(ringID, eventID int) (err error)
- func ChangeEventRules(eventID, rulesetID int) (err error)
- func ClearScores(routineID, ringID int) error
- func ClearState()
- func Connect(cfg *Config) error
- func CreateUser(username string, password []byte) error
- func CreateWebSession(key string, username string, created, expires time.Time) error
- func Delete(query string, values []interface{}) error
- func DeleteScore(scoreID int) error
- func DetermineDeductions(deductions map[string][]*DeductionMark) map[string][]DeductionResult
- func FindAllAroundWinner() ([]string, error)
- func FormatScore(score float64) string
- func FormatTimestamp(timestamp time.Time) string
- func GetAllRankings() ([]map[string]interface{}, error)
- func GetEventRanks(eventID int) ([]map[string]interface{}, error)
- func GetFinalScore(routineID int) (string, error)
- func GetNanduResults(routineID int) (map[string]string, error)
- func GetRulesets() ([]map[string]interface{}, error)
- func GetScores(routineID int) (map[string]*Score, error)
- func GetSimpleRanks(eventID int) ([]map[string]interface{}, error)
- func GetTopScores(competitorID int) (float64, error)
- func IsConnection(code string) bool
- func NanduMarksToSlice(marks string) []bool
- func Query(query string, values []interface{}) ([]map[string]interface{}, error)
- func QueryWithRowScan(query string, values []interface{}, rowScanner func(*sql.Rows) error) error
- func RemoveCompetitorFromEvent(competitorID, eventID int) (err error)
- func RemoveDeductionMark(id int) (err error)
- func SaveAdjustment(amount float64, reason string, routineID int, judgeTag string) (err error)
- func SaveDeductionMark(dm *DeductionMark) (err error)
- func SaveFinalScore(score, total string, elapsed string, eventID, competitorID int) (err error)
- func SaveNanduScore(routineID int, judgeID string, result string) (err error)
- func SaveScore(score float64, ringID int, judgeID string) error
- func SliceToNanduMarks(s []bool) string
- func ToTechnicalScore(deductions []DeductionResult, style Style) float64
- func UpdateDeductionMark(id int, code string) (err error)
- type Adjustment
- type AgeGroup
- type Category
- type Competitor
- type Config
- type DeductionCode
- type DeductionMark
- type DeductionResult
- type DeductionSheet
- type Event
- type Experience
- type Gender
- type Judge
- type Listener
- type Nandu
- type NanduCode
- type Nandusheet
- type Ring
- type RingState
- func (r *RingState) AddJudge(connID, tag string) bool
- func (r *RingState) AddListener(connID, tag string) bool
- func (r *RingState) CalculateScore() (result float64, components map[string]float64)
- func (r *RingState) ClearScores()
- func (r *RingState) DeleteDeduction(judgeTag string, id int)
- func (r *RingState) Duration() time.Duration
- func (r *RingState) FinalizeScore() error
- func (r *RingState) HeadJudge() *Judge
- func (r *RingState) Judges() []*Judge
- func (r *RingState) Listeners() []*Listener
- func (r *RingState) ParseNanduScores(judgeTag string, results []bool)
- func (r *RingState) PerformanceScores() []*Score
- func (r *RingState) ReadDone()
- func (r *RingState) RemoveJudge(connID string) bool
- func (r *RingState) RemoveListener(connID string) bool
- func (r *RingState) SetAdjustment(judgeTag string, amount float64, reason string)
- func (r *RingState) SetCompetitor(newComp *Competitor, event *Event)
- func (r *RingState) SetDeduction(dm *DeductionMark)
- func (r *RingState) SetEvent(newEvent *Event)
- func (r *RingState) SetEventStart(startTime time.Time)
- func (r *RingState) SetEventStop(stopTime time.Time)
- func (r *RingState) SetHeadJudge(connID, tag string) bool
- func (r *RingState) SetPerformanceScore(judgeTag string, score float64)
- func (r *RingState) UpdateDeduction(judgeTag string, id int, code string)
- type Routine
- type Ruleset
- type Score
- type Session
- type State
- type Style
- type User
Constants ¶
This section is empty.
Variables ¶
var ( InvalidDeduction = DeductionCode{"", 0.0, ""} NorthernDeductions = map[string]DeductionCode{ "10": {"10", 0.1, ""}, "11": {"11", 0.1, ""}, "12": {"12", 0.1, ""}, "13": {"13", 0.1, ""}, "14": {"14", 0.1, ""}, "20": {"20", 0.1, ""}, "21": {"21", 0.1, ""}, "22": {"22", 0.1, ""}, "23": {"23", 0.1, ""}, "30": {"30", 0.1, ""}, "31": {"31", 0.1, ""}, "32": {"32", 0.1, ""}, "33": {"33", 0.1, ""}, "34": {"34", 0.1, ""}, "50": {"50", 0.1, ""}, "51": {"51", 0.1, ""}, "52": {"52", 0.1, ""}, "60": {"60", 0.1, ""}, "61": {"61", 0.1, ""}, "62": {"62", 0.1, ""}, "63": {"63", 0.1, ""}, "64": {"64", 0.1, ""}, "65": {"65", 0.1, ""}, "66": {"66", 0.1, ""}, } TaijiDeductions = map[string]DeductionCode{ "15": {"15", 0.1, ""}, "16": {"16", 0.1, ""}, "17": {"17", 0.1, ""}, "18": {"18", 0.1, ""}, "24": {"24", 0.1, ""}, "25": {"25", 0.1, ""}, "26": {"26", 0.1, ""}, "27": {"27", 0.1, ""}, "30": {"30", 0.1, ""}, "31": {"31", 0.1, ""}, "50": {"50", 0.1, ""}, "53": {"53", 0.1, ""}, "54": {"54", 0.1, ""}, "60": {"60", 0.1, ""}, "61": {"61", 0.1, ""}, } SouthernDeductions = map[string]DeductionCode{ "22": {"22", 0.1, ""}, "28": {"28", 0.1, ""}, "30": {"30", 0.1, ""}, "40": {"40", 0.1, ""}, "41": {"41", 0.1, ""}, "42": {"42", 0.1, ""}, "50": {"50", 0.1, ""}, "51": {"51", 0.1, ""}, "52": {"52", 0.1, ""}, "53": {"53", 0.1, ""}, "55": {"55", 0.1, ""}, "56": {"56", 0.1, ""}, "57": {"57", 0.1, ""}, "62": {"62", 0.1, ""}, "67": {"67", 0.1, ""}, } GeneralDeductions = map[string]DeductionCode{ "01": {"01", 0.2, ""}, "02": {"02", 0.2, ""}, "03": {"03", 0.2, ""}, "04": {"04", 0.2, ""}, "05": {"05", 0.2, ""}, "06": {"06", 0.2, ""}, "07": {"07", 0.2, ""}, "08": {"08", 0.2, ""}, "70": {"70", 0.1, ""}, "71": {"71", 0.2, ""}, "72": {"72", 0.3, ""}, "73": {"73", 0.1, ""}, "74": {"74", 0.2, ""}, "75": {"75", 0.3, ""}, "76": {"76", 0.1, ""}, "77": {"77", 0.1, ""}, "78": {"78", 0.1, ""}, "79": {"79", 0.1, ""}, "80": {"80", 0.2, ""}, "81": {"81", 0.1, ""}, "82": {"82", 0.1, ""}, "83": {"83", 0.1, ""}, "84": {"84", 0.3, ""}, "85": {"85", 0.5, ""}, "86": {"86", 0.2, ""}, "87": {"87", 0.2, ""}, "88": {"88", 0.2, ""}, } InvalidNanduCode = NanduCode{"", 0.0, ""} NanduCodes = map[string]NanduCode{ "111A": {"111A", 0.2, "standing leg to head"}, "112A": {"112A", 0.2, "side kick and hold leg"}, "113A": {"113A", 0.2, "backward balance"}, "143A": {"143A", 0.2, "low balance with leg forward"}, "142A": {"142A", 0.2, "low stepping on kick forward"}, "132A": {"132A", 0.2, "balance with sideward sole kick"}, "133B": {"133B", 0.3, "balance with arms spread"}, "143B": {"143B", 0.3, "low balance with leg behind support leg"}, "112C": {"112C", 0.4, "back kick and hold leg"}, "113C": {"113C", 0.4, "raise leg sideways with heel up"}, "244A": {"244A", 0.2, "540 front sweep"}, "212A": {"212A", 0.2, "parting kick and heel kick"}, "244B": {"244B", 0.3, "900 front sweep"}, "323A": {"323A", 0.2, "360 tornado kick"}, "333A": {"333A", 0.2, "butterfly"}, "324A": {"324A", 0.2, "360 lotus kick"}, "335A": {"335A", 0.2, "aerial cartwheel"}, "312A": {"312A", 0.2, "kick in flight"}, "346A": {"346A", 0.2, "backflip"}, "323B": {"323B", 0.3, "540 tornado kick"}, "353B": {"353B", 0.3, "360 butterfly"}, "324B": {"324B", 0.3, "540 lotus kick"}, "355B": {"355B", 0.3, "360 aerial cartwheel"}, "312B": {"312B", 0.3, "front kick in flight"}, "322B": {"322B", 0.3, "180 kick in flight"}, "346B": {"346B", 0.3, "single-step backflip (gainer)"}, "355C": {"355C", 0.4, "720 aerial cartwheel"}, "323C": {"323C", 0.4, "720 tornado kick"}, "353C": {"353C", 0.4, "720 butterfly"}, "324C": {"324C", 0.4, "720 lotus kick"}, "366C": {"366C", 0.4, "360 single-step back butterfly"}, "415A": {"415A", 0.2, "double sidekick in flight"}, "423A": {"423A", 0.2, "360 tornado land on side"}, "447C": {"447C", 0.4, "kip-up"}, } TaijiNanduCodes = map[string]NanduCode{ "323B": {"323B", 0.3, "360 tornado kick"}, "323C": {"323C", 0.4, "540 tornado kick"}, "324B": {"324B", 0.3, "360 lotus kick"}, "324C": {"324C", 0.4, "540 lotus kick"}, } NanduConnectionCodes = map[string]NanduCode{ "(A)": {"(A)", 0.1, ""}, "1A": {"1A", 0.1, "horse stance"}, "2A": {"2A", 0.1, "butterfly stance"}, "3A": {"3A", 0.1, "standing with knee raised"}, "4A": {"4A", 0.1, "front split"}, "6A": {"6A", 0.1, "sitting position"}, "7A": {"7A", 0.1, "bow stance"}, "8A": {"8A", 0.1, "throw and catch"}, "9A": {"9A", 0.1, "land on takeoff foot"}, "(B)": {"(B)", 0.15, ""}, "1B": {"1B", 0.15, "horse stance"}, "2B": {"2B", 0.15, "butterfly stance"}, "3B": {"3B", 0.15, "stand with knee raised"}, "4B": {"4B", 0.15, "front split"}, "5B": {"5B", 0.15, "dragons dive"}, "8B": {"8B", 0.15, "throw and catch"}, "(C)": {"(C)", 0.2, ""}, "1C": {"1C", 0.2, "horse stance"}, "2C": {"2C", 0.2, "butterfly stance"}, "3C": {"3C", 0.2, "stand with knee raised"}, "5C": {"5C", 0.2, "dragons dive"}, "1D": {"1D", 0.25, "horse stance"}, "3D": {"3D", 0.25, "stand with knee raised"}, "4D": {"4D", 0.25, "front split"}, } )
var AllExperiences = []Experience{Beginner, Intermediate, Advanced, FirstTimer}
var AllGenders = []Gender{Female, Male}
var AllRulesets = []Ruleset{USWU, IWUF, IWUFAB}
var AllStyles = []Style{Changquan, Daoshu, Jianshu, Gunshu, Qiangshu, Nanquan, Nandao, Nangun, Taijiquan, Taijijian}
var (
ClientSettings = make(map[string]string)
)
Functions ¶
func AddCompetitorToEvent ¶
func AdjustedAverage ¶
func CalculateDifficulty ¶
func ChangeEventRing ¶
func ChangeEventRules ¶
func ClearScores ¶
func ClearState ¶
func ClearState()
func CreateUser ¶
CreateUser saves the given credentials in the database
func CreateWebSession ¶
func DeleteScore ¶
func DetermineDeductions ¶
func DetermineDeductions(deductions map[string][]*DeductionMark) map[string][]DeductionResult
func FindAllAroundWinner ¶
func FormatScore ¶
func FormatTimestamp ¶
FormatTimestamp takes a Time object and returns a datetime string formatted for PostgreSQL
func GetAllRankings ¶
func GetEventRanks ¶
GetEventRanks returns rows of distinct final_score, total_score combinations and the placement (rank) for those scores
func GetFinalScore ¶
func GetRulesets ¶
func GetSimpleRanks ¶
GetSimpleRanks gets the final score and placement without the total score as a tiebreaker
func GetTopScores ¶
func IsConnection ¶
func NanduMarksToSlice ¶
func Query ¶
Query executes the given statement with the values and returns a slice of values per row
func QueryWithRowScan ¶
QueryWithRowScan executes the given statement with the values and calls the provided rowScanner to process the results
func RemoveDeductionMark ¶
func SaveAdjustment ¶
func SaveDeductionMark ¶
func SaveDeductionMark(dm *DeductionMark) (err error)
func SaveFinalScore ¶
func SliceToNanduMarks ¶
func ToTechnicalScore ¶
func ToTechnicalScore(deductions []DeductionResult, style Style) float64
func UpdateDeductionMark ¶
Types ¶
type Adjustment ¶
type Adjustment struct { ID int `json:"id"` Routine int `json:"routine_id"` Judge string `json:"judge_tag"` Amount float64 `json:"amount"` Reason string `json:"reason"` }
Adjustment is a score change (typically a deduction) at the direction of the head judge
func GetAdjustments ¶
func GetAdjustments(routineID int) ([]*Adjustment, error)
type Competitor ¶
type Competitor struct { ID int `json:"id"` Bib string `json:"bib"` FirstName string `json:"first_name"` LastName string `json:"last_name"` Gender Gender `json:"gender_id"` Experience Experience `json:"experience_id"` AgeGroup AgeGroup `json:"age_group_id"` Team string `json:"team"` Email string `json:"email"` }
func GetCompetitorByID ¶
func GetCompetitorByID(id int) (*Competitor, error)
func GetCompetitors ¶
func GetCompetitors() ([]*Competitor, error)
func GetCompetitorsInEvent ¶
func GetCompetitorsInEvent(eventID int) ([]*Competitor, error)
GetCompetitorsInEvent returns the athletes competing in this event *sorted by turn order*
func GetNthCompetitorInEvent ¶
func GetNthCompetitorInEvent(n, eventID int) (*Competitor, error)
type Config ¶
type Config struct { Enabled bool `yaml:"enabled"` Host string `yaml:"host"` Database string `yaml:"dbname"` Username string `yaml:"user"` Password string `yaml:"password"` }
Config holds the database's connection parameters
func MustGetConfigFromMap ¶
MustGetConfigFromMap attempts to read yaml values into the Config. Errors parsing the configuration will result in a panic.
type DeductionCode ¶
type DeductionCode struct { Code string `json:"code"` Value float64 `json:"value"` Name string `json:"name"` }
func ToDeduction ¶
func ToDeduction(code string, style Style) DeductionCode
type DeductionMark ¶
type DeductionMark struct { ID int `json:"id"` Routine int `json:"routine_id"` Judge string `json:"judge_tag"` Code string `json:"code"` Timestamp int64 `json:"timestamp"` }
DeductionMark is a single deduction given by a judge for an event
func GetDeductions ¶
func GetDeductions(routineID int) ([]*DeductionMark, error)
func NewDeductionMark ¶
func NewDeductionMark(routineID int, judgeID, code string, timestamp int64) *DeductionMark
type DeductionResult ¶
type DeductionResult struct { *DeductionMark Applied bool `json:"applied"` }
type DeductionSheet ¶
type DeductionSheet []*DeductionMark
DeductionSheet implements the Sort interface
func (DeductionSheet) Len ¶
func (t DeductionSheet) Len() int
func (DeductionSheet) Less ¶
func (t DeductionSheet) Less(i, j int) bool
func (DeductionSheet) Swap ¶
func (t DeductionSheet) Swap(i, j int)
type Event ¶
type Event struct { ID int `json:"id"` Ring int `json:"ring_id"` Name string `json:"name"` Order int `json:"event_order"` Gender Gender `json:"gender_id"` Experience Experience `json:"experience_id"` AgeGroup AgeGroup `json:"age_group_id"` Ruleset Ruleset `json:"ruleset_id"` Style Style `json:"style"` // TODO: Consider enumerating all event types }
func GetEventByID ¶
func GetEventsByCompetitor ¶
func GetEventsInRing ¶
func GetNthEventInRing ¶
type Experience ¶
type Experience int
const ( InvalidExperience Experience = iota Beginner Intermediate Advanced FirstTimer )
func MapToExperience ¶
func MapToExperience(dbID int) Experience
func ToExperience ¶
func ToExperience(s string) Experience
func (Experience) String ¶
func (t Experience) String() string
func (Experience) StringShort ¶
func (t Experience) StringShort() string
type Nandu ¶
type Nandu struct { ID int `json:"id"` Judge string `json:"judge_tag"` Code NanduCode `json:"code"` Index int `json:"index"` Success bool `json:"success"` }
Nandu is a single mark given by a judge for an event
func DetermineNandu ¶
type NanduCode ¶
type NanduCode struct { Code string `json:"code"` Value float64 `json:"value"` Name string `json:"name"` }
func GetNanduSequence ¶
func GetNanduSequence(sheet *Nandusheet, style Style) []NanduCode
func ToNanduCode ¶
type Nandusheet ¶
type Nandusheet struct { ID int `json:"id"` Routine int `json:"routine_id"` Segment1 string `json:"segment1"` Segment2 string `json:"segment2"` Segment3 string `json:"segment3"` Segment4 string `json:"segment4"` }
func GetNandusheet ¶
func GetNandusheet(routineID int) (*Nandusheet, error)
type RingState ¶
type RingState struct { *Ring Event *Event Competitor *Competitor Routine *Routine StartTime time.Time StopTime time.Time Scores map[string]*Score Adjustments []*Adjustment Deductions map[string][]*DeductionMark Nandusheet *Nandusheet NanduScores map[string][]Nandu NanduResult []Nandu RuleName string // contains filtered or unexported fields }
func (*RingState) AddListener ¶
func (*RingState) CalculateScore ¶
CalculateScore returns the final score and the score components as a map[string]float64
func (*RingState) ClearScores ¶
func (r *RingState) ClearScores()
func (*RingState) DeleteDeduction ¶
func (*RingState) FinalizeScore ¶
func (*RingState) Judges ¶
Judges returns a list of connected judges. NOTE: CALLER MUST CALL ring.ReadDone() WHEN FINISHED!
func (*RingState) Listeners ¶
Listeners returns a list of connected listeners. NOTE: CALLER MUST CALL ring.ReadDone() WHEN FINISHED!
func (*RingState) ParseNanduScores ¶
func (*RingState) PerformanceScores ¶
func (*RingState) ReadDone ¶
func (r *RingState) ReadDone()
ReadDone signifies that the caller has finished reading the connections. Must be called after EACH call of ring.Judges(), ring.Listeners()
func (*RingState) RemoveJudge ¶
func (*RingState) RemoveListener ¶
func (*RingState) SetAdjustment ¶
func (*RingState) SetCompetitor ¶
func (r *RingState) SetCompetitor(newComp *Competitor, event *Event)
func (*RingState) SetDeduction ¶
func (r *RingState) SetDeduction(dm *DeductionMark)
func (*RingState) SetEventStart ¶
func (*RingState) SetEventStop ¶
func (*RingState) SetHeadJudge ¶
func (*RingState) SetPerformanceScore ¶
type Routine ¶
type Routine struct { ID int `json:"id"` Event int `json:"event_id"` Competitor int `json:"competitor_id"` Order int `json:"event_order"` StartTime time.Time `json:"start_time"` Duration string `json:"duration"` FinalScore string `json:"final_score"` TotalScore string `json:"total_score"` Scores []*Score `json:"scores"` Adjustments []*Adjustment `json:"adjustments"` }
Routine describes the performance of a competitor in a event
func GetRoutine ¶
func GetRoutineByID ¶
type Score ¶
type Score struct { ID int `json:"id"` Routine int `json:"routine_id"` Judge string `json:"judge_tag"` Score float64 `json:"score"` }
Score is a single score given by a judge for an event
type Session ¶
type Session struct { Key string //username+sessionID Username string SessionID string CSRFToken string Valid bool Expires time.Time When time.Time IPAddress string UserAgent string User *User // cached user struct, to prevent repeated DB lookups }
Session is an authenticated web session