Source release v3.5.0
This commit is contained in:
53
metrics/include/distribution.h
Normal file
53
metrics/include/distribution.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2017 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// This file contains the definition of a Distribution class which computes
|
||||
// the distribution values of a series of samples.
|
||||
|
||||
#ifndef WVCDM_METRICS_DISTRIBUTION_H_
|
||||
#define WVCDM_METRICS_DISTRIBUTION_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace wvcdm {
|
||||
namespace metrics {
|
||||
|
||||
// The Distribution class holds statistics about a series of values that the
|
||||
// client provides via the Record method. A caller will call Record once for
|
||||
// each of the values in a series. The Distribution instance will calculate the
|
||||
// mean, count, min, max and variance of the distribution.
|
||||
//
|
||||
// Example usage:
|
||||
// Distribution dist;
|
||||
// dist.Record(1);
|
||||
// dist.Record(2);
|
||||
// dist.Mean(); // Returns 1.5.
|
||||
// dist.Count(); // Returns 2.
|
||||
class Distribution {
|
||||
public:
|
||||
Distribution();
|
||||
|
||||
// Uses the provided sample value to update the computed statistics.
|
||||
void Record(double value);
|
||||
|
||||
// Return the value for each of the stats computed about the series of
|
||||
// values (min, max, count, etc.).
|
||||
double Min() const { return min_; }
|
||||
double Max() const { return max_; }
|
||||
double Mean() const { return mean_; }
|
||||
int64_t Count() const { return count_; }
|
||||
double Variance() const {
|
||||
return count_ == 0 ? 0.0 : sum_squared_deviation_ / count_;
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t count_;
|
||||
double min_;
|
||||
double max_;
|
||||
double mean_;
|
||||
double sum_squared_deviation_;
|
||||
};
|
||||
|
||||
} // namespace metrics
|
||||
} // namespace wvcdm
|
||||
|
||||
#endif // WVCDM_METRICS_DISTRIBUTION_H_
|
||||
Reference in New Issue
Block a user