don't check verb count
user may want to add '%%' in format string
Vladimir Bauer
3 years ago
| 1 | 1 |
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | |
"strings"
|
| 5 | 4 |
)
|
| 6 | 5 |
|
| 7 | 6 |
// CountersNoUnit is a wrapper around Counters with no unit param.
|
|
| 40 | 39 |
func Counters(unit interface{}, pairFmt string, wcc ...WC) Decorator {
|
| 41 | 40 |
if pairFmt == "" {
|
| 42 | 41 |
pairFmt = "%d / %d"
|
| 43 | |
} else if strings.Count(pairFmt, "%") != 2 {
|
| 44 | |
panic("expected pairFmt with exactly 2 verbs")
|
| 45 | 42 |
}
|
| 46 | 43 |
producer := func() DecorFunc {
|
| 47 | 44 |
switch unit.(type) {
|
|
| 98 | 95 |
func Total(unit interface{}, format string, wcc ...WC) Decorator {
|
| 99 | 96 |
if format == "" {
|
| 100 | 97 |
format = "%d"
|
| 101 | |
} else if strings.Count(format, "%") != 1 {
|
| 102 | |
panic("expected format with exactly 1 verb")
|
| 103 | 98 |
}
|
| 104 | 99 |
producer := func() DecorFunc {
|
| 105 | 100 |
switch unit.(type) {
|
|
| 156 | 151 |
func Current(unit interface{}, format string, wcc ...WC) Decorator {
|
| 157 | 152 |
if format == "" {
|
| 158 | 153 |
format = "%d"
|
| 159 | |
} else if strings.Count(format, "%") != 1 {
|
| 160 | |
panic("expected format with exactly 1 verb")
|
| 161 | 154 |
}
|
| 162 | 155 |
producer := func() DecorFunc {
|
| 163 | 156 |
switch unit.(type) {
|
|
| 214 | 207 |
func InvertedCurrent(unit interface{}, format string, wcc ...WC) Decorator {
|
| 215 | 208 |
if format == "" {
|
| 216 | 209 |
format = "%d"
|
| 217 | |
} else if strings.Count(format, "%") != 1 {
|
| 218 | |
panic("expected format with exactly 1 verb")
|
| 219 | 210 |
}
|
| 220 | 211 |
producer := func() DecorFunc {
|
| 221 | 212 |
switch unit.(type) {
|
| 3 | 3 |
"fmt"
|
| 4 | 4 |
"io"
|
| 5 | 5 |
"math"
|
| 6 | |
"strings"
|
| 7 | 6 |
"time"
|
| 8 | 7 |
|
| 9 | 8 |
"github.com/VividCortex/ewma"
|
|
| 69 | 68 |
func MovingAverageSpeed(unit interface{}, format string, average ewma.MovingAverage, wcc ...WC) Decorator {
|
| 70 | 69 |
if format == "" {
|
| 71 | 70 |
format = "%.0f"
|
| 72 | |
} else if strings.Count(format, "%") != 1 {
|
| 73 | |
panic("expected format with exactly 1 verb")
|
| 74 | 71 |
}
|
| 75 | 72 |
d := &movingAverageSpeed{
|
| 76 | 73 |
WC: initWC(wcc...),
|
|
| 132 | 129 |
func NewAverageSpeed(unit interface{}, format string, startTime time.Time, wcc ...WC) Decorator {
|
| 133 | 130 |
if format == "" {
|
| 134 | 131 |
format = "%.0f"
|
| 135 | |
} else if strings.Count(format, "%") != 1 {
|
| 136 | |
panic("expected format with exactly 1 verb")
|
| 137 | 132 |
}
|
| 138 | 133 |
d := &averageSpeed{
|
| 139 | 134 |
WC: initWC(wcc...),
|