public async Task <BarChartModel <int> > ByEnglishLanguageLearner(AssessmentTrendFilterModel model)
        {
            var groupings = BaseQuery(model)
                            .GroupBy(x => new AssessmentScoreTrendGroupBy
            {
                SchoolYearKey         = x.SchoolYearKey,
                SchoolYearDescription = x.SchoolYearDimension.SchoolYearDescription,
                ScoreResult           = x.Performance.ScoreResult,
                GroupByProperty       = x.Demographic.EnglishLanguageLearnerStatus
            });

            return(await CreateChart(groupings, "English Language Learner"));
        }
        public async Task <BarChartModel <int> > Get(AssessmentTrendFilterModel model)
        {
            var query = BaseQuery(model);

            var results = await query.GroupBy(x => new { x.Performance.ScoreResult, x.SchoolYearKey, x.SchoolYearDimension.SchoolYearDescription })
                          .Select(x => new
            {
                ScoreResult           = x.Key.ScoreResult.HasValue ? x.Key.ScoreResult.Value : 0,
                SchoolYearDescription = x.Key.SchoolYearDescription,
                SchoolYear            = x.Key.SchoolYearKey,
                Total = x.Sum(y => y.AssessmentStudentCount)
            })
                          .ToListAsync();

            var schoolYears            = results.Select(x => x.SchoolYear).Distinct().OrderBy(x => x).ToList();
            var schoolYearDescriptions = results.Select(x => new { y = x.SchoolYear, d = x.SchoolYearDescription }).Distinct().OrderBy(x => x.y).Select(x => x.d).ToList();

            var data = new List <int>();

            foreach (var year in schoolYears)
            {
                var resultTotal       = results.Where(x => x.SchoolYear == year).Sum(x => x.ScoreResult * x.Total);
                var totalParticipants = results.Where(x => x.SchoolYear == year).Sum(x => x.Total);

                var averageScore = (totalParticipants == 0) ? 0 : resultTotal / totalParticipants;
                data.Add(averageScore);
            }

            var headers = new List <string> {
                "", "Assessment"
            };

            headers.AddRange(schoolYearDescriptions);

            return(new BarChartModel <int>
            {
                Title = "Average Score Trend",
                Headers = headers,
                Labels = schoolYearDescriptions,
                Series = new List <string> {
                    model.AssessmentTitle
                },
                Data = new List <List <int> > {
                    data
                },
                ShowChart = true,
                HideTotal = true,
            });
        }
        private IQueryable <AssessmentFact> BaseQuery(AssessmentTrendFilterModel model)
        {
            var query = _assessmentRepository
                        .GetAll()
                        .Where(x => x.Performance.ScoreResult != null);

            if (model.SchoolYears != null && model.SchoolYears.Any())
            {
                query = query.Where(x => model.SchoolYears.Contains(x.SchoolYearKey));
            }

            if (model.Assessments != null && model.Assessments.Any())
            {
                query = query.Where(x => model.Assessments.Contains(x.AssessmentKey));
            }
            else
            {
                query = query.Where(x => x.Assessment.AssessmentTitle == model.AssessmentTitle && x.Assessment.AcademicSubject == model.Subject);
            }

            if (model.EnglishLanguageLearnerStatuses != null && model.EnglishLanguageLearnerStatuses.Any())
            {
                query = query.Where(x => model.EnglishLanguageLearnerStatuses.Contains(x.Demographic.EnglishLanguageLearnerStatus));
            }

            if (model.Ethnicities != null && model.Ethnicities.Any())
            {
                query = query.Where(x => model.Ethnicities.Contains(x.Demographic.Ethnicity));
            }

            if (model.LunchStatuses != null && model.LunchStatuses.Any())
            {
                query = query.Where(x => model.LunchStatuses.Contains(x.Demographic.FreeReducedLunchStatus));
            }

            if (model.SpecialEducationStatuses != null && model.SpecialEducationStatuses.Any())
            {
                query = query.Where(x => model.SpecialEducationStatuses.Contains(x.Demographic.SpecialEducationStatus));
            }

            return(query);
        }
        public async Task <IHttpActionResult> BySpecialEducation(AssessmentTrendFilterModel model)
        {
            var chart = await _assessmentScoreTrendService.BySpecialEducation(model);

            return(Ok(chart));
        }
        public async Task <IHttpActionResult> ByLunchStatus(AssessmentTrendFilterModel model)
        {
            var chart = await _assessmentScoreTrendService.ByLunchStatus(model);

            return(Ok(chart));
        }
        public async Task <IHttpActionResult> ByEnglishLanguageLearner(AssessmentTrendFilterModel model)
        {
            var chart = await _assessmentScoreTrendService.ByEnglishLanguageLearner(model);

            return(Ok(chart));
        }