Example #1
0
        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);
        }
Example #2
0
        private static IList <DailyStatsViewData> BuildDisciplineStats(IList <StudentInfractionInfo> studentInfractions, IList <Date> allSchoolDays)
        {
            var res = new List <DailyStatsViewData>();

            foreach (var day in allSchoolDays.Select(d => d.Day))
            {
                var infractionsCount = studentInfractions?.Count(x => x.OccurrenceDate == day.Date) ?? 0;
                res.Add(DailyStatsViewData.Create(day.Date, infractionsCount, "MMM yyyy"));
            }
            return(res);
        }
Example #3
0
        public IList <DailyStatsViewData> BuildDailyStats(IDictionary <DateTime, decimal> dailyStats, DateTime startDate, DateTime endDate)
        {
            var currentDate = startDate.Date;
            var res         = new List <DailyStatsViewData>();

            while (currentDate <= endDate)
            {
                if (dailyStats.ContainsKey(currentDate))
                {
                    var sum = dailyStats[currentDate];
                    res.Add(DailyStatsViewData.Create(currentDate, sum, dateFormat));
                }
                currentDate = currentDate.AddDays(1).Date;
            }
            return(res);
        }
Example #4
0
        public IList <DailyStatsViewData> BuildDailyStats(IDictionary <DateTime, decimal> dailyStats, DateTime startDate, DateTime endDate)
        {
            string  dateFormat  = "MMM";
            var     res         = new List <DailyStatsViewData>();
            var     currentDate = startDate.Date;
            decimal sum         = 0;

            while (currentDate <= endDate.Date)
            {
                sum += dailyStats.ContainsKey(currentDate) ? dailyStats[currentDate] : 0;
                if (currentDate.AddDays(-1).Month != currentDate.Month || currentDate == endDate.Date)
                {
                    res.Add(DailyStatsViewData.Create(currentDate.AddDays(-1), sum, dateFormat));
                    sum = 0;
                }
                currentDate = currentDate.AddDays(1).Date;
            }
            return(res);
        }
Example #5
0
        private static IList <DailyStatsViewData> BuildAttendanceStats(IList <StudentAbsenceInfo> absences, IList <Date> allSchoolDays)
        {
            var res = new List <DailyStatsViewData>();

            foreach (var day in allSchoolDays.Select(x => x.Day))
            {
                var     absent = absences?.FirstOrDefault(x => x.Date == day.Date);
                decimal number = 1;
                if (absent?.AbsenceLevel == "All Day")
                {
                    number = 0;
                }
                if (absent?.AbsenceLevel == "Half Day")
                {
                    number = 0.5m;
                }
                res.Add(DailyStatsViewData.Create(day.Date, number, "MMM yyyy"));
            }
            return(res);
        }
Example #6
0
        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);
        }