public void InitializationIntOneTests() { var int0 = new RollingStatistics <double>(7); Assert.AreEqual(1, int0.SampleSize); Assert.AreEqual(7, int0.Mean); Assert.AreEqual(7, int0.Min); Assert.AreEqual(7, int0.Max); Assert.AreEqual(7, int0.Mean); Assert.AreEqual(double.NaN, int0.Variance); Assert.AreEqual(double.NaN, int0.StandardDeviation); }
public void InitializationIntZeroTests() { var int0 = new RollingStatistics <int>(); Assert.AreEqual(0, int0.SampleSize); Assert.AreEqual(0, int0.Mean); Assert.AreEqual(double.MaxValue, int0.Min); Assert.AreEqual(double.MinValue, int0.Max); Assert.AreEqual(0, int0.Mean); Assert.AreEqual(double.NaN, int0.Variance); Assert.AreEqual(double.NaN, int0.StandardDeviation); }
public ClubPenguinClient(MonoBehaviour monoBehaviour, string apiURL, string clientToken, string clientApiVersion, string gameZone, bool gameEncryption, bool gameDebugging, bool lagMonitoring, int gameServerLatencyWindowSize, int webServiceLatencyWindowSize, string cpMonitoringURL, string websiteApiURL, bool offlineMode) { OfflineMode = offlineMode; SyncContext = new UnitySynchronizationContext(monoBehaviour); ICommonGameSettings commonGameSettings = Service.Get <ICommonGameSettings>(); if (offlineMode && string.IsNullOrEmpty(commonGameSettings.GameServerHost) && string.IsNullOrEmpty(commonGameSettings.CPAPIServicehost)) { GameServer = new OfflineGameServerClient(this); } else { GameServer = new SmartFoxGameServerClient(this, gameZone, gameEncryption, gameDebugging, lagMonitoring); } BreadcrumbApi = new BreadcrumbApi(this); ChatApi = new ChatApi(this); ConsumableApi = new ConsumableApi(this); DurableApi = new DurableApi(this); EncryptionApi = new EncryptionApi(this); GameApi = new GameApi(this); IglooApi = new IglooApi(this); InventoryApi = new InventoryApi(this); MinigameApi = new MinigameApi(this); PlayerApi = new PlayerApi(this); QuestApi = new QuestApi(this); RewardApi = new RewardApi(this); SavedOutfitApi = new SavedOutfitApi(this); TaskApi = new TaskApi(this); IAPApi = new IAPApi(this); TutorialApi = new TutorialApi(this); ModerationApi = new ModerationApi(this); TubeApi = new TubeApi(this); DisneyStoreApi = new DisneyStoreApi(this); NewsfeedApi = new NewsfeedApi(this); CatalogApi = new CatalogApi(this); ScheduledEventApi = new ScheduledEventApi(this); DiagnosticsApi = new DiagnosticsApi(this); CaptchaApi = new CaptchaApi(this); initWAK(apiURL, clientToken, clientApiVersion); Configuration.SetBaseUri("cp-monitoring-base-uri", cpMonitoringURL); Configuration.SetBaseUri("cp-website-api-base-uri", websiteApiURL); initCPKeyValueDatabase(Service.Get <IKeychain>()); initEncryption(); RecoverableOperationService = new QueuableRecoverableOperationService(this); if (lagMonitoring) { GameServerLatency = new RollingStatistics(gameServerLatencyWindowSize); WebServiceLatency = new RollingStatistics(webServiceLatencyWindowSize); } }
public void StatisticsOfDoubleListTest() { // test doubles var doubleList = rng.InclusiveList(-1e12, 1e12, Count); Assert.NotNull(doubleList, $"VarianceTest: DoubleList is null!"); Assert.AreEqual(doubleList.Count, 100, $"doubleList.Count {doubleList.Count} != {Count}"); var statistics = new RollingStatistics <double>(doubleList); Assert.AreEqual(Count, statistics.SampleSize); { // verify mean calculation var referrenceMean = MathNet.Numerics.Statistics.Statistics.Mean(doubleList); Assert.That(statistics.Mean / referrenceMean, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.Mean {statistics.Mean} != MathNet Variance {referrenceMean}"); } { // Verify Variance calculation var referenceVariance = MathNet.Numerics.Statistics.Statistics.Variance(doubleList); Assert.That(statistics.Variance / referenceVariance, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.Variance {statistics.Variance} != MathNet Variance {referenceVariance}"); } { // Verify StdDev calculation var refereneStdDev = MathNet.Numerics.Statistics.Statistics.StandardDeviation(doubleList); Assert.That(statistics.StandardDeviation / refereneStdDev, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.StandardDeviation {statistics.StandardDeviation} != MathNet StandardDeviation {refereneStdDev}"); } { // Verify Min calculation var referenceMinimum = MathNet.Numerics.Statistics.Statistics.Minimum(doubleList); Assert.That(statistics.Min / referenceMinimum, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.Min {statistics.StandardDeviation} != MathNet StandardDeviation {referenceMinimum}"); } { // Verify Max calculation var referenceMaximum = MathNet.Numerics.Statistics.Statistics.Maximum(doubleList); Assert.That(statistics.Max / referenceMaximum, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.Max {statistics.StandardDeviation} != MathNet StandardDeviation {referenceMaximum}"); } { // Verify SampleSize calculation var referenceCount = doubleList.Count; Assert.That(statistics.SampleSize / referenceCount, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.SampleSize {statistics.StandardDeviation} != MathNet StandardDeviation {referenceCount}"); } }
public void MeanTest() { { // test doubles var threadId = Thread.CurrentThread.ManagedThreadId; var doubleList = rng.InclusiveList(-1e12, 1e12, Count); Assert.NotNull(doubleList, $"MeanTest: DoubleList is null!"); Assert.AreEqual(doubleList.Count, Count, $"doubleList.Count {doubleList.Count} != {Count}"); var reference = MathNet.Numerics.Statistics.ArrayStatistics.Mean(doubleList.ToArray()); var referenceStreaming = MathNet.Numerics.Statistics.StreamingStatistics.Mean(doubleList); Assert.AreEqual(reference / referenceStreaming, 1.0, EPSILON); var stats = new RollingStatistics <double>(doubleList); Assert.That(stats.Mean / reference, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.Mean {stats.Mean} != MathNet Mean {reference} Difference: {stats.Mean - reference}"); stats = new RollingStatistics <double>(doubleList[0]); for (int i = 1; i < doubleList.Count; i++) { stats.Add(doubleList[i]); } Assert.That(stats.Mean / reference, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<double>.Mean {stats.Mean} != MathNet Mean {reference} Difference: {stats.Mean - reference}"); } { // test ints var intList = rng.InclusiveList(int.MaxValue / 10, int.MinValue / 10, Count); var doubleList = intList.Select(i => ((IConvertible)i).ToDouble(null)); Assert.NotNull(intList, $"MeanTest: intList is null!"); Assert.AreEqual(intList.Count, 100, $"intList.Count {intList.Count} != {Count}"); var reference = MathNet.Numerics.Statistics.ArrayStatistics.Mean(doubleList.ToArray()); var referenceStreaming = MathNet.Numerics.Statistics.StreamingStatistics.Mean(doubleList); Assert.AreEqual(reference / referenceStreaming, 1.0, EPSILON); var stats = new RollingStatistics <int>(intList); Assert.That(stats.Mean / reference, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.Mean {stats.Mean} != MathNet Mean {reference} Difference: {stats.Mean - reference}"); stats = new RollingStatistics <int>(intList[0]); for (int i = 1; i < intList.Count; i++) { stats.Add(intList[i]); } Assert.That(stats.Mean / reference, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.Mean {stats.Mean} != MathNet Mean {reference} Difference: {stats.Mean - reference}"); } }
public void StatisticsOfIntListTest() { // test ints var intList = rng.InclusiveList(int.MinValue / 2, int.MaxValue / 2, Count); var doubleList = intList.Select(i => ((IConvertible)i).ToDouble(null)).ToList(); Assert.NotNull(intList, $"MeanTest: intList is null!"); var statistics = new RollingStatistics <int>(intList); Assert.AreEqual(Count, statistics.SampleSize); { // verify mean calculation var referrenceMean = MathNet.Numerics.Statistics.Statistics.Mean(doubleList); Assert.That(statistics.Mean / referrenceMean, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.Mean {statistics.Mean} != MathNet Variance {referrenceMean}"); } { // Verify Variance calculation var referenceVariance = MathNet.Numerics.Statistics.Statistics.Variance(doubleList); Assert.That(statistics.Variance / referenceVariance, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.Variance {statistics.Variance} != MathNet Variance {referenceVariance}"); } { // Verify StdDev calculation var refereneStdDev = MathNet.Numerics.Statistics.Statistics.StandardDeviation(doubleList); Assert.That(statistics.StandardDeviation / refereneStdDev, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.StandardDeviation {statistics.StandardDeviation} != MathNet StandardDeviation {refereneStdDev}"); } { // Verify Min calculation var referenceMinimum = MathNet.Numerics.Statistics.Statistics.Minimum(doubleList); Assert.That(statistics.Min / referenceMinimum, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.Min {statistics.StandardDeviation} != MathNet StandardDeviation {referenceMinimum}"); } { // Verify Max calculation var referenceMaximum = MathNet.Numerics.Statistics.Statistics.Maximum(doubleList); Assert.That(statistics.Max / referenceMaximum, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.Max {statistics.StandardDeviation} != MathNet StandardDeviation {referenceMaximum}"); } { // Verify SampleSize calculation var referenceCount = doubleList.Count; Assert.That(statistics.SampleSize / referenceCount, Is.EqualTo(1.0).Within(EPSILON), $"RollingStatistics<int>.SampleSize {statistics.StandardDeviation} != MathNet StandardDeviation {referenceCount}"); } }
public static void LogNetworkLatency(RollingStatistics gameServerStats, RollingStatistics webServiceStats) { if (gameServerStats != null && webServiceStats != null) { if (gameServerStats.SampleCount > 0) { LogAction("network_latency", "max_latency", "game_server", gameServerStats.Maximum.ToString()); LogAction("network_latency", "min_latency", "game_server", gameServerStats.Minimum.ToString()); LogAction("network_latency", "avg_latency", "game_server", gameServerStats.Average.ToString()); LogAction("network_latency", "std_dev_latency", "game_server", gameServerStats.StandardDeviation.ToString()); } if (webServiceStats.SampleCount > 0) { LogAction("network_latency", "max_latency", "web_service", webServiceStats.Maximum.ToString()); LogAction("network_latency", "min_latency", "web_service", webServiceStats.Minimum.ToString()); LogAction("network_latency", "avg_latency", "web_service", webServiceStats.Average.ToString()); LogAction("network_latency", "std_dev_latency", "web_service", webServiceStats.StandardDeviation.ToString()); } } }
public void StdDevTest() { { // test doubles var doubleList = rng.InclusiveList(-1e12, 1e12, Count); Assert.NotNull(doubleList, $"StdDevTest: DoubleList is null!"); Assert.AreEqual(doubleList.Count, 100, $"doubleList.Count {doubleList.Count} != {Count}"); var reference = MathNet.Numerics.Statistics.Statistics.StandardDeviation(doubleList); var stats = new RollingStatistics <double>(doubleList); Assert.That(reference, Is.EqualTo(stats.StandardDeviation).Within(reference * EPSILON), $"RollingStatistics<double>.StdDev {stats.StandardDeviation} != MathNet StdDev {reference}"); stats = new RollingStatistics <double>(doubleList[0]); for (int i = 1; i < doubleList.Count; i++) { stats.Add(doubleList[i]); } Assert.That(reference, Is.EqualTo(stats.StandardDeviation).Within(reference * EPSILON), $"RollingStatistics<double>.StdDev {stats.StandardDeviation} != MathNet StdDev {reference}"); } { // test ints var intList = rng.InclusiveList(int.MinValue / 2, int.MaxValue / 2, Count); var doubleList = intList.Select(i => ((IConvertible)i).ToDouble(null)); Assert.NotNull(intList, $"MeanTest: intList is null!"); Assert.AreEqual(intList.Count, Count, $"intList.Count {intList.Count} != {Count}"); var reference = MathNet.Numerics.Statistics.Statistics.StandardDeviation(doubleList); var stats = new RollingStatistics <int>(intList); Assert.That(reference, Is.EqualTo(stats.StandardDeviation).Within(reference * EPSILON), $"RollingStatistics<int>.StdDev {stats.StandardDeviation} != MathNet StdDev {reference}"); stats = new RollingStatistics <int>(intList[0]); for (int i = 1; i < intList.Count; i++) { stats.Add(intList[i]); } Assert.That(reference, Is.EqualTo(stats.StandardDeviation).Within(reference * EPSILON), $"RollingStatistics<int>.StdDev {stats.StandardDeviation} != MathNet StdDev {reference}"); } }