public void TestStatsReturnedNullIfOneDataPoint()
        {
            var values = new List<double>();
            values.Add(4);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(values);
            Assert.IsNull(calc.GetStats());
        }
        public void TestGetStatsFor1To100()
        {
            var min = 1;
            var max = 100;
            var data = GetValues(min, max);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(data);
            IndicatorStatsPercentiles statsPercentiles = calc.GetStats();
            Assert.AreEqual(min, statsPercentiles.Min);
            Assert.AreEqual(max, statsPercentiles.Max);
            Assert.AreEqual(25.75, statsPercentiles.Percentile25);
            Assert.AreEqual(75.25, statsPercentiles.Percentile75);
        }
        public void TestGetStatsFor1To17()
        {
            var min = 1;
            var max = 17;
            var values = GetValues(min, max);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(values);
            IndicatorStatsPercentiles statsPercentiles = calc.GetStats();
            Assert.AreEqual(min, statsPercentiles.Min);
            Assert.AreEqual(max, statsPercentiles.Max);
            Assert.AreEqual(5, statsPercentiles.Percentile25);
            Assert.AreEqual(13, statsPercentiles.Percentile75);
        }
        public void TestGetStatsFor50To60()
        {
            var min = 50;
            var max = 60;
            var values = GetValues(min, max);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(values);
            IndicatorStatsPercentiles statsPercentiles = calc.GetStats();
            Assert.AreEqual(min, statsPercentiles.Min);
            Assert.AreEqual(max, statsPercentiles.Max);
            Assert.AreEqual(52.5, statsPercentiles.Percentile25);
            Assert.AreEqual(57.5, statsPercentiles.Percentile75);
        }
        public void TestStatsNullIfThreePoints()
        {
            var data = new List<double>();
            data.Add(4);
            data.Add(5);
            data.Add(6);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(data);
            Assert.IsNull(calc.GetStats());
        }
        public void TestStatsNullIfTwoPoints()
        {
            var values = new List<double>();
            values.Add(4);
            values.Add(5);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(values);
            Assert.IsNull(calc.GetStats());
        }
 public void TestStatsReturnedNullIfNoData()
 {
     IndicatorStatsCalculator calc = new IndicatorStatsCalculator(new List<double>());
     Assert.IsNull(calc.GetStats());
 }
        public void TestGetStatsWithDoubleList()
        {
            List<double> data = new List<double>();
            double val = 50;
            for (int i = 0; i < 11; i++)
            {
                data.Add(val);
                val += 1;
            }

            // 50-60
            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(data);
            IndicatorStatsPercentiles statsPercentiles = calc.GetStats();
            Assert.AreEqual(50, statsPercentiles.Min);
            Assert.AreEqual(60, statsPercentiles.Max);
            Assert.AreEqual(52.5, statsPercentiles.Percentile25);
            Assert.AreEqual(57.5, statsPercentiles.Percentile75);
        }
 public void TestStatsWithoutPercentilesNullIfNoData()
 {
     IndicatorStatsCalculator calc = new IndicatorStatsCalculator(new List<double>());
     Assert.IsNull(calc.GetStatsWithoutPercentiles());
 }
        public void TestStatsWithoutPercentiles()
        {
            var data = new List<double>();
            data.Add(4);
            data.Add(5);
            data.Add(6);

            IndicatorStatsCalculator calc = new IndicatorStatsCalculator(data);
            Assert.AreEqual(6, calc.GetStatsWithoutPercentiles().Max);
            Assert.AreEqual(4, calc.GetStatsWithoutPercentiles().Min);
        }
        public Dictionary<int, IndicatorStatsResponse> GetIndicatorStats()
        {
            profileIds = _parameters.RestrictResultsToProfileIdList;
            parentArea = AreaFactory.NewArea(areasReader, _parameters.ParentAreaCode);

            var roots = GetRoots();
            var responseObjects = new Dictionary<int, IndicatorStatsResponse>();

            SetAreaCodesToIgnore();

            if (parentArea.IsCcg)
            {
                ccgPopulation = new CcgPopulationProvider(pholioReader).GetPopulation(parentArea.Code);
            }

            childAreaCount = new ChildAreaCounter(areasReader)
                .GetChildAreasCount(parentArea, _parameters.ChildAreaTypeId);

            int rootIndex = 0;
            foreach (var root in roots)
            {
                Grouping grouping = root.Grouping[0];
                IndicatorMetadata metadata = indicatorMetadataRepository.GetIndicatorMetadata(grouping);
                TimePeriod timePeriod = new DataPointOffsetCalculator(grouping, _parameters.DataPointOffset, metadata.YearType).TimePeriod;

                IEnumerable<double> values = GetValuesForStats(grouping, timePeriod);

                IndicatorStatsResponse statsAndStatF;
                if (values != null)
                {
                    IndicatorStatsPercentiles statsPercentiles = new IndicatorStatsCalculator(values).GetStats();
                    var formatter = NumericFormatterFactory.New(metadata, groupDataReader);
                    indicatorStatsProcessor.Truncate(statsPercentiles);

                    statsAndStatF = new IndicatorStatsResponse
                    {
                        IID = metadata.IndicatorId,
                        Stats = statsPercentiles,
                        StatsF = formatter.FormatStats(statsPercentiles),
                        HaveRequiredValues = doEnoughAreasHaveValues
                    };
                }
                else
                {
                    // No stats calculated
                    statsAndStatF = new IndicatorStatsResponse
                    {
                        IID = metadata.IndicatorId,
                        HaveRequiredValues = doEnoughAreasHaveValues
                    };
                }
                responseObjects[rootIndex] = statsAndStatF;

                rootIndex++;
            }

            return responseObjects;
        }