public void GetPercentileData(TargetComparer targetComparer, Grouping grouping, IndicatorMetadata indicatorMetadata) { var bespokeComparer = targetComparer as BespokeTargetPercentileRangeComparer; if (bespokeComparer != null) { var nationalValues = groupDataReader.GetCoreDataForAllAreasOfType(grouping, TimePeriod.GetDataPoint(grouping)); var percentileCalculator = new BespokeTargetPercentileRangeCalculator(nationalValues.Where(x => x.IsValueValid).Select(x => x.Value).ToList()); bespokeComparer.LowerTargetPercentileBenchmarkData = new CoreDataSet() { Value = percentileCalculator.GetPercentileValue(bespokeComparer.GetLowerTargetPercentile()) }; bespokeComparer.UpperTargetPercentileBenchmarkData = new CoreDataSet() { Value = percentileCalculator.GetPercentileValue(bespokeComparer.GetUpperTargetPercentile()) }; } }
protected Dictionary<int, Significance> AssignSignificanceToTrendDataPoint( CoreDataSet data, Grouping grouping, TimePeriod period) { Dictionary<int, Significance> sig = new Dictionary<int, Significance>(); // Benchmark comparisons if (comparer is ICategoryComparer == false) { // Compare against benchmarks foreach (KeyValuePair<int, IList<CoreDataSet>> keyValuePair in comparatorIdToComparatorTrendData) { var comparatorId = keyValuePair.Key; CoreDataSet comparatorCoreData = GetDataAtSpecificTimePeriod(keyValuePair.Value, period); var significance = comparer.Compare(data, comparatorCoreData, IndicatorMetadata); sig.Add(comparatorId, significance); } } // Category comparison if (comparer is ICategoryComparer) { var provider = new CoreDataSetListProvider(groupDataReader); // Compare against benchmarks foreach (KeyValuePair<int, IList<CoreDataSet>> keyValuePair in comparatorIdToComparatorTrendData) { var comparatorId = keyValuePair.Key; ICategoryComparer categoryComparer; switch (comparatorId) { case ComparatorIds.England: // Get national comparer categoryComparer = GetCategoryComparerWithValues(timePeriodToNationalCategoryComparer, provider, grouping, period, AreaCodes.England); break; default: // Get subnational comparer categoryComparer = GetCategoryComparerWithValues(timePeriodToSubnationalCategoryComparer, provider, grouping, period, data.AreaCode); ; break; } sig.Add(comparatorId, (Significance)categoryComparer.GetCategory(data)); } } // Compare against target if (targetComparer != null) { if (targetComparer as BespokeTargetPreviousYearEnglandValueComparer != null) { var bespokeComparer = targetComparer as BespokeTargetPreviousYearEnglandValueComparer; // Assign benchmark data to bespoke comparator var comparatorTrendData = comparatorIdToComparatorTrendData[ComparatorIds.England]; bespokeComparer.BenchmarkData = GetDataAtSpecificTimePeriod(comparatorTrendData, period.GetTimePeriodForYearBefore()); } else { if (targetComparer as BespokeTargetPercentileRangeComparer != null) { var bespokeComparer = targetComparer as BespokeTargetPercentileRangeComparer; var nationalValues = groupDataReader.GetCoreDataForAllAreasOfType(grouping, period); var percentileCalculator = new BespokeTargetPercentileRangeCalculator(nationalValues.Where(x => x.IsValueValid).Select(x => x.Value).ToList()); bespokeComparer.LowerTargetPercentileBenchmarkData = new CoreDataSet() { Value = percentileCalculator.GetPercentileValue(bespokeComparer.GetLowerTargetPercentile()) }; bespokeComparer.UpperTargetPercentileBenchmarkData = new CoreDataSet() { Value = percentileCalculator.GetPercentileValue(bespokeComparer.GetUpperTargetPercentile()) }; } } sig.Add(ComparatorIds.Target, targetComparer.CompareAgainstTarget(data)); } return sig; }