From e43441db2f38c04effce381c0bc214efdeeb4c4c Mon Sep 17 00:00:00 2001 From: David Zhang Date: Tue, 10 Sep 2024 14:37:32 +0800 Subject: [PATCH] feat(analyze): support minimum events --- cmd/kicker-cli/cmd/event_analyze.go | 33 +++++++++++++----------- internal/operator/base.go | 13 +++++----- internal/operator/double_player_rank.go | 7 +++-- internal/operator/double_team_rank.go | 4 +-- internal/operator/double_team_rival.go | 4 +-- internal/operator/single_player_rank.go | 7 +++-- internal/operator/single_player_rival.go | 4 +-- 7 files changed, 41 insertions(+), 31 deletions(-) diff --git a/cmd/kicker-cli/cmd/event_analyze.go b/cmd/kicker-cli/cmd/event_analyze.go index 564117f..2c1c2b8 100644 --- a/cmd/kicker-cli/cmd/event_analyze.go +++ b/cmd/kicker-cli/cmd/event_analyze.go @@ -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") @@ -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, diff --git a/internal/operator/base.go b/internal/operator/base.go index 6debf16..bd9d667 100644 --- a/internal/operator/base.go +++ b/internal/operator/base.go @@ -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 diff --git a/internal/operator/double_player_rank.go b/internal/operator/double_player_rank.go index 525da78..cecd28d 100644 --- a/internal/operator/double_player_rank.go +++ b/internal/operator/double_player_rank.go @@ -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 @@ -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 } } diff --git a/internal/operator/double_team_rank.go b/internal/operator/double_team_rank.go index 9820211..43618cc 100644 --- a/internal/operator/double_team_rank.go +++ b/internal/operator/double_team_rank.go @@ -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 } diff --git a/internal/operator/double_team_rival.go b/internal/operator/double_team_rival.go index 99851d0..e2efd45 100644 --- a/internal/operator/double_team_rival.go +++ b/internal/operator/double_team_rival.go @@ -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 } diff --git a/internal/operator/single_player_rank.go b/internal/operator/single_player_rank.go index ae4e8e7..6dc40db 100644 --- a/internal/operator/single_player_rank.go +++ b/internal/operator/single_player_rank.go @@ -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 @@ -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 } } diff --git a/internal/operator/single_player_rival.go b/internal/operator/single_player_rival.go index a2b0db4..acaef3a 100644 --- a/internal/operator/single_player_rival.go +++ b/internal/operator/single_player_rival.go @@ -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 }