public async Task <PieChartModel <int> > Get(GraduateFilterModel model) { var groupings = _graduationFactService.BaseQuery(model) .Where(x => x.GraduationStatus.DiplomaType != "Not Applicable") .GroupBy(x => x.GraduationStatus.DiplomaType); return(await _graduationFactService.CreateBaseChart(groupings, "Diploma Type")); }
public async Task <PercentageTotalBarChartModel> ByStatus(GraduateFilterModel model) { var groupings = _graduationFactService.BaseQuery(model) .GroupBy(x => new GraduateTrendGroupByModel { ExpectedGraduationYear = x.Demographic.ExpectedGraduationYear, SchoolYear = x.SchoolYearKey, SchoolYearDescription = x.SchoolYearDimension.SchoolYearDescription, ChartGroupBy = x.GraduationStatus.GraduationStatus }); return(await _graduationFactService.CreateTrendChart(groupings, model, "Graduation Status")); }
public async Task <PercentageTotalBarChartModel> CreateTrendChart(IQueryable <IGrouping <GraduateTrendGroupByModel, GraduationFact> > groupings, GraduateFilterModel model, string type) { var results = await groupings .Select(x => new { x.Key.ChartGroupBy, x.Key.SchoolYear, x.Key.ExpectedGraduationYear, x.Key.SchoolYearDescription, Total = x.Sum(y => y.GraduationStudentCount) }) .Where(x => x.SchoolYear - x.ExpectedGraduationYear == model.GradCohortYearDifference) .OrderBy(x => x.SchoolYear) .ToListAsync(); var headers = new List <string> { "", type }; headers.AddRange(results.Select(x => x.SchoolYearDescription).Distinct()); var schoolYears = results.Select(x => x.SchoolYear).Distinct().ToList(); var series = results .Select(x => x.ChartGroupBy).Distinct().OrderBy(x => x).ToList(); var total = results.Sum(x => x.Total); var totals = results.GroupBy(x => x.SchoolYear) .OrderBy(x => x.Key) .Select(x => new PercentageTotalDataModel { Percentage = GetPercentage(x.Sum(y => y.Total), total), Total = x.Sum(y => y.Total) }).ToList(); var data = new List <List <PercentageTotalDataModel> >(); foreach (var label in series) { var values = new List <PercentageTotalDataModel>(); foreach (var schoolYear in schoolYears) { var row = results.FirstOrDefault(x => x.ChartGroupBy == label && x.SchoolYear == schoolYear); var rowTotal = row == null ? 0 : row.Total; var schoolYearTotal = results.Where(x => x.SchoolYear == schoolYear).Sum(x => x.Total); values.Add(new PercentageTotalDataModel { Percentage = rowTotal == 0 ? 0 : GetPercentage(rowTotal, schoolYearTotal), Total = rowTotal }); } data.Add(values); } return(new PercentageTotalBarChartModel { Title = type + " Trend", Headers = headers, HidePercentageTotal = true, Labels = results.Select(x => x.SchoolYearDescription).Distinct().ToList(), Series = series, Data = data, ShowChart = true, ShowPercentage = true, TotalRowTitle = type, Totals = totals }); }