| Index: pkg/analysis_server/lib/src/utilities/average.dart
|
| diff --git a/pkg/analysis_server/lib/src/utilities/average.dart b/pkg/analysis_server/lib/src/utilities/average.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a738d3976964b71f0f2c775777670074d6ae1a59
|
| --- /dev/null
|
| +++ b/pkg/analysis_server/lib/src/utilities/average.dart
|
| @@ -0,0 +1,30 @@
|
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library analysis_server.src.utilities.average;
|
| +
|
| +/// Simple rolling average sample counter.
|
| +class Average {
|
| + num _val;
|
| + final int _sampleCount;
|
| +
|
| + /// Create an average with the given (optional) sample count size.
|
| + Average([this._sampleCount = 20]);
|
| +
|
| + /// The current average.
|
| + num get value => _val ?? 0;
|
| +
|
| + /// Add the given [sample].
|
| + void addSample(num sample) {
|
| + if (_val == null) {
|
| + _val = sample;
|
| + } else {
|
| + _val = _val * ((_sampleCount - 1) / _sampleCount) +
|
| + sample * (1 / _sampleCount);
|
| + }
|
| + }
|
| +
|
| + @override
|
| + String toString() => 'average: ${value}';
|
| +}
|
|
|