public static IList <StandardizedTestStatsViewData> CreateForClass(IList <StudentStandardizedTestInfo> models, IList <StandardizedTestDetails> standardizedTests) { var res = new List <StandardizedTestStatsViewData>(); if (models == null) { return(res); } models = models.Where(x => { decimal a; return(decimal.TryParse(x.Score, out a)); }).OrderBy(x => x.Date).ToList(); foreach (var standardizedTestInfo in models) { var test = res.FirstOrDefault(x => x.StandardizedTest.Id == standardizedTestInfo.StandardizedTestId && x.Component.Id == standardizedTestInfo.StandardizedTestComponentId && x.ScoreType.Id == standardizedTestInfo.StandardizedTestScoreTypeId); if (test != null) { continue; } var stTest = standardizedTests.First(x => x.Id == standardizedTestInfo.StandardizedTestId); var component = stTest.Components.First(x => x.Id == standardizedTestInfo.StandardizedTestComponentId); var scoreType = stTest.ScoreTypes.First(x => x.Id == standardizedTestInfo.StandardizedTestScoreTypeId); var viewData = new StandardizedTestStatsViewData { StandardizedTest = ShortStandardizedTestViewData.Create(stTest), Component = StandardizedTestComponentViewData.Create(component), ScoreType = StandardizedTestScoreTypeViewData.Create(scoreType), DailyStats = new List <DailyStatsViewData>() }; var studentStTestsInfos = models .Where(x => x.StandardizedTestId == standardizedTestInfo.StandardizedTestId && x.StandardizedTestComponentId == standardizedTestInfo.StandardizedTestComponentId && x.StandardizedTestScoreTypeId == standardizedTestInfo.StandardizedTestScoreTypeId) .GroupBy(y => y.Date, x => decimal.Parse(x.Score)); foreach (var studentStTestsInfo in studentStTestsInfos) { var avg = !studentStTestsInfo.Any() ? 0 : decimal.Round(studentStTestsInfo.Average(), 2); viewData.DailyStats.Add(DailyStatsViewData.Create(studentStTestsInfo.Key, avg, "MMM yyyy")); } res.Add(viewData); } return(res); }
public static IList <StandardizedTestStatsViewData> CreateForStudent(int studentId, IList <StudentStandardizedTestInfo> models, IList <StandardizedTestDetails> standardizedTests) { var res = new List <StandardizedTestStatsViewData>(); if (models == null || models.Count == 0) { return(res); } var studentTests = models.Where(x => x.StudentId == studentId).ToList(); //We can draw plots only when we have numeric scores studentTests = studentTests.Where(x => { decimal a; return(decimal.TryParse(x.Score, out a)); }).OrderBy(x => x.Date).ToList(); if (studentTests.Count == 0) { return(res); } studentTests = studentTests.OrderBy(x => x.Date).ToList(); foreach (var test in studentTests) { var currentTest = res.FirstOrDefault(x => x.StandardizedTest.Id == test.StandardizedTestId && x.Component.Id == test.StandardizedTestComponentId && x.ScoreType.Id == test.StandardizedTestScoreTypeId); if (currentTest != null) { continue; } var standardizedTest = standardizedTests.FirstOrDefault(x => x.Id == test.StandardizedTestId); var component = standardizedTest?.Components?.FirstOrDefault(x => x.Id == test.StandardizedTestComponentId); var scoreType = standardizedTest?.ScoreTypes?.FirstOrDefault(x => x.Id == test.StandardizedTestScoreTypeId); var stats = new StandardizedTestStatsViewData { Component = component == null ? null : StandardizedTestComponentViewData.Create(component), StandardizedTest = standardizedTest == null ? null : ShortStandardizedTestViewData.Create(standardizedTest), ScoreType = scoreType == null ? null : StandardizedTestScoreTypeViewData.Create(scoreType), DailyStats = new List <DailyStatsViewData>() }; var studentStTestsInfos = studentTests .Where(x => x.StandardizedTestId == test.StandardizedTestId && x.StandardizedTestComponentId == test.StandardizedTestComponentId && x.StandardizedTestScoreTypeId == test.StandardizedTestScoreTypeId) .GroupBy(y => y.Date, x => decimal.Parse(x.Score)); foreach (var studentStTestsInfo in studentStTestsInfos) { var avg = !studentStTestsInfo.Any() ? 0 : decimal.Round(studentStTestsInfo.Average(), 2); stats.DailyStats.Add(DailyStatsViewData.Create(studentStTestsInfo.Key, avg, "MMM yyyy")); } res.Add(stats); } return(res); }