GetPeakHours returns the top N hours of activity.
(n int)
| 103 | |
| 104 | // GetPeakHours returns the top N hours of activity. |
| 105 | func (pd *PatternDetector) GetPeakHours(n int) []int { |
| 106 | pd.mu.RLock() |
| 107 | defer pd.mu.RUnlock() |
| 108 | |
| 109 | type hourCount struct { |
| 110 | hour int |
| 111 | count int |
| 112 | } |
| 113 | var hours []hourCount |
| 114 | for h, c := range pd.stats.HourDistribution { |
| 115 | if c > 0 { |
| 116 | hours = append(hours, hourCount{h, c}) |
| 117 | } |
| 118 | } |
| 119 | sort.Slice(hours, func(i, j int) bool { |
| 120 | return hours[i].count > hours[j].count |
| 121 | }) |
| 122 | if n > len(hours) { |
| 123 | n = len(hours) |
| 124 | } |
| 125 | result := make([]int, n) |
| 126 | for i := 0; i < n; i++ { |
| 127 | result[i] = hours[i].hour |
| 128 | } |
| 129 | return result |
| 130 | } |
| 131 | |
| 132 | // GetTopCommands returns the N most used commands. |
| 133 | func (pd *PatternDetector) GetTopCommands(n int) []string { |