public static ClassPanoramaViewData Create(ClassDetails cClass, IList <StandardizedTestDetails> standardizedTests, ClassPanorama panorama, IList <GradingScaleRange> gradingScaleRanges, IList <StudentDetailsInfo> classStudents, IList <int> selectedStudents, DateTime today) { var res = new ClassPanoramaViewData(cClass) { StandardizedTests = standardizedTests.Select(x => StandardizedTestViewData.Create(x, x.Components, x.ScoreTypes)).ToList(), ClassDistributionSection = ClassDistributionSectionViewData.Create(panorama.Grades, panorama.Absences, panorama.Infractions, gradingScaleRanges), StandardizedTestsStatsByClass = StandardizedTestStatsViewData.CreateForClass(panorama.StandardizedTests, standardizedTests), Students = new List <StudentStandardizedTestStats>() }; classStudents = classStudents.OrderBy(x => x.FullName()).ToList(); //Preparing students foreach (var student in classStudents) { var studentStats = StandardizedTestStatsViewData.CreateForStudent(student.Id, panorama.StandardizedTests, standardizedTests); var gradeAvg = panorama.Grades?.FirstOrDefault(x => x.StudentId == student.Id)?.AverageGrade; var infractions = panorama.Infractions?.FirstOrDefault(x => x.StudentId == student.Id)?.NumberOfInfractions; var absences = panorama.Absences?.FirstOrDefault(x => x.StudentId == student.Id); res.Students.Add(StudentStandardizedTestStats.Create(student, gradeAvg, absences, infractions, studentStats)); } if (selectedStudents == null || selectedStudents.Count == 0) { return(res); } var selected = panorama.StandardizedTests?.Where(x => selectedStudents.Contains(x.StudentId)); res.SelectStandardizedTestsStats = StandardizedTestStatsViewData.CreateForClass(selected?.ToList(), standardizedTests); return(res); }
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 StudentPanoramaViewData Create(int studentId, StudentPanoramaInfo panorama, StudentProfilePanoramaSetting settings, IList <StandardizedTestDetails> tests) { return(new StudentPanoramaViewData { StandardizedTestsStats = StandardizedTestStatsViewData.CreateForStudent(studentId, panorama.StandardizedTests, tests), Absences = panorama.DailyAbsences?.Select(StudentDailyAbsenceViewData.Create).OrderBy(x => x.Date).ToList(), DisciplineStats = panorama.Infractions?.Select(StudentInfractionViewData.Create).OrderBy(x => x.OccurrenceDate).ToList(), AttendanceStats = BuildAttendanceStats(panorama.DailyAbsences, panorama.AllSchoolDays), DailyDisciplineStats = BuildDisciplineStats(panorama.Infractions, panorama.AllSchoolDays), FilterSettings = settings, StandardizedTests = tests.Select(x => StandardizedTestViewData.Create(x, x.Components, x.ScoreTypes)).ToList(), Calendars = StudentPanoramaCalendarViewData.Create(panorama.DailyAbsences, panorama.Infractions, panorama.AllSchoolDays, panorama.SchoolYears) }); }
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); }