data

package
v0.0.0-...-8aa12d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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"},
	}
)
View Source
var AllGenders = []Gender{Female, Male}
View Source
var AllRulesets = []Ruleset{USWU, IWUF, IWUFAB}
View Source
var (
	ClientSettings = make(map[string]string)
)

Functions

func AddCompetitorToEvent

func AddCompetitorToEvent(competitorID, eventID int) (err error)

func AddRing

func AddRing(ring *Ring)

func AdjustedAverage

func AdjustedAverage(scores []*Score) float64

func CalculateDifficulty

func CalculateDifficulty(nandu []Nandu) float64

func ChangeEventRing

func ChangeEventRing(ringID, eventID int) (err error)

func ChangeEventRules

func ChangeEventRules(eventID, rulesetID int) (err error)

func ClearScores

func ClearScores(routineID, ringID int) error

func ClearState

func ClearState()

func Connect

func Connect(cfg *Config) error

Connect establishes a new PostgreSQL connection

func CreateUser

func CreateUser(username string, password []byte) error

CreateUser saves the given credentials in the database

func CreateWebSession

func CreateWebSession(key string, username string, created, expires time.Time) error

func Delete

func Delete(query string, values []interface{}) error

Delete executes a delete statement

func DeleteScore

func DeleteScore(scoreID int) error

func DetermineDeductions

func DetermineDeductions(deductions map[string][]*DeductionMark) map[string][]DeductionResult

func FindAllAroundWinner

func FindAllAroundWinner() ([]string, error)

func FormatScore

func FormatScore(score float64) string

func FormatTimestamp

func FormatTimestamp(timestamp time.Time) string

FormatTimestamp takes a Time object and returns a datetime string formatted for PostgreSQL

func GetAllRankings

func GetAllRankings() ([]map[string]interface{}, error)

func GetEventRanks

func GetEventRanks(eventID int) ([]map[string]interface{}, error)

GetEventRanks returns rows of distinct final_score, total_score combinations and the placement (rank) for those scores

func GetFinalScore

func GetFinalScore(routineID int) (string, error)

func GetNanduResults

func GetNanduResults(routineID int) (map[string]string, error)

func GetRulesets

func GetRulesets() ([]map[string]interface{}, error)

func GetScores

func GetScores(routineID int) (map[string]*Score, error)

func GetSimpleRanks

func GetSimpleRanks(eventID int) ([]map[string]interface{}, error)

GetSimpleRanks gets the final score and placement without the total score as a tiebreaker

func GetTopScores

func GetTopScores(competitorID int) (float64, error)

func IsConnection

func IsConnection(code string) bool

func NanduMarksToSlice

func NanduMarksToSlice(marks string) []bool

func Query

func Query(query string, values []interface{}) ([]map[string]interface{}, error)

Query executes the given statement with the values and returns a slice of values per row

func QueryWithRowScan

func QueryWithRowScan(query string, values []interface{}, rowScanner func(*sql.Rows) error) error

QueryWithRowScan executes the given statement with the values and calls the provided rowScanner to process the results

func RemoveCompetitorFromEvent

func RemoveCompetitorFromEvent(competitorID, eventID int) (err error)

func RemoveDeductionMark

func RemoveDeductionMark(id int) (err error)

func SaveAdjustment

func SaveAdjustment(amount float64, reason string, routineID int, judgeTag string) (err error)

func SaveDeductionMark

func SaveDeductionMark(dm *DeductionMark) (err error)

func SaveFinalScore

func SaveFinalScore(score, total string, elapsed string, eventID, competitorID int) (err error)

func SaveNanduScore

func SaveNanduScore(routineID int, judgeID string, result string) (err error)

func SaveScore

func SaveScore(score float64, ringID int, judgeID string) error

func SliceToNanduMarks

func SliceToNanduMarks(s []bool) string

func ToTechnicalScore

func ToTechnicalScore(deductions []DeductionResult, style Style) float64

func UpdateDeductionMark

func UpdateDeductionMark(id int, code string) (err error)

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 AgeGroup

type AgeGroup int
const (
	InvalidAge AgeGroup = iota
	Child
	Youth
	GroupC
	GroupB
	GroupA
	Adult
	AdultII
)

func MapToAgeGroup

func MapToAgeGroup(dbID int) AgeGroup

func ToAgeGroup

func ToAgeGroup(s string) AgeGroup

func (AgeGroup) String

func (t AgeGroup) String() string

type Category

type Category int
const (
	Northern Category = iota
	Southern
	Taiji
)

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

func MustGetConfigFromMap(v map[string]interface{}) *Config

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 GetEventByID(id int) (*Event, error)

func GetEvents

func GetEvents() ([]*Event, error)

func GetEventsByCompetitor

func GetEventsByCompetitor(competitorID int) ([]*Event, error)

func GetEventsInRing

func GetEventsInRing(ringID int) ([]*Event, error)

func GetNthEventInRing

func GetNthEventInRing(n, ringID int) (*Event, error)

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 Gender

type Gender int
const (
	OtherGender Gender = iota
	Female
	Male
)

func MapToGender

func MapToGender(dbID int) Gender

func ToGender

func ToGender(s string) Gender

func (Gender) String

func (t Gender) String() string

func (Gender) StringShort

func (t Gender) StringShort() string

type Judge

type Judge struct {
	UserID int
	ConnID string
	Tag    string
}

type Listener

type Listener struct {
	ID     int
	ConnID string
	Tag    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

func DetermineNandu(judgeScores map[string][]Nandu) []Nandu

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

func ToNanduCode(code string, style Style) NanduCode

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 Ring

type Ring struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Ring represents a competition field of play

func GetRings

func GetRings() ([]*Ring, error)

GetRings returns a list of all the available rings

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 GetRing

func GetRing(ringID int) *RingState

func (*RingState) AddJudge

func (r *RingState) AddJudge(connID, tag string) bool

func (*RingState) AddListener

func (r *RingState) AddListener(connID, tag string) bool

func (*RingState) CalculateScore

func (r *RingState) CalculateScore() (result float64, components map[string]float64)

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 (r *RingState) DeleteDeduction(judgeTag string, id int)

func (*RingState) Duration

func (r *RingState) Duration() time.Duration

func (*RingState) FinalizeScore

func (r *RingState) FinalizeScore() error

func (*RingState) HeadJudge

func (r *RingState) HeadJudge() *Judge

func (*RingState) Judges

func (r *RingState) Judges() []*Judge

Judges returns a list of connected judges. NOTE: CALLER MUST CALL ring.ReadDone() WHEN FINISHED!

func (*RingState) Listeners

func (r *RingState) Listeners() []*Listener

Listeners returns a list of connected listeners. NOTE: CALLER MUST CALL ring.ReadDone() WHEN FINISHED!

func (*RingState) ParseNanduScores

func (r *RingState) ParseNanduScores(judgeTag string, results []bool)

func (*RingState) PerformanceScores

func (r *RingState) PerformanceScores() []*Score

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 (r *RingState) RemoveJudge(connID string) bool

func (*RingState) RemoveListener

func (r *RingState) RemoveListener(connID string) bool

func (*RingState) SetAdjustment

func (r *RingState) SetAdjustment(judgeTag string, amount float64, reason string)

func (*RingState) SetCompetitor

func (r *RingState) SetCompetitor(newComp *Competitor, event *Event)

func (*RingState) SetDeduction

func (r *RingState) SetDeduction(dm *DeductionMark)

func (*RingState) SetEvent

func (r *RingState) SetEvent(newEvent *Event)

func (*RingState) SetEventStart

func (r *RingState) SetEventStart(startTime time.Time)

func (*RingState) SetEventStop

func (r *RingState) SetEventStop(stopTime time.Time)

func (*RingState) SetHeadJudge

func (r *RingState) SetHeadJudge(connID, tag string) bool

func (*RingState) SetPerformanceScore

func (r *RingState) SetPerformanceScore(judgeTag string, score float64)

func (*RingState) UpdateDeduction

func (r *RingState) UpdateDeduction(judgeTag string, id int, code string)

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 GetRoutine(eventID, competitorID int) (*Routine, error)

func GetRoutineByID

func GetRoutineByID(id int) (*Routine, error)

type Ruleset

type Ruleset int
const (
	InvalidRuleset Ruleset = iota
	USWU
	IWUF
	IWUFAB
)

func MapToRuleset

func MapToRuleset(dbID int) Ruleset

func (Ruleset) String

func (t Ruleset) String() string

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

func GetWebSession

func GetWebSession(key string) (*Session, error)

type State

type State struct {
	Rings []*RingState
}

Competition state

func NewState

func NewState() State

type Style

type Style int
const (
	Changquan Style = iota
	Daoshu
	Jianshu
	Gunshu
	Qiangshu
	Nanquan
	Nandao
	Nangun
	Taijiquan
	Taijijian
)

func (Style) Category

func (t Style) Category() Category

func (Style) MarshalJSON

func (t Style) MarshalJSON() ([]byte, error)

func (Style) String

func (t Style) String() string

func (Style) StringShort

func (t Style) StringShort() string

type User

type User struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	Password []byte `json:"password"`
}

* DATABASE MODELS

func GetUser

func GetUser(username string) (*User, error)

GetUser queries the database for the user with the given username

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL