87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
package seasonsview
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.haelnorr.com/h/oslstats/internal/db"
|
|
)
|
|
|
|
// seriesByNumber returns a map of series_number -> *PlayoffSeries for quick lookup
|
|
func seriesByNumber(series []*db.PlayoffSeries) map[int]*db.PlayoffSeries {
|
|
m := make(map[int]*db.PlayoffSeries, len(series))
|
|
for _, s := range series {
|
|
m[s.SeriesNumber] = s
|
|
}
|
|
return m
|
|
}
|
|
|
|
// formatLabel returns a human-readable format description
|
|
func formatLabel(format db.PlayoffFormat) string {
|
|
switch format {
|
|
case db.PlayoffFormat5to6:
|
|
return "Top 5 qualify"
|
|
case db.PlayoffFormat7to9:
|
|
return "Top 6 qualify"
|
|
case db.PlayoffFormat10to15:
|
|
return "Top 8 qualify"
|
|
default:
|
|
return string(format)
|
|
}
|
|
}
|
|
|
|
// bracketConnection represents a line to draw between two series cards
|
|
type bracketConnection struct {
|
|
From int `json:"from"`
|
|
To int `json:"to"`
|
|
Type string `json:"type"` // "winner" or "loser"
|
|
ToSide string `json:"toSide,omitempty"` // "left" or "right" — enters side of dest card
|
|
}
|
|
|
|
// connectionsJSON returns a JSON string of connections for the bracket overlay JS.
|
|
// Connections are derived from the series advancement links stored in the DB.
|
|
// For the 10-15 format, QF winner lines enter PF cards from the side.
|
|
func connectionsJSON(series []*db.PlayoffSeries) string {
|
|
// Build a lookup of series ID → series for resolving advancement targets
|
|
byID := make(map[int]*db.PlayoffSeries, len(series))
|
|
for _, s := range series {
|
|
byID[s.ID] = s
|
|
}
|
|
|
|
var conns []bracketConnection
|
|
for _, s := range series {
|
|
if s.WinnerNextID != nil {
|
|
if target, ok := byID[*s.WinnerNextID]; ok {
|
|
conn := bracketConnection{
|
|
From: s.SeriesNumber,
|
|
To: target.SeriesNumber,
|
|
Type: "winner",
|
|
}
|
|
// QF winners enter PF cards from the side in the 10-15 format
|
|
if s.Round == "qualifying_final" && target.Round == "preliminary_final" {
|
|
if s.SeriesNumber == 1 {
|
|
conn.ToSide = "left"
|
|
} else if s.SeriesNumber == 2 {
|
|
conn.ToSide = "right"
|
|
}
|
|
}
|
|
conns = append(conns, conn)
|
|
}
|
|
}
|
|
if s.LoserNextID != nil {
|
|
if target, ok := byID[*s.LoserNextID]; ok {
|
|
conns = append(conns, bracketConnection{
|
|
From: s.SeriesNumber,
|
|
To: target.SeriesNumber,
|
|
Type: "loser",
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
b, err := json.Marshal(conns)
|
|
if err != nil {
|
|
return "[]"
|
|
}
|
|
return string(b)
|
|
}
|