public void TestTrendingCalculatorCustomCriteria_ShouldRunSuccessfully_Suite2()
        {
            var trendingStrategy = new CustomTrendingCalculator();
            var inputData        = DataPreparator.PrepareData_Suite2();
            var output           = trendingStrategy.CalculateTrending <TestInputModel>(6, 1, inputData);

            Assert.AreEqual("ABC", output.First().First().item.MovieName);
            Assert.AreEqual("PQR", output[1][1].item.MovieName);
        }
Beispiel #2
0
        /// <summary>
        /// This method evaluates the trending data based on the strategy selected
        /// </summary>
        /// <param name="windowPeriod">Window Period to consider for bucketing your input data. E.g. Last 6 months data means window period is 6</param>
        /// <param name="numberOfSegmentsOfEachUnit">Number of segments in each window unit. E.g. each window is divided into 2 buckets</param>
        /// <param name="listOfModels">List of models extending the base class TModel containing the input list of data used for finding trending data</param>
        /// <param name="strategy">Enum of the type TrendCalculationStrategy which returns the trending models as per Custom Criteria or ZMean Criteria</param>
        /// <returns></returns>
        public IEnumerable <T> FindTrendingData <T>(int windowPeriod, int numberOfSegmentsOfEachUnit, List <T> listOfModels, TrendCalculationStrategy strategy) where T : TModel
        {
            var validationMessage = IsInputDataValid(windowPeriod, numberOfSegmentsOfEachUnit, listOfModels.ConvertAll(x => (TModel)x));

            if (!string.IsNullOrWhiteSpace(validationMessage))
            {
                throw new ArgumentNullException(validationMessage);
            }

            validationMessage = IsCountWithPeriodsDataValid(windowPeriod, numberOfSegmentsOfEachUnit, listOfModels.ConvertAll(x => (TModel)x));
            if (!string.IsNullOrWhiteSpace(validationMessage))
            {
                throw new ArgumentException(validationMessage);
            }

            this._strategy = strategy;

            AbstractTrendingCalculator baseCalculator = null;

            switch (_strategy)
            {
            case TrendCalculationStrategy.ZMean:
                baseCalculator = new ZMeanTrendingCalculator();
                break;

            case TrendCalculationStrategy.Custom:
                baseCalculator = new CustomTrendingCalculator();
                break;

            default:
                baseCalculator = new CustomTrendingCalculator();
                break;
            }

            var trendingModels = baseCalculator.CalculateTrending <T>(windowPeriod, numberOfSegmentsOfEachUnit, listOfModels);
            var sortedModel    = baseCalculator.GetSortedCombinedResult <T>(trendingModels);

            return(baseCalculator.PostProcessZScore <T>(sortedModel.ToList()).Select(x => x.item));
        }