• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include "rtc_base/numerics/sample_stats.h"
11 
12 namespace webrtc {
13 
Max()14 double SampleStats<double>::Max() {
15   if (IsEmpty())
16     return INFINITY;
17   return GetMax();
18 }
19 
Mean()20 double SampleStats<double>::Mean() {
21   if (IsEmpty())
22     return 0;
23   return GetAverage();
24 }
25 
Median()26 double SampleStats<double>::Median() {
27   return Quantile(0.5);
28 }
29 
Quantile(double quantile)30 double SampleStats<double>::Quantile(double quantile) {
31   if (IsEmpty())
32     return 0;
33   return GetPercentile(quantile);
34 }
35 
Min()36 double SampleStats<double>::Min() {
37   if (IsEmpty())
38     return -INFINITY;
39   return GetMin();
40 }
41 
Variance()42 double SampleStats<double>::Variance() {
43   if (IsEmpty())
44     return 0;
45   return GetVariance();
46 }
47 
StandardDeviation()48 double SampleStats<double>::StandardDeviation() {
49   return sqrt(Variance());
50 }
51 
Count()52 int SampleStats<double>::Count() {
53   return static_cast<int>(GetSamples().size());
54 }
55 
AddSample(TimeDelta delta)56 void SampleStats<TimeDelta>::AddSample(TimeDelta delta) {
57   RTC_DCHECK(delta.IsFinite());
58   stats_.AddSample(delta.seconds<double>());
59 }
60 
AddSampleMs(double delta_ms)61 void SampleStats<TimeDelta>::AddSampleMs(double delta_ms) {
62   AddSample(TimeDelta::Millis(delta_ms));
63 }
AddSamples(const SampleStats<TimeDelta> & other)64 void SampleStats<TimeDelta>::AddSamples(const SampleStats<TimeDelta>& other) {
65   stats_.AddSamples(other.stats_);
66 }
67 
IsEmpty()68 bool SampleStats<TimeDelta>::IsEmpty() {
69   return stats_.IsEmpty();
70 }
71 
Max()72 TimeDelta SampleStats<TimeDelta>::Max() {
73   return TimeDelta::Seconds(stats_.Max());
74 }
75 
Mean()76 TimeDelta SampleStats<TimeDelta>::Mean() {
77   return TimeDelta::Seconds(stats_.Mean());
78 }
79 
Median()80 TimeDelta SampleStats<TimeDelta>::Median() {
81   return Quantile(0.5);
82 }
83 
Quantile(double quantile)84 TimeDelta SampleStats<TimeDelta>::Quantile(double quantile) {
85   return TimeDelta::Seconds(stats_.Quantile(quantile));
86 }
87 
Min()88 TimeDelta SampleStats<TimeDelta>::Min() {
89   return TimeDelta::Seconds(stats_.Min());
90 }
91 
Variance()92 TimeDelta SampleStats<TimeDelta>::Variance() {
93   return TimeDelta::Seconds(stats_.Variance());
94 }
95 
StandardDeviation()96 TimeDelta SampleStats<TimeDelta>::StandardDeviation() {
97   return TimeDelta::Seconds(stats_.StandardDeviation());
98 }
99 
Count()100 int SampleStats<TimeDelta>::Count() {
101   return stats_.Count();
102 }
103 
AddSample(DataRate sample)104 void SampleStats<DataRate>::AddSample(DataRate sample) {
105   stats_.AddSample(sample.bps<double>());
106 }
107 
AddSampleBps(double rate_bps)108 void SampleStats<DataRate>::AddSampleBps(double rate_bps) {
109   stats_.AddSample(rate_bps);
110 }
111 
AddSamples(const SampleStats<DataRate> & other)112 void SampleStats<DataRate>::AddSamples(const SampleStats<DataRate>& other) {
113   stats_.AddSamples(other.stats_);
114 }
115 
IsEmpty()116 bool SampleStats<DataRate>::IsEmpty() {
117   return stats_.IsEmpty();
118 }
119 
Max()120 DataRate SampleStats<DataRate>::Max() {
121   return DataRate::BitsPerSec(stats_.Max());
122 }
123 
Mean()124 DataRate SampleStats<DataRate>::Mean() {
125   return DataRate::BitsPerSec(stats_.Mean());
126 }
127 
Median()128 DataRate SampleStats<DataRate>::Median() {
129   return Quantile(0.5);
130 }
131 
Quantile(double quantile)132 DataRate SampleStats<DataRate>::Quantile(double quantile) {
133   return DataRate::BitsPerSec(stats_.Quantile(quantile));
134 }
135 
Min()136 DataRate SampleStats<DataRate>::Min() {
137   return DataRate::BitsPerSec(stats_.Min());
138 }
139 
Variance()140 DataRate SampleStats<DataRate>::Variance() {
141   return DataRate::BitsPerSec(stats_.Variance());
142 }
143 
StandardDeviation()144 DataRate SampleStats<DataRate>::StandardDeviation() {
145   return DataRate::BitsPerSec(stats_.StandardDeviation());
146 }
147 
Count()148 int SampleStats<DataRate>::Count() {
149   return stats_.Count();
150 }
151 
152 }  // namespace webrtc
153