private void FillRepositoryWithPreviousResults(IMetricsRepository repository)
        {
            Enumerable.Range(1, 31)
            .ToList()
            .ForEach(pastDay =>
            {
                var pastResultsEU = new Dictionary <IAnalyzer <IMetric>, IMetric>
                {
                    { Initializers.Size(), new DoubleMetric(MetricEntity.Dataset, "*", "Size", Math.Floor(pastDay / 3.0)) },
                    { Initializers.Mean("sales"), new DoubleMetric(MetricEntity.Column, "sales", "Mean", pastDay * 7) }
                };

                var pastResultsNA = new Dictionary <IAnalyzer <IMetric>, IMetric>
                {
                    { Initializers.Size(), new DoubleMetric(MetricEntity.Dataset, "*", "Size", pastDay) },
                    { Initializers.Mean("sales"), new DoubleMetric(MetricEntity.Column, "sales", "Mean", pastDay * 9) }
                };

                var analyzerContextEU = new AnalyzerContext(pastResultsEU);
                var analyzerContextNA = new AnalyzerContext(pastResultsNA);

                long dateTime = CreateDate(2018, 7, pastDay);

                repository.Save(new ResultKey(dateTime, new Dictionary <string, string> {
                    { "marketplace", "EU" }
                }),
                                analyzerContextEU);

                repository.Save(new ResultKey(dateTime, new Dictionary <string, string> {
                    { "marketplace", "NA" }
                }),
                                analyzerContextNA);
            });
        }
        private VerificationResult CreateAnomalyChecksAndRunEverything(
            DataFrame data,
            IMetricsRepository repository,
            Check otherCheck,
            IEnumerable <IAnalyzer <IMetric> > additionalRequiredAnalyzers)
        {
            // We only want to use historic data with the EU tag for the anomaly checks since the new
            // data point is from the EU marketplace
            var filterEU = new Dictionary <string, string> {
                { "marketplace", "EU" }
            };

            // We only want to use data points before the date time associated with the current
            // data point and only ones that are from 2018
            var afterDateTime  = CreateDate(2018, 1, 1);
            var beforeDateTime = CreateDate(2018, 8, 1);

            // Config for the size anomaly check
            var sizeAnomalyCheckConfig = new AnomalyCheckConfig(CheckLevel.Error, "Size only increases",
                                                                filterEU, afterDateTime, beforeDateTime);
            var sizeAnomalyDetectionStrategy = new AbsoluteChangeStrategy(0);

            // Config for the mean sales anomaly check
            var meanSalesAnomalyCheckConfig = new AnomalyCheckConfig(
                CheckLevel.Warning,
                "Sales mean within 2 standard deviations",
                filterEU,
                afterDateTime,
                beforeDateTime
                );

            var meanSalesAnomalyDetectionStrategy = new OnlineNormalStrategy(upperDeviationFactor: 2, lowerDeviationFactor: Option <double> .None,
                                                                             ignoreAnomalies: false);

            // ResultKey to be used when saving the results of this run
            var currentRunResultKey =
                new ResultKey(CreateDate(2018, 8, 1), new Dictionary <string, string> {
                { "marketplace", "EU" }
            });


            return(new VerificationSuite()
                   .OnData(data)
                   .AddCheck(otherCheck)
                   .AddRequiredAnalyzers(additionalRequiredAnalyzers)
                   .UseRepository(repository)
                   // Add the Size anomaly check
                   .AddAnomalyCheck(sizeAnomalyDetectionStrategy, Initializers.Size(), sizeAnomalyCheckConfig)
                   // Add the Mean sales anomaly check
                   .AddAnomalyCheck(meanSalesAnomalyDetectionStrategy, Initializers.Mean("sales"),
                                    meanSalesAnomalyCheckConfig)
                   // Save new data point in the repository after we calculated everything
                   .SaveOrAppendResult(currentRunResultKey)
                   .Run());
        }