Exemplo n.º 1
0
        public ActionResult PerformanceReport(int semesterId)
        {
            Semester semester = _semesterService.GetSemester(semesterId);
            List <PerformanceReportModel> performanceReports = new List <PerformanceReportModel>();

            if (semester == null)
            {
                // return empty list
                return(Ok(performanceReports));
            }

            List <Class> classes = _classService.GetClasses(null, null, semester.Year, null, null, null).ToList();

            // List<Student> students = _studentService.GetStudents(null, null, null, semester.Year, null).ToList();

            // if no student found
            if (classes.Count == 0)
            {
                return(Ok(performanceReports));
            }

            List <Student>         students          = new List <Student>();
            List <ReportModel>     semesterReports   = new List <ReportModel>();
            List <Subject>         subjects          = _subjectService.GetSubjects(null, null).ToList();
            PerformanceReportModel performanceReport = new PerformanceReportModel();
            int numOfSubject = subjects.Count;



            foreach (var aClass in classes)
            {
                performanceReport        = new PerformanceReportModel();
                performanceReport.aClass = aClass;
                semesterReports          = new List <ReportModel>();

                students = _studentService.GetStudents(null, null, aClass.ClassID, null, null).ToList();
                if (students.Count != 0)
                {
                    semesterReports = RenderSemesterReport(semesterReports, students, subjects, semesterId, numOfSubject);
                }

                performanceReport = _reportService.PercentagePerformance(performanceReport, semesterReports, "A");
                performanceReport = _reportService.PercentagePerformance(performanceReport, semesterReports, "B");
                performanceReport = _reportService.PercentagePerformance(performanceReport, semesterReports, "C");
                performanceReport = _reportService.PercentagePerformance(performanceReport, semesterReports, "D");
                performanceReport = _reportService.PercentagePerformance(performanceReport, semesterReports, "F");

                performanceReports.Add(performanceReport);
            }

            return(Ok(performanceReports));
        }
        public PerformanceReportModel PercentagePerformance(PerformanceReportModel performanceReport, List <ReportModel> reports, string performance)
        {
            Percentage percentage = new Percentage();
            double     classSize  = reports.Count;

            if (classSize == 0)
            {
                percentage.performance = performance;
                percentage.percent     = 0;

                performanceReport.classSize = (int)classSize;
                performanceReport.percentages.Add(percentage);

                return(performanceReport);
            }

            double performanceCount = 0;

            foreach (var r in reports)
            {
                if (!string.IsNullOrEmpty(r.performance))
                {
                    if (r.performance.Equals(performance))
                    {
                        performanceCount++;
                    }
                }
            }

            percentage.performance = performance;
            percentage.percent     = Math.Round(performanceCount / classSize, 2);

            performanceReport.classSize = (int)classSize;
            performanceReport.percentages.Add(percentage);

            return(performanceReport);
        }