Beispiel #1
0
        public ActionResult EditIndividualAttendance(int id, int studentId)
        {
            List <Attendance>        attendanceItemsList = this.AttendanceItemsList(id);
            List <Student>           studentList         = this.SingleStudentList(id, studentId);
            IEnumerable <Enrollment> enrollmentList      = this.SingleStudentEnrollmentList(id, studentId);
            Course     course     = this.db.Courses.FirstOrDefault(p => p.CourseID == id);
            List <int> attDayList = AttDayList(course);

            var model = new AttendanceReportViewModel
            {
                AttendanceDays = attDayList,
                Students       = studentList,
                Enrollments    = enrollmentList,
                Attendances    = attendanceItemsList,
                CourseId       = id
            };

            if (course.Completed)
            {
                RedirectToAction("Error");
            }
            else
            {
                return(View(model));
            }

            return(View("Error"));
        }
Beispiel #2
0
        public void Models_AttendanceReportViewModel_Default_Instantiate_Should_Pass()
        {
            // Act
            var result = new AttendanceReportViewModel();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
Beispiel #3
0
        public void Models_AttendanceReportViewModel_Default_Instantiate_Get_Set_Should_Pass()
        {
            //arrange
            var result                   = new AttendanceReportViewModel();
            var expectDate               = DateTime.Today;
            var expectIsSchoolDay        = false;
            var expectTimeIn             = DateTime.UtcNow;
            var expectTimeOut            = DateTime.UtcNow;
            var expectTotalHours         = TimeSpan.Zero;
            var expectTotalHoursExpected = TimeSpan.MaxValue;
            var expectHoursAttended      = TimeSpan.Zero;
            var expectHoursExpected      = TimeSpan.MaxValue;
            var expectPercentAttended    = 10;
            var expectAttendanceStatus   = _5051.Models.Enums.AttendanceStatusEnum.Present;
            var expectCheckInStatus      = _5051.Models.Enums.CheckInStatusEnum.ArriveOnTime;
            var expectCheckOutstatus     = _5051.Models.Enums.CheckOutStatusEnum.DoneEarly;
            var expectEmotion            = _5051.Models.EmotionStatusEnum.Happy;
            var expectEmotionUri         = Emotion.GetEmotionURI(result.Emotion);

            // Act
            result.Date               = expectDate;
            result.IsSchoolDay        = expectIsSchoolDay;
            result.TimeIn             = expectTimeIn;
            result.TimeOut            = expectTimeOut;
            result.TotalHours         = expectTotalHours;
            result.TotalHoursExpected = expectTotalHoursExpected;
            result.HoursAttended      = expectHoursAttended;
            result.HoursExpected      = expectHoursExpected;
            result.PercentAttended    = expectPercentAttended;
            result.AttendanceStatus   = expectAttendanceStatus;
            result.CheckInStatus      = expectCheckInStatus;
            result.CheckOutStatus     = expectCheckOutstatus;
            result.Emotion            = expectEmotion;
            result.EmotionUri         = expectEmotionUri;

            // Assert
            Assert.AreEqual(expectDate, result.Date, TestContext.TestName);
            Assert.AreEqual(expectIsSchoolDay, result.IsSchoolDay, TestContext.TestName);
            Assert.AreEqual(expectTimeIn, result.TimeIn, TestContext.TestName);
            Assert.AreEqual(expectTimeOut, result.TimeOut, TestContext.TestName);
            Assert.AreEqual(expectTotalHours, result.TotalHours, TestContext.TestName);
            Assert.AreEqual(expectTotalHoursExpected, result.TotalHoursExpected, TestContext.TestName);
            Assert.AreEqual(expectHoursAttended, result.HoursAttended, TestContext.TestName);
            Assert.AreEqual(expectHoursExpected, result.HoursExpected, TestContext.TestName);
            Assert.AreEqual(expectPercentAttended, result.PercentAttended, TestContext.TestName);
            Assert.AreEqual(expectAttendanceStatus, result.AttendanceStatus, TestContext.TestName);
            Assert.AreEqual(expectCheckInStatus, result.CheckInStatus, TestContext.TestName);
            Assert.AreEqual(expectCheckOutstatus, result.CheckOutStatus, TestContext.TestName);
            Assert.AreEqual(expectEmotion, result.Emotion, TestContext.TestName);
            Assert.AreEqual(expectEmotionUri, result.EmotionUri, TestContext.TestName);
        }
Beispiel #4
0
        public async Task <ActionResult> Attendance([Bind("From, To, SchoolId, SubjectId")] AttendanceReportViewModel model)
        {
            ViewData["data"]    = "data";
            ViewData["schools"] = await _context.Schools.ToListAsync();

            ViewData["subjects"] = await _context.Subjects.ToListAsync();

            ViewData["students"] = await _context.Students /*.Where(x => x.SchoolId == model.SchoolId)*/.ToListAsync();

            ViewData["attendances"] = await _context.Attendance.Include(x => x.AttendanceDetails)
                                      .Where(x => x.SchoolId == model.SchoolId && x.SubjectId == model.SubjectId &&
                                             x.Date >= model.From && x.Date <= model.To).ToListAsync();

            return(View());
        }
Beispiel #5
0
        public ActionResult StudentDetails(int id)
        {
            //// Generates list of Attendances specifically for current Course
            IQueryable <Attendance> attendanceItems     = this.db.Attendance.Where(s => s.CourseID == id);
            List <Attendance>       attendanceItemsList = attendanceItems.ToList();

            //// End of generating list of Attendances

            //// Generates list of Students (should be one only one student)
            IQueryable <Student> student     = this.db.Students.Where(a => a.UserName == this.User.Identity.Name);
            List <Student>       studentList = student.ToList();

            //// End of generating list of Students

            //// Generates list of AttendingDays specifically for current Course
            Course course     = this.db.Courses.FirstOrDefault(p => p.CourseID == id);
            var    attDayList = new List <int>();

            for (int i = 0; i < course.AttendingDays; i++)
            {
                attDayList.Add(i + 1);
            }

            //// End of generating list of AttendingDays
            Enrollment enrollment =
                this.db.Enrollments.FirstOrDefault(
                    q => q.Student.UserName == this.User.Identity.Name && q.CourseID == id);

            var model = new AttendanceReportViewModel
            {
                AttendanceDays = attDayList,
                Students       = studentList,


                ////should be only one student for this ActionResult
                Attendances             = attendanceItemsList,
                Comments                = enrollment.Comments,
                Paid                    = enrollment.Paid,
                Course                  = course,
                SingleStudentEnrollment = enrollment
            };

            return(View(model));
        }
Beispiel #6
0
        public ActionResult AttendanceView(int id)
        {
            List <Attendance>        attendanceItemsList = this.AttendanceItemsList(id);
            List <Student>           studentList         = this.StudentList(id);
            IEnumerable <Enrollment> enrollmentList      = this.EnrollmentList(id);
            Course     course     = this.db.Courses.FirstOrDefault(p => p.CourseID == id);
            List <int> attDayList = AttDayList(course);

            var model = new AttendanceReportViewModel
            {
                AttendanceDays = attDayList,
                Students       = studentList,
                Enrollments    = enrollmentList,
                Attendances    = attendanceItemsList,
                CourseId       = id,
                Course         = course
            };

            this.ViewBag.CourseName = course.Title;
            return(View(model));
        }
Beispiel #7
0
        //
        public ActionResult AttendanceReport(int id, int?smtID)
        {
            List <RollCall> rollcalls = StuBO.GetRollCallsOfStudent(id);

            //set semestr defaul la 1
            int smID = Convert.ToInt32(smtID);
            AttendanceReportViewModel Model = new AttendanceReportViewModel();

            if (smtID == null)
            {
                ViewBag.SemesterID = slFactory.MakeSelectList <Semester>("SemesterID", "SemesterName", 3);
                Model.RollCallList = rollcalls.Where(r => r.SemesterID == 3).ToList();
            }
            else
            {
                ViewBag.SemesterID = slFactory.MakeSelectList <Semester>("SemesterID", "SemesterName", smID);
                Model.RollCallList = rollcalls.Where(r => r.SemesterID == smtID).ToList();
            }

            Model.Student = StuBO.GetStudentByID(id);
            return(View(Model));
        }
Beispiel #8
0
        /// <summary>
        /// Walk the official school calendar and tally up what is expected
        /// </summary>
        private bool GenerateAttendance(StudentReportViewModel Report)
        {
            DateTime currentDate = new DateTime();

            // Don't go beyond today
            if (Report.DateEnd.CompareTo(DateTime.UtcNow) > 0)
            {
                Report.DateEnd = DateTime.UtcNow;
            }

            // Reset the values to be 0, then add to them.
            Report.Stats.AccumlatedTotalHoursExpected = TimeSpan.Zero;
            Report.Stats.AccumlatedTotalHours         = TimeSpan.Zero;

            currentDate = Report.DateStart;
            while (currentDate.CompareTo(Report.DateEnd) < 0)
            {
                var temp = new AttendanceReportViewModel();
                temp.Date = currentDate;

                var myToday = DataSourceBackend.Instance.SchoolCalendarBackend.ReadDate(currentDate);
                if (myToday == null)
                {
                    return(false);
                }

                temp.HoursExpected = myToday.TimeDuration;

                // Find out if the student attended that day, and add that in.  Because the student can check in/out multiple times add them together.
                var myRange = Report.Student.Attendance.Where(m => m.In.DayOfYear == currentDate.DayOfYear).ToList();
                foreach (var item in myRange)
                {
                    var tempDuration = item.Duration;
                    if (item.Status == StudentStatusEnum.In)
                    {
                        // Todo, refactor this rule based check out to a general location, and then call it when needed to force a checkout.
                        var myItemDefault = DataSourceBackend.Instance.SchoolCalendarBackend.ReadDate(item.In);

                        // If the person is still checked in, and the day is over, then check them out.
                        if (item.In.DayOfYear <= DateTime.UtcNow.DayOfYear && myItemDefault.TimeEnd.Ticks < DateTime.UtcNow.Ticks)
                        {
                            var myDate = item.In.ToShortDateString() + " " + myItemDefault.TimeEnd.ToString();
                            //Add the current date of Item, with the end time for the default date, and return that back as a date time.
                            item.Out      = DateTime.Parse(myDate);
                            item.Status   = StudentStatusEnum.Out;
                            item.Duration = item.Out.Subtract(item.In);

                            // Log the student out as well.
                            Report.Student.Status = StudentStatusEnum.Out;

                            // Update the change for that item be rewriting the student record back to the datastore
                            DataSourceBackend.Instance.StudentBackend.Update(Report.Student);
                        }
                        else
                        {
                            // If the person is still checked in, and it is today, use now and add up till then.
                            tempDuration = DateTime.UtcNow.Subtract(item.In);
                        }
                    }
                    temp.HoursAttended += tempDuration;

                    temp.AttendanceStatus = item.AttendanceStatus;
                    temp.CheckInStatus    = item.CheckInStatus;
                    temp.CheckOutStatus   = item.CheckOutStatus;
                }

                Report.Stats.AccumlatedTotalHoursExpected += temp.HoursExpected;
                Report.Stats.AccumlatedTotalHours         += temp.HoursAttended;

                // Need to add the totals back to the temp, because the temp is new each iteration
                temp.TotalHoursExpected += Report.Stats.AccumlatedTotalHoursExpected;
                temp.TotalHours          = Report.Stats.AccumlatedTotalHours;

                Report.AttendanceList.Add(temp);

                // Look to the next day
                currentDate = currentDate.AddDays(1);
            }

            return(true);
        }
Beispiel #9
0
        /// <summary>
        /// Generate the report from the start date to the end date
        /// </summary>
        /// <param name="report"></param>
        /// <returns></returns>
        private void GenerateReportFromStartToEnd(BaseReportViewModel report)
        {
            var myDateNow = UTCConversionsBackend.UtcToKioskTime(DateTimeHelper.Instance.GetDateTimeNowUTC()).Date; //today's date in kiosk time zone

            // Don't go beyond today
            if (report.DateEnd.CompareTo(myDateNow) > 0)
            {
                report.DateEnd = myDateNow;
            }

            var currentDate = report.DateStart;                    //loop variable

            TimeSpan accumlatedTotalHoursExpected = TimeSpan.Zero; //current accumulated total hours expected
            TimeSpan accumlatedTotalHours         = TimeSpan.Zero; //current accululated total hours attended
            int      emotionLevel = 0;                             //current emotion level

            while (currentDate.CompareTo(report.DateEnd) <= 0)     //loop until last date, include last date
            {
                //create a new AttendanceReportViewmodel for each day
                var temp = new AttendanceReportViewModel
                {
                    Date = currentDate
                };

                // Hold the emotion for the null condition
                temp.EmotionUri = "/content/img/placeholder.png";

                //get today's school calendar model
                var myToday = DataSourceBackend.Instance.SchoolCalendarBackend.ReadDate(currentDate);

                // if the day is not a school day, set IsSchoolDay to false
                if (myToday == null || myToday.SchoolDay == false)
                {
                    temp.IsSchoolDay = false;
                }

                // if the day is a school day, perform calculations
                else
                {
                    temp.HoursExpected = myToday.TimeDuration;

                    // Find out if the student attended that day, and add that in.  Because the student can check in/out multiple times add them together.
                    var myRange = report.Student.Attendance.Where(m => UTCConversionsBackend.UtcToKioskTime(m.In).Date == currentDate.Date).OrderBy(m => m.In).ToList();

                    //if no attendance record on this day, set attendance status to absent
                    if (!myRange.Any())
                    {
                        temp.AttendanceStatus = AttendanceStatusEnum.AbsentUnexcused;
                        report.Stats.DaysAbsentUnexcused++;
                    }
                    else
                    {
                        temp.AttendanceStatus = AttendanceStatusEnum.Present;

                        //set TimeIn to be the first check-in time in the list, so that if there are multiple check-ins,
                        //the TimeIn is set to the first check-in time. Same for emotion.
                        temp.TimeIn     = UTCConversionsBackend.UtcToKioskTime(myRange.First().In);
                        temp.Emotion    = myRange.First().Emotion;
                        temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                        //determine whether is on time or late
                        if (temp.TimeIn.TimeOfDay > myToday.TimeStart)
                        {
                            temp.CheckInStatus = CheckInStatusEnum.ArriveLate;
                        }
                        else
                        {
                            temp.CheckInStatus = CheckInStatusEnum.ArriveOnTime;
                        }

                        // a list containing all intervals in this day
                        List <Interval> intervals = new List <Interval>();

                        //loop through all attendance records in my range
                        foreach (var item in myRange)
                        {
                            TimeSpan timeIn  = UTCConversionsBackend.UtcToKioskTime(item.In).TimeOfDay;
                            TimeSpan timeOut = UTCConversionsBackend.UtcToKioskTime(item.Out).TimeOfDay;
                            Interval inter   = new Interval(timeIn, timeOut);

                            intervals.Add(inter);

                            //update the checkout time for this attendance report view model
                            temp.TimeOut = UTCConversionsBackend.UtcToKioskTime(item.Out);

                            //determine whether left early or not
                            if (temp.TimeOut.TimeOfDay < myToday.TimeEnd)
                            {
                                temp.CheckOutStatus = CheckOutStatusEnum.DoneEarly;
                            }
                            else
                            {
                                temp.CheckOutStatus = CheckOutStatusEnum.DoneAuto;
                            }
                        }

                        report.Stats.DaysPresent++;  //increase number of days present

                        var earlyWindow = SchoolDismissalSettingsBackend.Instance.GetDefault().EarlyWindow;
                        var lateWindow  = SchoolDismissalSettingsBackend.Instance.GetDefault().LateWindow;
                        //the time from which duration starts to count
                        var start = myToday.TimeStart.Add(-earlyWindow);
                        //the time that duration counts until
                        var end = myToday.TimeEnd.Add(lateWindow);

                        //Calculate hours attended on this day
                        temp.HoursAttended = CalculateHoursAttended(intervals, start, end);

                        temp.PercentAttended = (int)(temp.HoursAttended.TotalMinutes * 100 / temp.HoursExpected.TotalMinutes);  //calculate percentage of attended time

                        if (temp.CheckInStatus == CheckInStatusEnum.ArriveLate)
                        {
                            report.Stats.DaysLate++;
                        }

                        report.Stats.DaysOnTime = report.Stats.DaysPresent - report.Stats.DaysLate;

                        if (temp.CheckOutStatus == CheckOutStatusEnum.DoneEarly)
                        {
                            report.Stats.DaysOutEarly++;
                        }

                        report.Stats.DaysOutAuto = report.Stats.DaysPresent - report.Stats.DaysOutEarly;
                    }

                    switch (temp.Emotion)
                    {
                    case EmotionStatusEnum.VeryHappy:
                        temp.EmotionLevel = emotionLevel + 2;
                        report.Stats.DaysVeryHappy++;
                        break;

                    case EmotionStatusEnum.Happy:
                        temp.EmotionLevel = emotionLevel + 1;
                        report.Stats.DaysHappy++;
                        break;

                    case EmotionStatusEnum.Neutral:
                        temp.EmotionLevel = emotionLevel;
                        report.Stats.DaysNeutral++;
                        break;

                    case EmotionStatusEnum.Sad:
                        temp.EmotionLevel = emotionLevel - 1;
                        report.Stats.DaysSad++;
                        break;

                    case EmotionStatusEnum.VerySad:
                        temp.EmotionLevel = emotionLevel - 2;
                        report.Stats.DaysVerySad++;
                        break;

                    default:
                        temp.EmotionLevel = emotionLevel;
                        break;
                    }

                    emotionLevel = temp.EmotionLevel;
                    //calculations for both absent and present records
                    //calculations for both absent and present records
                    report.Stats.NumOfSchoolDays++;
                    accumlatedTotalHoursExpected += temp.HoursExpected;
                    accumlatedTotalHours         += temp.HoursAttended;

                    // Need to add the totals back to the temp, because the temp is new each iteration
                    temp.TotalHoursExpected += accumlatedTotalHoursExpected;
                    temp.TotalHours          = accumlatedTotalHours;
                }

                //add this attendance report to the attendance list
                report.AttendanceList.Add(temp);

                currentDate = currentDate.AddDays(1);
            }

            report.Stats.AccumlatedTotalHoursExpected = accumlatedTotalHoursExpected;
            report.Stats.AccumlatedTotalHours         = accumlatedTotalHours;

            //if there is at least one school days in this report, calculate the following stats
            if (report.Stats.NumOfSchoolDays > 0)
            {
                report.Stats.PercPresent       = (int)Math.Round((double)report.Stats.DaysPresent * 100 / report.Stats.NumOfSchoolDays);
                report.Stats.PercAttendedHours =
                    (int)Math.Round(report.Stats.AccumlatedTotalHours.TotalHours * 100 / report.Stats.AccumlatedTotalHoursExpected.TotalHours);
                report.Stats.PercExcused   = (int)Math.Round((double)report.Stats.DaysAbsentExcused * 100 / report.Stats.NumOfSchoolDays);
                report.Stats.PercUnexcused = (int)Math.Round((double)report.Stats.DaysAbsentUnexcused * 100 / report.Stats.NumOfSchoolDays);
                if (report.Stats.DaysPresent > 0)
                {
                    report.Stats.PercInLate   = (int)Math.Round((double)report.Stats.DaysLate * 100 / report.Stats.DaysPresent);
                    report.Stats.PercOutEarly = (int)Math.Round((double)report.Stats.DaysOutEarly * 100 / report.Stats.DaysPresent);
                }
            }

            //set the attendance goal percent according to school dismissal settings
            report.Goal = SchoolDismissalSettingsBackend.Instance.GetDefault().Goal;

            //set the date array, ideal value array and actual value array for line chart
            report.YearArray    = @String.Join(", ", report.AttendanceList.Where(m => m.IsSchoolDay).ToList().Select(m => m.Date.Year.ToString()).ToArray());
            report.MonthArray   = @String.Join(", ", report.AttendanceList.Where(m => m.IsSchoolDay).ToList().Select(m => m.Date.Month.ToString()).ToArray());
            report.DayArray     = @String.Join(", ", report.AttendanceList.Where(m => m.IsSchoolDay).ToList().Select(m => m.Date.Day.ToString()).ToArray());
            report.ActualValues = @String.Join(", ",
                                               report.AttendanceList.Where(m => m.IsSchoolDay).ToList()
                                               .Select(m => m.TotalHours.TotalHours.ToString("0.#")).ToArray());
            report.PerfectValues = @String.Join(", ",
                                                report.AttendanceList.Where(m => m.IsSchoolDay).ToList()
                                                .Select(m => m.TotalHoursExpected.TotalHours.ToString("0.#")).ToArray());
            report.GoalValues = @String.Join(", ",
                                             report.AttendanceList.Where(m => m.IsSchoolDay).ToList()
                                             .Select(m => (m.TotalHoursExpected.TotalHours * (report.Goal) / 100).ToString("0.#")).ToArray());
            report.EmotionLevelValues = @String.Join(", ",
                                                     report.AttendanceList.Where(m => m.IsSchoolDay).Select(m => m.EmotionLevel).ToArray());
        }