/// <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 InitComparer(PholioReader pholioReader, IArea nationalArea)
 {
     if (indicatorMetadata.HasTarget)
     {
         targetComparer = TargetComparerFactory.New(indicatorMetadata.TargetConfig);
         new TargetComparerHelper(groupDataReader, nationalArea)
             .AssignExtraDataIfRequired(nationalArea, targetComparer, grouping, indicatorMetadata);
     }
     else
     {
         comparer = new IndicatorComparerFactory {PholioReader = pholioReader}.New(grouping);
     }
 }
        private void CompareLocalAreaData(GroupRoot groupRoot, IndicatorMetadata metadata)
        {
            var groupings = groupRoot.Grouping;
            foreach (var grouping in groupings)
            {
                if (grouping.IsComparatorDefined())
                {
                    comparer = new IndicatorComparerFactory { PholioReader = PholioReader }.New(grouping);
                    ICategoryComparer categoryComparer = comparer as ICategoryComparer;
                    IndicatorComparisonHelper.AssignCategoryDataIfRequired(comparer, grouping, groupDataReader,
                        groupRoot.Data);

                    foreach (CoreDataSet coreData in groupRoot.Data)
                    {
                        coreData.Significance.Add(grouping.ComparatorId, categoryComparer == null
                            ? (int)comparer.Compare(coreData, grouping.ComparatorData, metadata)
                            : categoryComparer.GetCategory(coreData));
                    }
                }
            }
        }
        public IndicatorComparer New(Grouping grouping)
        {
            assignConfidenceVariable = false;
            this.grouping = grouping;

            CheckDependencies();

            switch (grouping.ComparatorMethodId)
            {
                case ComparatorMethodId.NoComparison:
                    comparer = new NoComparisonComparer();
                    break;
                case ComparatorMethodId.SingleOverlappingCIs:
                    comparer = new SingleOverlappingCIsComparer();
                    break;
                case ComparatorMethodId.SpcForProportions:
                    comparer = new SpcForProportionsComparer();
                    assignConfidenceVariable = true;
                    break;
                case ComparatorMethodId.SpcForDsr:
                    comparer = new SpcForDsrComparer();
                    assignConfidenceVariable = true;
                    break;
                case ComparatorMethodId.DoubleOverlappingCIs:
                    comparer = new DoubleOverlappingCIsComparer();
                    break;
                case ComparatorMethodId.Quintiles:
                    comparer = new QuintilesComparer();
                    break;
                default:
                    throw new FingertipsException("Invalid comparator method ID: " + grouping.ComparatorMethodId);
            }

            AssignConfidenceVariable();

            comparer.PolarityId = grouping.PolarityId;

            return comparer;
        }
 private void Init()
 {
     comparer = NewIndicatorComparer();
     targetComparer = TargetComparerFactory.New(IndicatorMetadata.TargetConfig);
     // Note: TargetComparerHelper.AssignExtraDataIfRequired called in GroupDataProcessor
 }