protected virtual void CalculateSignificances(string areaCode, TimePeriod timePeriod, IList<CoreDataSet> categoryDataList) { var area = AreaFactory.NewArea(_areasReader, areaCode); var nationalArea = GetNationalArea(area); var indicatorComparisonHelper = new IndicatorComparisonHelper(_indicatorMetadata, _grouping, _groupDataReader, _pholioReader, nationalArea); // Set benchmark data var benchmarkDataProvider = new BenchmarkDataProvider(_groupDataReader); AverageCalculator averageCalculator = null; // Assume parent value is in database CoreDataSet benchmarkData = benchmarkDataProvider.GetBenchmarkData(_grouping, timePeriod, averageCalculator, area); foreach (CoreDataSet coreDataSet in categoryDataList) { coreDataSet.SignificanceAgainstOneBenchmark = (int) indicatorComparisonHelper.GetSignificance(coreDataSet, benchmarkData); } }
private void AssignComparatorData(GroupRoot root, TimePeriod timePeriod) { IndicatorMetadata indicatorMetaData = GroupData.GetIndicatorMetadataById(root.IndicatorId); var benchmarkDataProvider = new BenchmarkDataProvider(GroupDataReader); // Comparator data foreach (Grouping grouping in root.Grouping) { Comparator comparator = ComparatorMap.GetComparatorById(grouping.ComparatorId, grouping.AreaTypeId); CoreDataSet data; if (comparator == null) { data = CoreDataSet.GetNullObject(string.Empty); } else { var comparatorArea = NearestNeighbourArea.IsNearestNeighbourAreaCode(comparator.Area.Code) ? AreaFactory.NewArea(AreasReader, comparator.Area.Code.Substring(5)) : comparator.Area; // Only get subnational data, do not want to prefetch England data as usually won't be needed var dataList = grouping.ComparatorId == ComparatorIds.Subnational ? root.Data : null; AverageCalculator averageCalculator = AverageCalculatorFactory.New(dataList, indicatorMetaData); data = benchmarkDataProvider.GetBenchmarkData(grouping, timePeriod, averageCalculator, comparatorArea); // Calculate England data if not found in DB (this done after so do not have to read all data when necessary) if (data.IsValueValid == false && grouping.ComparatorId == ComparatorIds.England) { dataList = GroupDataReader.GetCoreDataForAllAreasOfType(grouping, timePeriod); averageCalculator = AverageCalculatorFactory.New(dataList, indicatorMetaData); data = benchmarkDataProvider.GetBenchmarkData(grouping, timePeriod, averageCalculator, comparatorArea); } } grouping.ComparatorData = data; } }