public PartitionTrendData GetPartitionTrendData(int profileId,
            string areaCode, int indicatorId, int ageId, int sexId, int categoryTypeId, int areaTypeId)
        {
            InitGrouping(profileId, areaTypeId, indicatorId, sexId, ageId);
            InitMetadata(_grouping);
            var categories = _areasReader.GetCategories(categoryTypeId);
            var dictionaryBuilder = new PartitionTrendDataDictionaryBuilder(
                categories.Cast<INamedEntity>().ToList(), PartitionDataType.Category);

            // Add data for each time period
            var timePeriods = _grouping.GetTimePeriodIterator(_indicatorMetadata.YearType).TimePeriods;
            foreach (var timePeriod in timePeriods)
            {
                IList<CoreDataSet> dataList = _groupDataReader.GetAllCategoryDataWithinParentArea(areaCode,
                indicatorId, sexId, ageId, timePeriod).Where(x => x.CategoryTypeId == categoryTypeId).ToList();
                dictionaryBuilder.AddDataForNextTimePeriod(dataList);
            }

            // Remove entities without data from dictionary
            var allData = dictionaryBuilder.AllDataAsList;

            // Return trend data
            timePeriods = RemoveEarlyEmptyTimePeriods(dictionaryBuilder, timePeriods);
            FormatData(allData);
            var limits = new LimitsBuilder().GetLimits(allData);
            return new PartitionTrendData
            {
                Limits = limits,
                Labels = categories.Cast<INamedEntity>().ToList(),
                TrendData = dictionaryBuilder.Dictionary,
                Periods = GetTimePeriodStrings(timePeriods)
            };
        }
        public PartitionTrendData GetPartitionTrendData(int profileId,
            string areaCode, int indicatorId, int ageId, int areaTypeId)
        {
            InitGrouping(profileId, areaTypeId, indicatorId, ageId);
            InitMetadata(_grouping);
            var sexes = _pholioReader.GetAllSexes();
            var dictionaryBuilder = new PartitionTrendDataDictionaryBuilder(
                sexes.Cast<INamedEntity>().ToList(), PartitionDataType.Sex);

            // Add data for each time period
            var timePeriods = _grouping.GetTimePeriodIterator(_indicatorMetadata.YearType).TimePeriods;
            foreach (var timePeriod in timePeriods)
            {
                IList<CoreDataSet> dataList = _groupDataReader.GetCoreDataForAllSexes(
                    indicatorId, timePeriod, areaCode, ageId);
                dictionaryBuilder.AddDataForNextTimePeriod(dataList);
            }

            // Remove entities without data from dictionary
            var allData = dictionaryBuilder.AllDataAsList;
            var sexesWithData = GetSexesFromDataList(allData);
            foreach (var sex in sexes)
            {
                if (sexesWithData.Contains(sex) == false)
                {
                    dictionaryBuilder.RemoveEntity(sex.Id);
                }
            }

            // Return trend data
            timePeriods = RemoveEarlyEmptyTimePeriods(dictionaryBuilder, timePeriods);
            FormatData(allData);
            var limits = new LimitsBuilder().GetLimits(allData);
            return new PartitionTrendData
            {
                Limits = limits,
                Labels = sexesWithData.Cast<INamedEntity>().ToList(),
                TrendData = dictionaryBuilder.Dictionary,
                Periods = GetTimePeriodStrings(timePeriods)
            };
        }
コード例 #3
0
 public void When_Null_Data_List_Then_Null_Returned()
 {
     var limits = new LimitsBuilder().GetLimits(new List<CoreDataSet>());
     Assert.IsNull(limits);
 }
コード例 #4
0
 public void When_Data_List_Then_Limits_Returned()
 {
     var limits = new LimitsBuilder().GetLimits(GetCoreDataList(1,2));
     Assert.AreEqual(1, limits.Min);
     Assert.AreEqual(2, limits.Max);
 }
コード例 #5
0
 public void When_Data_List_Of_Invalid_Values_Then_Null_Returned()
 {
     var limits = new LimitsBuilder().GetLimits(GetCoreDataList(-1));
     Assert.IsNull(limits);
 }
コード例 #6
0
        private Limits GetLimits(Grouping grouping,  bool excludeComparators)
        {
            var areaCodes = new List<string>
            {
                AreaCodes.CountyUa_Cambridgeshire,
                AreaCodes.CountyUa_Bedford
            };

            var comparatorMap = new ComparatorMap();
            comparatorMap.Add(new Comparator
            {
                Area = AreaFactory.NewArea(areasReader, AreaCodes.Gor_EastOfEngland),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority,
                ComparatorId = ComparatorIds.Subnational
            });
            comparatorMap.Add(new Comparator
            {
                Area = AreaFactory.NewArea(areasReader, AreaCodes.England),
                ChildAreaTypeId = AreaTypeIds.CountyAndUnitaryAuthority,
                ComparatorId = ComparatorIds.England
            });

            var limitsBuilder = new LimitsBuilder()
            {
                ExcludeComparators = excludeComparators
            };
            return limitsBuilder.GetLimits(areaCodes, grouping, comparatorMap);
        }
コード例 #7
0
        public TrendRoot BuildTrendRoot(ComparatorMap comparatorMap, GroupRoot root,
            ITrendDataReader trendReader, IList<string> childAreaCodes)
        {

            Init();

            TrendRoot trendRoot = new TrendRoot(root);

            periods = Grouping.GetTimePeriodIterator(IndicatorMetadata.YearType).TimePeriods;

            var formatter = NumericFormatterFactory.New(IndicatorMetadata, groupDataReader);
            dataProcessor = new CoreDataProcessor(formatter);

            // Get comparator trend data
            foreach (var comparator in comparatorMap.Comparators)
            {
                CategoryArea categoryArea = comparator.Area as CategoryArea;
                if (categoryArea != null)
                {
                    var categoryTypeId = categoryArea.CategoryTypeId;
                    //TODO: we we don't have data for trends calculate on the fly
                    var categoryAreaDataList = trendReader.GetTrendDataForSpecificCategory(Grouping,
                        AreaCodes.England, categoryTypeId, categoryArea.CategoryId);
                    comparatorIdToComparatorTrendData.Add(comparator.ComparatorId, categoryAreaDataList);
                }
                else
                {
                    var comparatorAreaDataList = trendReader.GetTrendData(Grouping, comparator.Area.Code);
                    comparatorIdToComparatorTrendData.Add(comparator.ComparatorId, comparatorAreaDataList);
                }
            }

            bool hasData = false;

            foreach (string areaCode in childAreaCodes)
            {
                dataList = trendReader.GetTrendData(Grouping, areaCode);

                // Do not include areas without data
                if (dataList.Count == 0)
                {
                    bool isData = comparatorIdToComparatorTrendData
                        .Any(keyValuePair => keyValuePair.Value.Count > 0);
                    if (isData == false)
                    {
                        continue;
                    }
                }
                hasData = true;

                // Create trend data points
                IList<TrendDataPoint> trendDataPoints = new List<TrendDataPoint>();
                foreach (var timePeriod in periods)
                {

                    var dataPoint = GetDataAtSpecificTimePeriod(dataList, timePeriod)
                                    ?? CoreDataSet.GetNullObject(areaCode);

                    var significances = AssignSignificanceToTrendDataPoint(dataPoint, Grouping, timePeriod);

                    // Need to assess count before data is truncated
                    var isCountValid = dataPoint.IsCountValid;

                    dataProcessor.FormatAndTruncate(dataPoint);
                    var trendDataPoint = new TrendDataPoint(dataPoint)
                    {
                        Significance = significances,
                        IsCountValid = isCountValid
                    };
                    trendDataPoints.Add(trendDataPoint);
                }
                trendRoot.DataPoints[areaCode] = trendDataPoints;
            }

            trendRoot.RecentTrends = root.RecentTrends;

            AssignPeriods(trendRoot);

            if (hasData)
            {
                AssignComparatorDataToTrendRoot(trendRoot, root.FirstGrouping, childAreaCodes);

                // Assign limits
                var limitBuilder = new LimitsBuilder()
                {
                    ExcludeComparators = IndicatorMetadata.ValueTypeId == ValueTypeIds.Count
                };
                trendRoot.Limits = limitBuilder.GetLimits(childAreaCodes, Grouping, comparatorMap);
            }

            return trendRoot;
        }