public void TestCopyConstructor()
        {
            GroupRoot root = new GroupRoot {
                AreaTypeId = 2,
                StateSex = true,
                IndicatorId = 3,
                SexId = 5,
                PolarityId = 6,
                AgeId = 7
            };

            TrendRoot rootTrend = new TrendRoot(root);

            Assert.AreEqual(root.IndicatorId, rootTrend.IndicatorId);
            Assert.AreEqual(root.StateSex, rootTrend.StateSex);
            Assert.AreEqual(root.AreaTypeId, rootTrend.AreaTypeId);
            Assert.AreEqual(5, rootTrend.SexId);
            Assert.AreEqual(6, rootTrend.PolarityId);
            Assert.AreEqual(7, rootTrend.AgeId);
        }
        private void AssignComparatorDataToTrendRoot(TrendRoot trendRoot, Grouping grouping, IList<string> childAreaCodes)
        {
            foreach (TimePeriod period in periods)
            {
                Dictionary<int, string> comparatorToValueFs = new Dictionary<int, string>();
                Dictionary<int, double> comparatorToValue = new Dictionary<int, double>();

                trendRoot.ComparatorValueFs.Add(comparatorToValueFs);
                trendRoot.ComparatorValue.Add(comparatorToValue);

                foreach (KeyValuePair<int, IList<CoreDataSet>> keyValuePair in comparatorIdToComparatorTrendData)
                {
                    var comparatorId = keyValuePair.Key;
                    var comparatorDataList = keyValuePair.Value;

                    var data = GetFormattedValueData(period, comparatorDataList, grouping, childAreaCodes);
                    comparatorToValueFs.Add(comparatorId, data.ValueFormatted);
                    comparatorToValue.Add(comparatorId, data.Value);
                }
            }
        }
        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;
        }
 private void AssignPeriods(TrendRoot trendRoot)
 {
     trendRoot.Periods = periods.Select(p =>
         new SpecifiedTimePeriodFormatter { TimePeriod = p }.Format(IndicatorMetadata)).ToList();
 }