public MeterMetric(string eventType, TimeUnit rateUnit) { var timestamp = Timer.ElapsedNanoseconds; _m1Rate = EWMA.OneMinuteEWMA(timestamp); _m5Rate = EWMA.FiveMinuteEWMA(timestamp); _m15Rate = EWMA.FifteenMinuteEWMA(timestamp); EventType = eventType; RateUnit = rateUnit; Timer.Tick += Tick; }
public void Can_relative_decay_rates_for_discrete_values() { var one = EWMA.OneMinuteEWMA(InitialTimestamp); one.Update(100000); one.Tick(FiveSecondsTimestamp); var five = EWMA.FiveMinuteEWMA(InitialTimestamp); five.Update(100000); five.Tick(FiveSecondsTimestamp); var fifteen = EWMA.FifteenMinuteEWMA(InitialTimestamp); fifteen.Update(100000); fifteen.Tick(FiveSecondsTimestamp); var rateOne = one.Rate(TimeUnit.Seconds); var rateFive = five.Rate(TimeUnit.Seconds); var rateFifteen = fifteen.Rate(TimeUnit.Seconds); Assert.AreEqual(20000, rateOne); Assert.AreEqual(20000, rateFive); Assert.AreEqual(20000, rateFifteen); var timestamp = FiveSecondsTimestamp; ElapseMinute(timestamp, one); rateOne = one.Rate(TimeUnit.Seconds); ElapseMinute(timestamp, five); rateFive = five.Rate(TimeUnit.Seconds); ElapseMinute(timestamp, fifteen); rateFifteen = fifteen.Rate(TimeUnit.Seconds); Assert.AreEqual(7357.5888234288504d, rateOne); Assert.AreEqual(16374.615061559636d, rateFive); Assert.AreEqual(18710.13970063235d, rateFifteen); }
public void EWMA_aFifteenMinuteEWMAWithAValueOfThree() { var ewma = EWMA.FifteenMinuteEWMA(); ewma.Update(3L); ewma.Tick(); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.6, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.56130419, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.52510399, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.49123845, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.45955700, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.42991879, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.40219203, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.37625345, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.35198773, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.32928698, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.30805027, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.28818318, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.26959738, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.25221023, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.23594443, 0.000001); ElapseMinute(ewma); ewma.GetRate(TimeUnit.Seconds).Should().BeApproximately(0.22072766, 0.000001); }