Codebase list golang-github-vbauerster-mpb / 7b9c53c
correct Decor methods need to comply with Decorator interface Vladimir Bauer 2 years ago
4 changed file(s) with 13 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
6767 producer func(time.Duration) string
6868 }
6969
70 func (d *movingAverageETA) Decor(s Statistics) string {
70 func (d *movingAverageETA) Decor(s Statistics) (string, int) {
7171 v := math.Round(d.average.Value())
7272 remaining := time.Duration((s.Total - s.Current) * int64(v))
7373 if d.normalizer != nil {
7474 remaining = d.normalizer.Normalize(remaining)
7575 }
76 return d.FormatMsg(d.producer(remaining))
76 return d.Format(d.producer(remaining))
7777 }
7878
7979 func (d *movingAverageETA) EwmaUpdate(n int64, dur time.Duration) {
119119 producer func(time.Duration) string
120120 }
121121
122 func (d *averageETA) Decor(s Statistics) string {
122 func (d *averageETA) Decor(s Statistics) (string, int) {
123123 var remaining time.Duration
124124 if s.Current != 0 {
125125 durPerItem := float64(time.Since(d.startTime)) / float64(s.Current)
129129 remaining = d.normalizer.Normalize(remaining)
130130 }
131131 }
132 return d.FormatMsg(d.producer(remaining))
132 return d.Format(d.producer(remaining))
133133 }
134134
135135 func (d *averageETA) AverageAdjust(startTime time.Time) {
8181 msg string
8282 }
8383
84 func (d *movingAverageSpeed) Decor(s Statistics) string {
84 func (d *movingAverageSpeed) Decor(s Statistics) (string, int) {
8585 if !s.Completed {
8686 var speed float64
8787 if v := d.average.Value(); v > 0 {
8989 }
9090 d.msg = d.producer(speed * 1e9)
9191 }
92 return d.FormatMsg(d.msg)
92 return d.Format(d.msg)
9393 }
9494
9595 func (d *movingAverageSpeed) EwmaUpdate(n int64, dur time.Duration) {
139139 msg string
140140 }
141141
142 func (d *averageSpeed) Decor(s Statistics) string {
142 func (d *averageSpeed) Decor(s Statistics) (string, int) {
143143 if !s.Completed {
144144 speed := float64(s.Current) / float64(time.Since(d.startTime))
145145 d.msg = d.producer(speed * 1e9)
146146 }
147 return d.FormatMsg(d.msg)
147 return d.Format(d.msg)
148148 }
149149
150150 func (d *averageSpeed) AverageAdjust(startTime time.Time) {
132132 stat := Statistics{
133133 Current: tc.current,
134134 }
135 res := decor.Decor(stat)
135 res, _ := decor.Decor(stat)
136136 if res != tc.expected {
137137 t.Fatalf("expected: %q, got: %q\n", tc.expected, res)
138138 }
268268 stat := Statistics{
269269 Current: tc.current,
270270 }
271 res := decor.Decor(stat)
271 res, _ := decor.Decor(stat)
272272 if res != tc.expected {
273273 t.Fatalf("expected: %q, got: %q\n", tc.expected, res)
274274 }
3030 }
3131
3232 for _, test := range tests {
33 got := test.decorator.Decor(decor.Statistics{})
33 got, _ := test.decorator.Decor(decor.Statistics{})
3434 if got != test.want {
3535 t.Errorf("Want: %q, Got: %q\n", test.want, got)
3636 }
187187 step := step
188188 ch := make(chan string)
189189 go func() {
190 ch <- step.decorator.Decor(step.stat)
190 str, _ := step.decorator.Decor(step.stat)
191 ch <- str
191192 }()
192193 results = append(results, ch)
193194 }