public TrendMarkersProvider(ITrendDataReader trendReader, TrendMarkerCalculator trendCalculator) { _trendReader = trendReader; _trendCalculator = trendCalculator; }
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; }