GetTopCommands returns the N most used commands.
(n int)
| 131 | |
| 132 | // GetTopCommands returns the N most used commands. |
| 133 | func (pd *PatternDetector) GetTopCommands(n int) []string { |
| 134 | pd.mu.RLock() |
| 135 | defer pd.mu.RUnlock() |
| 136 | |
| 137 | type cmdCount struct { |
| 138 | cmd string |
| 139 | count int |
| 140 | } |
| 141 | cmds := make([]cmdCount, 0, len(pd.stats.CommandFrequency)) |
| 142 | for c, count := range pd.stats.CommandFrequency { |
| 143 | cmds = append(cmds, cmdCount{c, count}) |
| 144 | } |
| 145 | sort.Slice(cmds, func(i, j int) bool { |
| 146 | return cmds[i].count > cmds[j].count |
| 147 | }) |
| 148 | if n > len(cmds) { |
| 149 | n = len(cmds) |
| 150 | } |
| 151 | result := make([]string, n) |
| 152 | for i := 0; i < n; i++ { |
| 153 | result[i] = cmds[i].cmd |
| 154 | } |
| 155 | return result |
| 156 | } |
| 157 | |
| 158 | // FormatForPrompt returns a concise usage summary. |
| 159 | func (pd *PatternDetector) FormatForPrompt() string { |