private static void Evaluate(SparkSession session, Action <AnalyzerContext, IMetricsRepository> func) { DataFrame data = FixtureSupport.GetDFFull(session); AnalyzerContext results = CreateAnalysis() .Run(data, Option <IStateLoader> .None, Option <IStatePersister> .None); InMemoryMetricsRepository repository = new InMemoryMetricsRepository(); func(results, repository); }
public void should_execute_anomaly_detection_example() { // Anomaly detection operates on metrics stored in a metric repository, so lets create one InMemoryMetricsRepository metricsRepository = new InMemoryMetricsRepository(); // This is the key which we use to store the metrics for the dataset from yesterday ResultKey yesterdayKeys = new ResultKey(DateTime.Now.Ticks - 24 * 60 * 1000); /* In this simple example, we assume that we compute metrics on a dataset every day and we want * to ensure that they don't change drastically. For sake of simplicity, we just look at the * size of the data */ /* Yesterday, the data had only two rows */ var yesterdaysDataset = LoadAnomalyDetectionData(new List <object[]> { new object[] { 1, "Thingy A", "awesome thing.", "high", 0 }, new object[] { 2, "Thingy B", "available at http://thingb.com", null, 0 } }); /* We test for anomalies in the size of the data, it should not increase by more than 2x. Note * that we store the resulting metrics in our repository */ new VerificationSuite() .OnData(yesterdaysDataset) .UseRepository(metricsRepository) .SaveOrAppendResult(yesterdayKeys) .AddAnomalyCheck( new RelativeRateOfChangeStrategy(maxRateIncrease: 2.0), Size() ) .Run() .Debug(_helper.WriteLine); /* Todays data has five rows, so the data size more than doubled and our anomaly check should * catch this */ var todaysDataset = LoadAnomalyDetectionData(new List <object[]> { new object[] { 1, "Thingy A", "awesome thing.", "high", 0 }, new object[] { 2, "Thingy B", "available at http://thingb.com", null, 0 }, new object[] { 3, null, null, "low", 5 }, new object[] { 4, "Thingy D", "checkout https://thingd.ca", "low", 10 }, new object[] { 5, "Thingy W", null, "high", 12 } }); /* The key for today's result */ var todaysKey = new ResultKey(DateTime.Now.Ticks - 24 * 60 * 1000); /* Repeat the anomaly check for today's data */ var verificationResult = new VerificationSuite() .OnData(todaysDataset) .UseRepository(metricsRepository) .SaveOrAppendResult(todaysKey) .AddAnomalyCheck( new RelativeRateOfChangeStrategy(maxRateIncrease: 2.0), Size() ) .Run(); verificationResult.Status.ShouldBe(CheckStatus.Warning); _helper.WriteLine("Anomaly detected in the Size() metric!"); /* Lets have a look at the actual metrics. */ metricsRepository .Load() .ForAnalyzers(new[] { Size() }) .GetSuccessMetricsAsDataFrame(_session) .Show(); }
public void work_using_the_InMemoryMetricsRepository() { var repository = new InMemoryMetricsRepository(); TestAnomalyDetection(_session, repository); }