Skip to content

Commit

Permalink
feat(analyze): support minimum events
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Sep 10, 2024
1 parent e4ea4f4 commit e43441d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
33 changes: 18 additions & 15 deletions cmd/kicker-cli/cmd/event_analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ import (
)

var (
rankGameMode string
rankMinPlayed int
rankHead int
rankTail int
rankShowInactive bool
rankSortBy string
rankPlayerName string
rankOutputFormat string
rankGameMode string
rankMinEventsPlayed int
rankMinGamesPlayed int
rankHead int
rankTail int
rankShowInactive bool
rankSortBy string
rankPlayerName string
rankOutputFormat string
)

func init() {
analyzeCmd.Flags().StringVarP(&rankGameMode, "mode", "m", "", "rank mode")
analyzeCmd.Flags().StringVarP(&rankSortBy, "sort-by", "o", "KRP", "sort by (KRP/ITSF/ATSA/ELO/WR)")
analyzeCmd.Flags().BoolVarP(&rankShowInactive, "show-inactive", "i", false, "show inactive players")
analyzeCmd.Flags().IntVarP(&rankMinPlayed, "minimum-played", "p", 0, "minimum matches played")
analyzeCmd.Flags().IntVarP(&rankMinEventsPlayed, "minimum-events", "e", 0, "minimum tournaments played")
analyzeCmd.Flags().IntVarP(&rankMinGamesPlayed, "minimum-games", "g", 0, "minimum games played")
analyzeCmd.Flags().IntVarP(&rankHead, "head", "", 0, "display the head part of rank")
analyzeCmd.Flags().IntVarP(&rankTail, "tail", "", 0, "display the last part of rank")
analyzeCmd.Flags().StringVarP(&rankPlayerName, "player", "", "", "Player name for detail only modes")
Expand Down Expand Up @@ -129,12 +131,13 @@ var analyzeCmd = &cobra.Command{
})
}
options := operator.Option{
OrderBy: strings.ToUpper(rankSortBy),
MinimumPlayed: rankMinPlayed,
Head: rankHead,
Tail: rankTail,
PlayerName: rankPlayerName,
ShowInactive: rankShowInactive,
OrderBy: strings.ToUpper(rankSortBy),
Head: rankHead,
Tail: rankTail,
PlayerName: rankPlayerName,
ShowInactive: rankShowInactive,
MinimumEventsPlayed: rankMinEventsPlayed,
MinimumGamesPlayed: rankMinGamesPlayed,

OutputFormat: strings.ToLower(rankOutputFormat),
WithHeader: !globalNoHeaders,
Expand Down
13 changes: 7 additions & 6 deletions internal/operator/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ type Operator interface {

// Option .
type Option struct {
OrderBy string
MinimumPlayed int
ShowInactive bool
Head int
Tail int
PlayerName string
OrderBy string
MinimumGamesPlayed int
MinimumEventsPlayed int
ShowInactive bool
Head int
Tail int
PlayerName string

WithHeader bool
WithBoxes bool
Expand Down
7 changes: 5 additions & 2 deletions internal/operator/double_player_rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func (o *DoublePlayerRank) Output() {
// {{{ map to slice
var sliceData []entity.Player
for _, d := range data {
if d.GamesPlayed < o.options.MinimumGamesPlayed || d.EventsPlayed < o.options.MinimumEventsPlayed {
continue
}
if d.GamesPlayed != 0 {
d.WinRate = float64(d.Win) / float64(d.GamesPlayed) * 100.0
d.QualificationWinRate = float64(d.QualificationWin) / float64(d.QualificationWin+d.QualificationDraw+d.QualificationLoss) * 100.0
Expand All @@ -203,10 +206,10 @@ func (o *DoublePlayerRank) Output() {
// {{{ sort
sort.SliceStable(sliceData, func(i, j int) bool {
if o.options.OrderBy == rating.RSysWinRate || o.options.OrderBy == rating.RSysELO {
if sliceData[i].GamesPlayed >= o.options.MinimumPlayed && sliceData[j].GamesPlayed < o.options.MinimumPlayed {
if sliceData[i].GamesPlayed >= o.options.MinimumGamesPlayed && sliceData[j].GamesPlayed < o.options.MinimumGamesPlayed {
return true
}
if sliceData[i].GamesPlayed < o.options.MinimumPlayed && sliceData[j].GamesPlayed >= o.options.MinimumPlayed {
if sliceData[i].GamesPlayed < o.options.MinimumGamesPlayed && sliceData[j].GamesPlayed >= o.options.MinimumGamesPlayed {
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/operator/double_team_rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ func (o *DoubleTeamRank) Output() {
}
}
sort.SliceStable(sliceData, func(i, j int) bool {
if sliceData[i].Played >= o.options.MinimumPlayed && sliceData[j].Played < o.options.MinimumPlayed {
if sliceData[i].Played >= o.options.MinimumGamesPlayed && sliceData[j].Played < o.options.MinimumGamesPlayed {
return true
}
if sliceData[i].Played < o.options.MinimumPlayed && sliceData[j].Played >= o.options.MinimumPlayed {
if sliceData[i].Played < o.options.MinimumGamesPlayed && sliceData[j].Played >= o.options.MinimumGamesPlayed {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions internal/operator/double_team_rival.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func (o *DoubleTeamRival) Output() {
}

sort.SliceStable(sliceData, func(i, j int) bool {
if sliceData[i].Played >= o.options.MinimumPlayed && sliceData[j].Played < o.options.MinimumPlayed {
if sliceData[i].Played >= o.options.MinimumGamesPlayed && sliceData[j].Played < o.options.MinimumGamesPlayed {
return true
}
if sliceData[i].Played < o.options.MinimumPlayed && sliceData[j].Played >= o.options.MinimumPlayed {
if sliceData[i].Played < o.options.MinimumGamesPlayed && sliceData[j].Played >= o.options.MinimumGamesPlayed {
return false
}

Expand Down
7 changes: 5 additions & 2 deletions internal/operator/single_player_rank.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ func (o *SinglePlayerRank) Output() {
// {{{ map to slice
var sliceData []entity.Player
for _, d := range data {
if d.GamesPlayed < o.options.MinimumGamesPlayed || d.EventsPlayed < o.options.MinimumEventsPlayed {
continue
}
if d.GamesPlayed != 0 {
d.WinRate = float64(d.Win) / float64(d.GamesPlayed) * 100.0
d.QualificationWinRate = float64(d.QualificationWin) / float64(d.QualificationWin+d.QualificationDraw+d.QualificationLoss) * 100.0
Expand All @@ -159,10 +162,10 @@ func (o *SinglePlayerRank) Output() {
// {{{ sort
sort.SliceStable(sliceData, func(i, j int) bool {
if o.options.OrderBy == rating.RSysWinRate || o.options.OrderBy == rating.RSysELO {
if sliceData[i].GamesPlayed >= o.options.MinimumPlayed && sliceData[j].GamesPlayed < o.options.MinimumPlayed {
if sliceData[i].GamesPlayed >= o.options.MinimumGamesPlayed && sliceData[j].GamesPlayed < o.options.MinimumGamesPlayed {
return true
}
if sliceData[i].GamesPlayed < o.options.MinimumPlayed && sliceData[j].GamesPlayed >= o.options.MinimumPlayed {
if sliceData[i].GamesPlayed < o.options.MinimumGamesPlayed && sliceData[j].GamesPlayed >= o.options.MinimumGamesPlayed {
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/operator/single_player_rival.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func (o *SinglePlayerRival) Output() {
}

sort.SliceStable(sliceData, func(i, j int) bool {
if sliceData[i].Played >= o.options.MinimumPlayed && sliceData[j].Played < o.options.MinimumPlayed {
if sliceData[i].Played >= o.options.MinimumGamesPlayed && sliceData[j].Played < o.options.MinimumGamesPlayed {
return true
}
if sliceData[i].Played < o.options.MinimumPlayed && sliceData[j].Played >= o.options.MinimumPlayed {
if sliceData[i].Played < o.options.MinimumGamesPlayed && sliceData[j].Played >= o.options.MinimumGamesPlayed {
return false
}

Expand Down

0 comments on commit e43441d

Please sign in to comment.