Skip to content

Commit

Permalink
adding some validation stuff to scoreboards
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevinTeacutter committed Feb 14, 2024
1 parent 20f6fa8 commit 93e5081
Show file tree
Hide file tree
Showing 7 changed files with 3,540 additions and 3,368 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build:
go build -ldflags "\
-H windowsgui \
-s -w \
-X github.com/trevinteacutter/mwo-helper/pkg/build.Build=v0.1.1 \
-X github.com/trevinteacutter/mwo-helper/pkg/build.Build=v0.2.2 \
-X github.com/trevinteacutter/mwo-helper/pkg/build.Commit=$(git rev-parse HEAD) \
-X github.com/trevinteacutter/mwo-helper/pkg/build.Date=Never \
-X github.com/trevinteacutter/mwo-helper/pkg/build.Runtime=$(go version | awk '{print $3;}') \
Expand Down
26 changes: 26 additions & 0 deletions pkg/helper/pages/isc/validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package isc

import (
"github.com/trevinteacutter/mwo-helper/pkg/helper/pages/series"
)

var _ series.Validator = (*Validator)(nil)

type Validator struct{}

func (v *Validator) Name() string {
return "ISC"
}

func (v *Validator) Validate(_ series.MatchDetails, _ ...series.MatchDetails) map[string]error {
validations := make(map[string]error)

validations["Tonnage Limit"] = nil
validations["Chassis Limit"] = nil
validations["Hero Limit"] = nil
validations["Legend Limit"] = nil
validations["Tech Base Limit"] = nil
validations["Player Limit"] = nil

return validations
}
4 changes: 2 additions & 2 deletions pkg/helper/pages/matches/scoreboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func (s *Scoreboard) Layout(gtx layout.Context, theme *material.Theme) layout.Di
return s.overview.Layout(gtx, theme, s.results.MatchDetails)
}),
layout.Flexed(2, func(gtx layout.Context) layout.Dimensions {
return s.team1.Layout(gtx, theme, s.results.MatchDetails.Team1Score, s.results.MatchDetails.WinningTeam == "1", team1)
return s.team1.Layout(gtx, theme, s.results.MatchDetails.Team1Score, s.results.MatchDetails.WinningTeam == "1", true, team1)
}),
layout.Flexed(2, func(gtx layout.Context) layout.Dimensions {
return s.team2.Layout(gtx, theme, s.results.MatchDetails.Team2Score, s.results.MatchDetails.WinningTeam == "2", team2)
return s.team2.Layout(gtx, theme, s.results.MatchDetails.Team2Score, s.results.MatchDetails.WinningTeam == "2", true, team2)
}),
)
}
Expand Down
147 changes: 140 additions & 7 deletions pkg/helper/pages/matches/teamscoreboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
"github.com/trevinteacutter/mwo-helper/pkg/mwo/api"
)

var headingText = []string{"Lance", "Player", "Mech", "Health", "Match Score", "Damage", "Kills", "Assists", "KMDD", "Components", "Team Damage"}
var scoreboardHeaders = []string{"Lance", "Player", "Mech", "Health", "Match Score", "Damage", "Kills", "Assists", "KMDD", "Components", "Team Damage"}
var overviewHeaders = []string{"Tonnage", "Lights", "Mediums", "Heavies", "Assaults", "Heroes", "Legends", "Clan", "IS", "Dupes", "Validity"}

type TeamScoreboard struct {
cellBorder widget.Border
Expand All @@ -34,14 +35,23 @@ func NewTeamScoreboard() *TeamScoreboard {
}
}

func (s *TeamScoreboard) Layout(gtx layout.Context, theme *material.Theme, score int, winner bool, users []api.UserDetails) layout.Dimensions {
func (s *TeamScoreboard) Layout(gtx layout.Context, theme *material.Theme, score int, winner bool, valid bool, users []api.UserDetails) layout.Dimensions {
return layout.Flex{
Alignment: layout.Middle,
Axis: layout.Horizontal,
}.Layout(
gtx,
s.ScoreColumn(theme, score, len(users), winner),
s.Table(theme, users),
layout.Flexed(float32(len(scoreboardHeaders)), func(gtx layout.Context) layout.Dimensions {
return layout.Flex{
Alignment: layout.Middle,
Axis: layout.Vertical,
}.Layout(
gtx,
s.Table(theme, users),
s.OverviewTable(theme, valid, users),
)
}),
)
}

Expand Down Expand Up @@ -104,20 +114,20 @@ func (s *TeamScoreboard) Table(theme *material.Theme, users []api.UserDetails) l
dataLabel.MaxLines = 1
dataLabel.Alignment = text.Start

return layout.Flexed(float32(1*len(headingText)), func(gtx layout.Context) layout.Dimensions {
return component.Table(theme, &s.grid).Layout(gtx, len(users), len(headingText),
return layout.Flexed(float32(len(users)+1), func(gtx layout.Context) layout.Dimensions {
return component.Table(theme, &s.grid).Layout(gtx, len(users), len(scoreboardHeaders),
func(axis layout.Axis, index, constraint int) int {
switch axis {
case layout.Horizontal:
return constraint / len(headingText)
return constraint / len(scoreboardHeaders)
case layout.Vertical:
return constraint / (len(users) + 1)
default:
return constraint
}
},
func(gtx layout.Context, col int) layout.Dimensions {
headingLabel.Text = headingText[col]
headingLabel.Text = scoreboardHeaders[col]

return s.StyleCell(gtx, headingLabel.Layout)
},
Expand Down Expand Up @@ -154,6 +164,129 @@ func (s *TeamScoreboard) Table(theme *material.Theme, users []api.UserDetails) l
})
}

func (s *TeamScoreboard) OverviewTable(theme *material.Theme, valid bool, users []api.UserDetails) layout.FlexChild {
// Configure a label styled to be a heading.
headingLabel := material.Body2(theme, "")
headingLabel.Font.Weight = font.Bold
headingLabel.Alignment = text.Middle
headingLabel.MaxLines = 1

// Configure a label styled to be a data element.
dataLabel := material.Body2(theme, "")
dataLabel.Font.Typeface = "Go Mono"
dataLabel.MaxLines = 1
dataLabel.Alignment = text.Start

tonnage := 0
lights := 0
mediums := 0
heavies := 0
assaults := 0
heroes := 0
legends := 0
clan := 0
is := 0
dupes := 0
variants := make(map[string]int)

for _, user := range users {
mech := api.VariantFromCode(user.MechItemID)
variant := mech.Name

if mech.Alias != "" {
variant = mech.Alias
}

variants[variant]++
tonnage += mech.Weight

switch strings.ToUpper(mech.WeightClass) {
case "LIGHT":
lights++
case "MEDIUM":
mediums++
case "HEAVY":
heavies++
case "ASSAULT":
assaults++
}

switch strings.ToUpper(mech.TechBase) {
case "CLAN":
clan++
case "INNERSPHERE":
is++
}

for _, tag := range mech.Tags {
switch strings.ToUpper(tag) {
case "HERO":
heroes++
case "LEGEND":
legends++
}
}
}

for _, count := range variants {
if count > 1 {
dupes++
}
}

return layout.Flexed(2.0, func(gtx layout.Context) layout.Dimensions {
return component.Table(theme, &s.grid).Layout(gtx, 1, len(overviewHeaders),
func(axis layout.Axis, index, constraint int) int {
switch axis {
case layout.Horizontal:
return constraint / len(overviewHeaders)
case layout.Vertical:
return constraint / 2
default:
return constraint
}
},
func(gtx layout.Context, col int) layout.Dimensions {
headingLabel.Text = overviewHeaders[col]

return s.StyleCell(gtx, headingLabel.Layout)
},
func(gtx layout.Context, _, col int) layout.Dimensions {
switch col {
case 0:
dataLabel.Text = strconv.Itoa(tonnage)
case 1:
dataLabel.Text = strconv.Itoa(lights)
case 2:
dataLabel.Text = strconv.Itoa(mediums)
case 3:
dataLabel.Text = strconv.Itoa(heavies)
case 4:
dataLabel.Text = strconv.Itoa(assaults)
case 5:
dataLabel.Text = strconv.Itoa(heroes)
case 6:
dataLabel.Text = strconv.Itoa(legends)
case 7:
dataLabel.Text = strconv.Itoa(clan)
case 8:
dataLabel.Text = strconv.Itoa(is)
case 9:
dataLabel.Text = strconv.Itoa(dupes)
case 10:
if valid {
dataLabel.Text = "VALID"
} else {
dataLabel.Text = "INVALID"
}
}

return s.StyleCell(gtx, dataLabel.Layout)
},
)
})
}

func (s *TeamScoreboard) StyleCell(gtx layout.Context, widget layout.Widget) layout.Dimensions {
return s.cellBorder.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return s.cellInset.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
Expand Down
28 changes: 19 additions & 9 deletions pkg/helper/pages/series/pilotsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (p *PilotSummary) Layout(gtx layout.Context, theme *material.Theme) layout.
// }.Layout(gtx, children...)
}

type pilotSorters struct {
Username string
Team string
}

func (p *PilotSummary) Table(theme *material.Theme) layout.FlexChild {
// Configure a label styled to be a heading.
headingLabel := material.Body2(theme, "")
Expand Down Expand Up @@ -173,19 +178,24 @@ func (p *PilotSummary) BuildRow(name string) []string {
}

matches := float64(wins + losses)
wlr := float64(wins) / float64(losses)

if losses <= 0 {
wlr = float64(wins)
}

return []string{
team,
name,
strconv.FormatFloat(float64(wins)/float64(losses), 'G', -1, 64),
strconv.FormatFloat(float64(matchScore)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(damage)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(kills)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(assists)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(deaths)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(kmdds)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(components)/matches, 'G', -1, 64),
strconv.FormatFloat(float64(teamDamage)/matches, 'G', -1, 64),
strconv.FormatFloat(wlr, 'G', 3, 64),
strconv.FormatFloat(float64(matchScore)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(damage)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(kills)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(assists)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(deaths)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(kmdds)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(components)/matches, 'G', 3, 64),
strconv.FormatFloat(float64(teamDamage)/matches, 'G', 3, 64),
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/helper/pages/series/validator.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package series

type Validator func(match MatchDetails, previous ...MatchDetails) map[string]error
type Validator interface {
Name() string
Validate(match MatchDetails, previous ...MatchDetails) map[string]error
}
Loading

0 comments on commit 93e5081

Please sign in to comment.