public void TestYearlyData()
        {
            ITrendDataReader reader = ReaderFactory.GetTrendDataReader();

            Grouping grouping = new Grouping
            {
                IndicatorId = IndicatorIds.ObesityYear6,
                BaselineYear = 2006,
                BaselineQuarter = -1,
                DataPointYear = 2009,
                YearRange = 1,
                DataPointQuarter = -1,
                SexId = SexIds.Persons,
                AgeId = AgeIds.From10To11
            };

            IList<CoreDataSet> data = reader.GetTrendData(grouping, 
                AreaCodes.CountyUa_Leicestershire);

            Assert.AreEqual(4, data.Count);

            // Assert order is correct
            for (int i = 0; i < data.Count; i++)
            {
                Assert.AreEqual(2006 + i, data[i].Year);
            }

            foreach (CoreDataSet coreDataSet in data)
            {
                Assert.AreEqual(1, coreDataSet.YearRange);
                Assert.AreEqual(-1, coreDataSet.Quarter);
            }
        }
        /// <summary>
        /// Assigns required data if the comparer calculate categories.
        /// </summary>
        /// <param name="subnationalDataList">Use null if you know the categories will be national</param>
        public static void AssignCategoryDataIfRequired(IndicatorComparer comparer, Grouping grouping, 
            IGroupDataReader groupDataReader, IList<CoreDataSet> subnationalDataList)
        {
            ICategoryComparer categoryComparer = comparer as ICategoryComparer;
            if (categoryComparer != null)
            {
                IList<CoreDataSet> coreDataList = null;

                if (grouping.ComparatorId == ComparatorIds.England)
                {
                    coreDataList = groupDataReader.GetCoreDataForAllAreasOfType(
                    grouping, TimePeriod.GetDataPoint(grouping));
                }
                else
                {
                    if (subnationalDataList != null)
                    {
                        coreDataList = subnationalDataList;
                    }
                }

                if (coreDataList != null)
                {
                    var values = coreDataList
                        .Where(x => x.IsValueValid)
                        .Select(x => x.Value)
                        .ToList();

                    categoryComparer.SetDataForCategories(values);
                }
            }
        }
        private void SetSingleAreaValue(IGroupDataReader groupDataReader, Area area, Grouping grouping, TimePeriod period)
        {
            IList<CoreDataSet> dataList = groupDataReader.GetCoreData(grouping, period, area.Code);
            if (dataList.Count == 1)
            {
                var data = dataList.First();
                if (data.IsValueValid)
                {
                    Value = data.Value;

                    if (area.IsGpPractice == false)
                    {
                        // Calculate average

                        var areasReader = ReaderFactory.GetAreasReader();

                        int count = area.IsCountry ?
                            areasReader.GetAreaCountForAreaType(grouping.AreaTypeId) :
                            areasReader.GetChildAreaCount(area.Code, grouping.AreaTypeId);

                        Value /= count;
                    }
                }
            }
            else if (dataList.Count > 1)
            {
                throw new FingertipsException(string.Format(
                    "More data than expected on determination of QOF list size: area:{0}", area.Code));
            }
        }
        public void TestAllCountyUAsInDeprivationDecile()
        {
            Grouping grouping = new Grouping
            {
                AgeId = AgeIds.Under75,
                SexId = SexIds.Persons,
                IndicatorId = IndicatorIds.OverallPrematureDeaths,
                GroupId = GroupIds.LongerLives,
                ComparatorId = ComparatorIds.Subnational,
                ComparatorMethodId = ComparatorMethodId.SingleOverlappingCIs,
                AreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority,
                YearRange = 3,
                DataPointYear = 2010
            };

            ChildAreaValuesBuilder builder = new ChildAreaValuesBuilder(
                new IndicatorComparerFactory { PholioReader = ReaderFactory.GetPholioReader() },
                ReaderFactory.GetGroupDataReader(),
                ReaderFactory.GetAreasReader(),
                ReaderFactory.GetProfileReader())
            {
                AreaTypeId = grouping.AreaTypeId,
                DataPointOffset = 0,
                ParentAreaCode = CategoryArea.CreateAreaCode(
                    CategoryTypeIds.DeprivationDecileCountyAndUA2010, 1),
                ComparatorId = grouping.ComparatorId
            };

            BuildAndVerifyData(builder, grouping);
        }
 /// <summary>
 /// Factory method
 /// </summary>
 public static GroupRootTrendBuilderBase New(Grouping grouping, IndicatorMetadata indicatorMetadata)
 {
     GroupRootTrendBuilderBase builder = GetAppropriateBuilderType(grouping);
     builder.Grouping = grouping;
     builder.IndicatorMetadata = indicatorMetadata;
     return builder;
 }
 private void SetOffsetTimePeriod(Grouping grouping, int dataPointOffset, TimePeriod dataPointPeriod, YearType yearType)
 {
     if (dataPointOffset < 0)
     {
         // Ensures datapoint cannot be exceeded
         TimePeriod = dataPointPeriod;
     }
     else
     {
         TimePeriod baseline = TimePeriod.GetBaseline(grouping);
         TimePeriodIterator iterator = new TimePeriodIterator(baseline, dataPointPeriod, yearType);
         int periodCount = iterator.TimePeriods.Count;
         int index = periodCount - 1 - dataPointOffset;
         if (index < periodCount && index > 0)
         {
             TimePeriod = iterator.TimePeriods[index];
         }
         else
         {
             if (index < 0)
             {
                 // Ensures baseline cannot be overshot
                 TimePeriod = new TimePeriod { Year = InvalidYear };
             }
             else
             {
                 TimePeriod = baseline;
             }
         }
     }
 }
 public Grouping(Grouping templateGrouping)
 {
     // TODO use automapper
     GroupingId = templateGrouping.GroupingId;
     GroupId = templateGrouping.GroupId;
     SexId = templateGrouping.SexId;
     Sex = templateGrouping.Sex;
     AgeId = templateGrouping.AgeId;
     Age = templateGrouping.Age;
     AreaTypeId = templateGrouping.AreaTypeId;
     IndicatorId = templateGrouping.IndicatorId;
     PolarityId = templateGrouping.PolarityId;
     ComparatorMethodId = templateGrouping.ComparatorMethodId;
     ComparatorTargetId = templateGrouping.ComparatorTargetId;
     ComparatorConfidence = templateGrouping.ComparatorConfidence;
     Sequence = templateGrouping.Sequence;
     BaselineYear = templateGrouping.BaselineYear;
     BaselineMonth = templateGrouping.BaselineMonth;
     BaselineQuarter = templateGrouping.BaselineQuarter;
     DataPointYear = templateGrouping.DataPointYear;
     DataPointQuarter = templateGrouping.DataPointQuarter;
     DataPointMonth = templateGrouping.DataPointMonth;
     YearRange = templateGrouping.YearRange;
     TimePeriodText = templateGrouping.TimePeriodText;
     ComparatorData = templateGrouping.ComparatorData;
 }
        public override CoreDataSet GetData(Grouping grouping, TimePeriod timePeriod, IndicatorMetadata indicatorMetadata)
        {
            double val = practiceDataAccess.GetPracticeAggregateDataValue(grouping, timePeriod, Area.Code);

            return val.Equals(ValueData.NullValue) ?
                null :
                new CoreDataSet { Value = val };
        }
 public IndicatorMetadata GetIndicatorMetadata(Grouping grouping)
 {
     IndicatorMetadata indicatorMetadata = reader.GetIndicatorMetadata(grouping, IndicatorMetadataTextProperties);
     OverrideGenericTextMetadata(
         new List<Grouping> { grouping },
         new List<IndicatorMetadata> { indicatorMetadata });
     return indicatorMetadata;
 }
        public override CoreDataSet GetData(Grouping grouping, TimePeriod timePeriod, IndicatorMetadata indicatorMetadata)
        {
            double val = practiceDataAccess.GetGpDeprivationDecileDataValue(grouping, timePeriod, categoryArea);

            return val.Equals(ValueData.NullValue) ?
                null :
                new CoreDataSet { Value = val };
        }
 private static void CheckOnlyOneCoreDataSetFound(Grouping grouping, IArea area,
     IList<CoreDataSet> dataList)
 {
     if (dataList.Count > 1)
     {
         throw new FingertipsException(string.Format("More than one CoreDataSet row for: IndicatorId={0} Area={1}",
             grouping.IndicatorId, area.Code));
     }
 }
        public void GetDataReturnsNullIfValueUndefined()
        {
            Grouping grouping = new Grouping();
            TimePeriod timePeriod = new TimePeriod();

            var data = CoreDataSetProvider(grouping, timePeriod, ValueData.NullValue)
                .GetData(grouping, timePeriod, null);
            Assert.IsNull(data);
        }
        public void GetDataReturnsNullIfValueUndefined()
        {
            Grouping grouping = new Grouping();
            TimePeriod timePeriod = new TimePeriod();

            var data = PracticeAggregateCoreDataSetProvider(grouping, timePeriod, ValueData.NullValue)
                .GetData(grouping, timePeriod, IndicatorMetadata());
            Assert.IsNull(data);
        }
        private Limits GetLimitsOfSpecifiedAreas(Grouping grouping)
        {
            ITrendDataReader trendReader = ReaderFactory.GetTrendDataReader();

            double? min = trendReader.GetMin(grouping, areaCodes);
            double? max = trendReader.GetMax(grouping, areaCodes);

            return GetLimitsFromMinAndMax(min, max);
        }
 public void TestMonthAndQuarterAreInitialisedToUndefined()
 {
     var g = new Grouping();
     const int undefined = TimePoint.Undefined;
     Assert.AreEqual(undefined, g.BaselineMonth);
     Assert.AreEqual(undefined, g.BaselineQuarter);
     Assert.AreEqual(undefined, g.DataPointMonth);
     Assert.AreEqual(undefined, g.DataPointQuarter);
 }
        public Limits GetLimits(IList<string> childAreaCodes, Grouping grouping, ComparatorMap comparatorMap)
        {
            areaCodes = new List<string>();

            AddRegionAndChildAreas(childAreaCodes, comparatorMap);
            AddNationalArea(comparatorMap);

            return GetLimitsOfSpecifiedAreas(grouping);
        }
 protected void InitBuild(Grouping grouping)
 {
     if (grouping != null)
     {
         Grouping = grouping;
         IndicatorMetadata = IndicatorMetadataRepository.Instance.GetIndicatorMetadata(grouping.IndicatorId);
         Period = new DataPointOffsetCalculator(grouping, DataPointOffset, IndicatorMetadata.YearType).TimePeriod;
         Formatter = GetFormatter();
     }
 }
        public void GetData()
        {
            double val = 2;
            var grouping = new Grouping();
            var timePeriod = new TimePeriod();

            CoreDataSet data = CoreDataSetProvider(grouping, timePeriod, val)
                .GetData(grouping, timePeriod, null);
            Assert.AreEqual(val, data.Value);
        }
 private void AssignPropertiesFromGrouping(Grouping grouping)
 {
     root.PolarityId = grouping.PolarityId;
     root.SexId = grouping.SexId;
     root.AgeId = grouping.AgeId;
     root.ComparatorMethodId = grouping.ComparatorMethodId;
     root.YearRange = grouping.YearRange;
     root.Sex = grouping.Sex;
     root.Age = grouping.Age;
 }
 private static Grouping Aged0To4Years()
 {
     var grouping = new Grouping
     {
         IndicatorId = IndicatorIds.Aged0To4Years,
         SexId = SexIds.Persons,
         AgeId = AgeIds.From0To4
     };
     return grouping;
 }
 public static TimePeriod GetDataPoint(Grouping grouping)
 {
     return new TimePeriod
     {
         Year = grouping.DataPointYear,
         YearRange = grouping.YearRange,
         Quarter = grouping.DataPointQuarter,
         Month = grouping.DataPointMonth
     };
 }
        public IndicatorComparisonHelper(IndicatorMetadata indicatorMetadata, Grouping grouping,
            IGroupDataReader groupDataReader, PholioReader pholioReader, IArea nationalArea)
        {
            // Assign constructor parameter to instance variables
            this.indicatorMetadata = indicatorMetadata;
            this.grouping = grouping;
            this.groupDataReader = groupDataReader;

            InitComparer(pholioReader, nationalArea);
        }
 public static TimePeriod GetBaseline(Grouping grouping)
 {
     return new TimePeriod
     {
         Year = grouping.BaselineYear,
         YearRange = grouping.YearRange,
         Quarter = grouping.BaselineQuarter,
         Month = grouping.BaselineMonth
     };
 }
        public override IList<CoreDataSet> AddMultipleAreaData(RowLabels rowLabels, Grouping grouping, 
            TimePeriod timePeriod, IndicatorMetadata metadata, Dictionary<string, Area> areaCodeToParentMap)
        {
            var dataList = GroupDataReader.GetCoreDataListForAllCategoryAreasOfCategoryAreaType(
                grouping, timePeriod, _categoryAreaTypeId, AreaCodes.England);

            ProfileDataWriter.AddCategorisedData(Worksheet, rowLabels, dataList, subnationalCategoryIdToCategoryAreaMap);

            return dataList;
        }
        public void GetData()
        {
            double val = 2;
            Grouping grouping = new Grouping();
            TimePeriod timePeriod = new TimePeriod();

            var data = PracticeAggregateCoreDataSetProvider(grouping, timePeriod, val)
                .GetData(grouping, timePeriod, IndicatorMetadata());
            Assert.AreEqual(val, data.Value);
        }
 private Grouping Grouping()
 {
     Grouping grouping = new Grouping
     {
         IndicatorId = indicatorId,
         SexId = sexId,
         AgeId = ageId
     };
     return grouping;
 }
        private ShapeCoreDataSetProvider PracticeAggregateCoreDataSetProvider(Grouping grouping,
            TimePeriod timePeriod, double val)
        {
            var practiceDataAccess = new Mock<PracticeDataAccess>(MockBehavior.Strict);
            practiceDataAccess.Protected();
            practiceDataAccess.Setup(x => x
                .GetPracticeAggregateDataValue(grouping, timePeriod, AreaCode))
                .Returns(val);

            return new ShapeCoreDataSetProvider(area, practiceDataAccess.Object);
        }
        private GpDeprivationDecileCoreDataSetProvider CoreDataSetProvider(Grouping grouping,
            TimePeriod timePeriod, double val)
        {
            var practiceDataAccess = new Mock<PracticeDataAccess>(MockBehavior.Strict);
            practiceDataAccess.Protected();
            practiceDataAccess.Setup(x => x
                .GetGpDeprivationDecileDataValue(grouping, timePeriod, categoryArea))
                .Returns(val);

            return new GpDeprivationDecileCoreDataSetProvider(categoryArea, practiceDataAccess.Object);
        }
 public DataPointOffsetCalculator(Grouping grouping, int dataPointOffset, YearType yearType)
 {
     TimePeriod dataPointPeriod = TimePeriod.GetDataPoint(grouping);
     if (dataPointOffset == 0)
     {
         TimePeriod = TimePeriod.GetDataPoint(grouping);
     }
     else
     {
         SetOffsetTimePeriod(grouping, dataPointOffset, dataPointPeriod, yearType);
     }
 }
        /// <summary>
        ///     Supported combinations:
        ///     Parent area England & comparator (i) deprivation decile (ii) national
        ///     Parent area is a region & comparator (i) region
        /// </summary>
        public IList<CoreDataSet> Build(Grouping grouping)
        {
            InitBuild(grouping);

            if (Grouping != null)
            {
                parentArea = AreaFactory.NewArea(areasReader, ParentAreaCode);
                return GetDataList();
            }

            return null;
        }