@@ -11,11 +11,9 @@ public sealed class ExponentialDecayEstimator
1111{
1212 public const double LogOfHalf = - 0.69314718055994529 ; //Math.Log(0.5);
1313 public readonly TimeSpan halflife ;
14- DateTime timestampOfValue = default ( DateTime ) . ToUniversalTime ( ) ;
1514 double currentValue ;
1615
17- public DateTime UtcTimestampOfValue
18- => timestampOfValue ;
16+ public DateTime UtcTimestampOfValue { get ; private set ; } = default ( DateTime ) . ToUniversalTime ( ) ;
1917
2018 public ExponentialDecayEstimator ( TimeSpan halflife )
2119 => this . halflife = halflife ;
@@ -40,7 +38,7 @@ public double EstimatedRateOfChangePerHalflife(DateTime moment)
4038 public ExponentialDecayEstimatorValue ValueAt ( DateTime moment )
4139 {
4240 Debug . Assert ( moment . Kind == DateTimeKind . Utc , "Error:non-UTC DateTime detected; all moments should be in UTC to make reasoning about exponential decays simpler." ) ;
43- var halflives = ( moment - timestampOfValue ) . TotalSeconds / halflife . TotalSeconds ;
41+ var halflives = ( moment - UtcTimestampOfValue ) . TotalSeconds / halflife . TotalSeconds ;
4442 return new ( currentValue * Math . Exp ( LogOfHalf * Math . Max ( 0.0 , halflives ) ) ) ;
4543 }
4644
@@ -50,12 +48,12 @@ public ExponentialDecayEstimatorValue ValueAt(DateTime moment)
5048 public ExponentialDecayEstimatorValue AddAmount ( DateTime timestamp , double amount )
5149 {
5250 currentValue = ValueAt ( timestamp ) . RawValue + amount ;
53- timestampOfValue = timestamp ;
51+ UtcTimestampOfValue = timestamp ;
5452 return new ( currentValue ) ;
5553 }
5654
5755 public override string ToString ( )
58- => $ "{ currentValue } at { timestampOfValue } with halflife { halflife } ";
56+ => $ "{ currentValue } at { UtcTimestampOfValue } with halflife { halflife } ";
5957}
6058
6159public readonly struct ExponentialDecayEstimatorValue
0 commit comments