public void Test_Multiple_Area_Data_By_Category_Id()
        {
            var collector = new CoreDataCollector();

            collector.AddDataList(GetDataThatVariesByCategoryId());
            collector.AddDataList(GetDataThatVariesByCategoryId());

            Assert.AreEqual(2, collector.GetDataListForArea(new CategoryIdAndAreaCode { CategoryId = 2}).Count);
        }
        public void Test_Single_Area_Data()
        {
            var collector = new CoreDataCollector();

            collector.AddData(new CoreDataSet());
            collector.AddData(new CoreDataSet());
            collector.AddData(new CoreDataSet());

            Assert.AreEqual(3, collector.GetDataList().Count);
        }
        public void WriteMultipleSubnationalTrendMarkers(WorksheetInfo worksheetInfo, Grouping grouping,
            IndicatorMetadata indicatorMetadata, CoreDataCollector coreDataCollector,
            IList<CategoryIdAndAreaCode> categoryIdAndAreaCodes)
        {
            int rowOffset = categoryIdAndAreaCodes.Count;

            foreach (var area in categoryIdAndAreaCodes)
            {
                var dataList = coreDataCollector.GetDataListForArea(area);
                var result = _trendMarkersProvider.GetTrendMarkerResult(indicatorMetadata, grouping, dataList);
                _profileDataWriter.AddTrendMarker(GetLabel(result), rowOffset, worksheetInfo);
                rowOffset--;
            }
        }
 public void WriteSingleSubnationalTrendMarker(WorksheetInfo worksheetInfo, Grouping grouping,
     IndicatorMetadata indicatorMetadata, CoreDataCollector coreDataCollector)
 {
 }
 public void WriteMultipleSubnationalTrendMarkers(WorksheetInfo worksheetInfo, Grouping grouping,
     IndicatorMetadata indicatorMetadata, CoreDataCollector coreDataCollector, IList<CategoryIdAndAreaCode> categoryIdAndAreaCodes)
 {
 }
 public void WriteSingleSubnationalTrendMarker(WorksheetInfo worksheetInfo, Grouping grouping,
     IndicatorMetadata indicatorMetadata, CoreDataCollector coreDataCollector)
 {
     List<CoreDataSet> dataList = coreDataCollector.GetDataList();
     var result = _trendMarkersProvider.GetTrendMarkerResult(indicatorMetadata, grouping, dataList);
     _profileDataWriter.AddTrendMarker(GetLabel(result), RowOffsetForOneArea, worksheetInfo);
 }
        private void WriteCoreData(GroupData data, ParentArea parentArea)
        {
            if (data.IsDataOk)
            {
                var valueNoteLookUp = ValueNotes.ToDictionary(x => x.Id, x => x.Text);

                // Child areas
                var childAreaCodes = data.Areas.Select(x => x.Code).ToArray();
                var childAreaCodeToAreaMap = data.Areas.ToDictionary(area => area.Code);

                // Worksheets
                WorksheetInfo childAreaWorksheet = _profileDataWriter.GetWorksheetInfo(_childAreaTypeSheetName);
                WorksheetInfo subnationalWorksheet = _profileDataWriter.GetWorksheetInfo(_subnationalAreaTypeSheetName);
                WorksheetInfo nationalWorksheet = _profileDataWriter.GetWorksheetInfo(NationalLabel);

                // Subnational areas
                ParentDataWriter parentDataWriter = ParentDataWriterFactory.New(_areasReader, _groupDataReader,
                    subnationalWorksheet, _profileDataWriter, _subnationalAreaType);
                var parentAreaDataProvider = new CoreDataSetProviderFactory().New(_parentArea);

                // No subnational sheet if direct parent area is country
                var isSubnationalSheet = subnationalWorksheet != null;

                var areMultipleSubnationalAreasRequired = AreMultipleSubnationalAreasRequired();

                foreach (var groupRoot in data.GroupRoots)
                {
                    // Check this data has not already been writen
                    var key = new GroupRootUniqueKey(groupRoot).Key + parentArea.AreaCode;
                    if (_groupRootKeys.Contains(key))
                    {
                        // This added has already been written
                        continue;
                    }
                    _groupRootKeys.Add(key);

                    var indicatorMetadata = data.GetIndicatorMetadataById(groupRoot.IndicatorId);

                    // Adding here means order in metadata sheet is same as in data sheet
                    AddMetadata(indicatorMetadata);

                    var timePeriodFormatter = new TimePeriodTextFormatter(indicatorMetadata);
                    var coreDataCollector = new CoreDataCollector();

                    var grouping = groupRoot.Grouping.FirstOrDefault();
                    if (grouping != null)
                    {
                        var sex = _labelReader.LookUpSexLabel(grouping.SexId);
                        var age = _labelReader.LookUpAgeLabel(grouping.AgeId);

                        var timePeriods = grouping.GetTimePeriodIterator(indicatorMetadata.YearType).TimePeriods;

                        // Write core data
                        foreach (TimePeriod timePeriod in timePeriods)
                        {
                            string timeString = timePeriodFormatter.Format(timePeriod);

                            var rowLabels = new RowLabels
                            {
                                Age = age,
                                Sex = sex,
                                TimePeriod = timeString,
                                IndicatorName = indicatorMetadata.Descriptive[IndicatorMetadataTextColumnNames.Name],
                                ValueNoteLookUp = valueNoteLookUp
                            };

                            // Write child area data
                            var coreDataList = _groupDataReader.GetCoreData(grouping, timePeriod, childAreaCodes);
                            _profileDataWriter.AddData(childAreaWorksheet, rowLabels, coreDataList, childAreaCodeToAreaMap, _areaCodeToParentMap);

                            // Subnational data
                            if (isSubnationalSheet)
                            {
                                if (areMultipleSubnationalAreasRequired)
                                {
                                    // Multiple parent areas
                                    var dataList = parentDataWriter.AddMultipleAreaData(rowLabels, grouping, timePeriod,
                                        indicatorMetadata, _areaCodeToParentMap);
                                    coreDataCollector.AddDataList(dataList);
                                }
                                else
                                {
                                    // One parent area
                                    var coreData = parentAreaDataProvider.GetData(grouping, timePeriod, indicatorMetadata);
                                    _profileDataWriter.AddData(subnationalWorksheet, rowLabels, coreData, _parentArea);
                                    coreDataCollector.AddData(coreData);
                                }
                            }

                            // Write national data
                            var nationalData = new CoreDataSetProviderFactory().New(_nationalArea).GetData(grouping, timePeriod, indicatorMetadata);
                            _profileDataWriter.AddData(nationalWorksheet, rowLabels, nationalData, _nationalArea);
                        }

                        // Write trend data
                        var trendMarkerWriter = TrendMarkerWriterFactory.New(_profileDataWriter, groupRoot.PolarityId, timePeriods, _profile.HasTrendMarkers);

                        // Child area trend markers
                        trendMarkerWriter.WriteChildTrendMarkers(childAreaWorksheet, groupRoot.RecentTrends, childAreaCodes);

                        // Subnational trend markers
                        if (isSubnationalSheet)
                        {
                            if (areMultipleSubnationalAreasRequired)
                            {
                                trendMarkerWriter.WriteMultipleSubnationalTrendMarkers(subnationalWorksheet, grouping,
                                    indicatorMetadata, coreDataCollector, parentDataWriter.CategoryIdAndAreaCodes);
                            }
                            else
                            {
                                trendMarkerWriter.WriteSingleSubnationalTrendMarker(subnationalWorksheet, grouping,
                                    indicatorMetadata, coreDataCollector);
                            }
                        }

                        // National trend markers
                        trendMarkerWriter.WriteNationalTrendMarkers(nationalWorksheet, groupRoot.RecentTrends,
                            _nationalArea.Code);
                    }
                }
            }
        }