private List <PieChart> Populate(List <SentenceFragment> dataSlices, string monthYear) { List <PieChart> pieCharts = null; //bool isPanTumor = ChartAuditRuleEngine.GetTumors(sentenceFragments[0]).Count == 0; var measureRE = dataSlices[0].RecognizedEntities.Where(re => re.IsMeasure).FirstOrDefault(); string measureName = measureRE.Entity.DomainName; string measureColumn = measureRE.Entity.FieldName; string measureRecognizedName = measureRE.RecognizedName; if (String.IsNullOrEmpty(measureName)) { return(null); } double residualVal = 100; string legendColumn = null; if (TumorNames.Distinct().Count() == 1) { legendColumn = CAConstants.DIMENSION1_COMPONENT3; } else { legendColumn = CAConstants.DIMENSION1_COMPONENT1; } pieCharts = new List <PieChart> { new PieChart { Caption = String.Format("{0} {1} {2} in {3}", TumorNames[0], String.Empty, measureRecognizedName, monthYear), Slices = new List <PieSlice>() } }; foreach (var row in dataSlices) { var sliceMonthYear = row.RecognizedEntities. Where(re => re.Entity is Time). Select(re => re.Value.ToFormattedDateTimeStr("MMM yyyy")) .FirstOrDefault(); if (String.Compare(monthYear, sliceMonthYear, true) == 0) { string tumorName = row.RecognizedEntities. Where(re => String.Compare(re.Entity.FieldName, legendColumn, true) == 0). Select(RE => RE.Value.SafeTrim()). FirstOrDefault(); if (String.IsNullOrEmpty(tumorName)) { return(null); } double measureVal = row.RecognizedEntities. Where(re => re.IsMeasure). Select(re => re.Value.SafeToDouble()). FirstOrDefault(); residualVal -= measureVal; pieCharts[0].Slices.Add(new PieSlice { Legend = String.Empty, Value = measureVal }); } } if (residualVal > 0) { pieCharts[0].Slices.Add(new PieSlice { Legend = CAConstants.RESIDUAL_SLICE, Value = Math.Round(residualVal, CAConstants.CHART_LABEL_PRECISION) }); } Arrange(pieCharts); return(pieCharts); }
private List <PieChart> Populate(List <SentenceFragment> dataSlices, string monthYear) { List <PieChart> pieCharts = null; //bool isPanTumor = ChartAuditRuleEngine.GetTumors(sentenceFragments[0]).Count == 0; var measureRE = dataSlices[0].RecognizedEntities.Where(re => re.IsMeasure).FirstOrDefault(); string measureName = measureRE.Entity.DomainName; string measureColumn = measureRE.Entity.FieldName; string measureRecognizedName = measureRE.RecognizedName; if (String.IsNullOrEmpty(measureName)) { return(null); } double residualVal = 100; //if single regimen if (RegimenNames.Distinct().Count() == 1) { string legendColumn = null; if (TumorNames.Distinct().Count() == 1) { legendColumn = CAConstants.DIMENSION1_COMPONENT3; } else { legendColumn = CAConstants.DIMENSION1_COMPONENT1; } pieCharts = new List <PieChart> { new PieChart { Caption = String.Format("{0} {1} {2} in {3}", TumorNames[0], RegimenNames[0], measureRecognizedName, monthYear), Slices = new List <PieSlice>() } }; foreach (var row in dataSlices) { string sliceMonthYear = row.RecognizedEntities. Where(re => re.Entity is Time). Select(re => re.Value.ToFormattedDateTimeStr("MMM yyyy")). FirstOrDefault(); if (String.Compare(monthYear, sliceMonthYear, true) == 0) { string tumorName = row.RecognizedEntities. Where(re => String.Compare(re.Entity.FieldName, legendColumn, true) == 0). Select(re => re.Value.SafeTrim()). FirstOrDefault(); if (String.IsNullOrWhiteSpace(tumorName)) { return(null); } double measureVal = row.RecognizedEntities. Where(re => re.IsMeasure). Select(re => re.Value.SafeToDouble()). FirstOrDefault(); residualVal -= measureVal; pieCharts[0].Slices.Add(new PieSlice { Legend = RegimenNames[0] /*tumorName*/, Value = measureVal }); } } if (residualVal > 0) { pieCharts[0].Slices.Add(new PieSlice { Legend = CAConstants.RESIDUAL_SLICE, Value = Math.Round(residualVal, CAConstants.CHART_LABEL_PRECISION) }); } } //if single tumor else if (TumorNames.Distinct().Count() == 1) { pieCharts = new List <PieChart> { new PieChart { Caption = String.Format("{0} {1} in {2}", TumorNames[0], measureRecognizedName, monthYear), Slices = new List <PieSlice>() } }; foreach (var row in dataSlices) { string sliceMonthYear = row.RecognizedEntities. Where(re => re.Entity is Time). Select(re => re.Value.ToFormattedDateTimeStr("MMM yyyy")). FirstOrDefault(); if (String.Compare(monthYear, sliceMonthYear, true) == 0) { string regimenName = row.RecognizedEntities. Where(re => re.Entity is Regimen). Select(re => re.Value.SafeTrim()). FirstOrDefault(); if (String.IsNullOrEmpty(regimenName)) { return(null); } double measureVal = row.RecognizedEntities. Where(re => re.IsMeasure). Select(re => re.Value.SafeToDouble()). FirstOrDefault(); residualVal -= measureVal; pieCharts[0].Slices.Add(new PieSlice { Legend = regimenName, Value = measureVal }); } } //do math.round again as sometimes subtraction on 2 decimal places is resulting in multiple decimal values (though 0 in all places but last) if (residualVal > 0) { AdjustResidual(pieCharts, residualVal); } } Arrange(pieCharts); return(pieCharts); }