public void Models_AttendanceModel_Default_Instantiate_Get_Set_Should_Pass()
        {
            //arrange
            var result          = new AttendanceModel();
            var expectStudentId = "GoodID1";
            var expectIn        = DateTime.UtcNow;
            var expectOut       = DateTime.UtcNow;
            //var expectStatus = _5051.Models.StudentStatusEnum.In;
            //var expectDuration = TimeSpan.Zero;
            var expectedIsNew    = false;
            var expectEmotion    = _5051.Models.EmotionStatusEnum.Neutral;
            var expectEmotionUri = Emotion.GetEmotionURI(expectEmotion);

            // Act
            result.StudentId = expectStudentId;
            result.In        = expectIn;
            result.Out       = expectOut;
            //result.Status = expectStatus;
            result.IsNew      = expectedIsNew;
            result.Emotion    = expectEmotion;
            result.EmotionUri = expectEmotionUri;

            // Assert
            Assert.IsNotNull(result.Id, TestContext.TestName);
            Assert.AreEqual(expectStudentId, result.StudentId, TestContext.TestName);
            Assert.AreEqual(expectIn, result.In, TestContext.TestName);
            Assert.AreEqual(expectOut, result.Out, TestContext.TestName);
            //Assert.AreEqual(expectStatus, result.Status, TestContext.TestName);
            Assert.AreEqual(expectEmotion, result.Emotion, TestContext.TestName);
            Assert.AreEqual(expectEmotionUri, result.EmotionUri, TestContext.TestName);

            Assert.AreEqual(expectedIsNew, result.IsNew, TestContext.TestName);
        }
Exemple #2
0
        public ActionResult Create([Bind(Include =
                                             "Id," +
                                             "StudentId," +
                                             "In," +
                                             "Out," +
                                             "Emotion," +
                                             "IsNew," +
                                             "")] AttendanceModel data)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(data.Id))
            {
                // Send back for edit
                return(View(data));
            }

            //create a new attendance using the data
            var myAttendance = new AttendanceModel
            {
                StudentId = data.StudentId,
                //update the time
                In         = UTCConversionsBackend.KioskTimeToUtc(data.In),
                Out        = UTCConversionsBackend.KioskTimeToUtc(data.Out),
                Emotion    = data.Emotion,
                EmotionUri = Emotion.GetEmotionURI(data.Emotion),

                IsNew = data.IsNew
            };

            //add the attendance to the student's attendance
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(myAttendance.StudentId);

            myStudent.Attendance.Add(myAttendance);
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);

            return(RedirectToAction("Read", new { id = myAttendance.StudentId }));
        }
        public void Models_Emotion_GetEmotionUri_Values_Should_Pass()
        {
            // Assert

            // Make sure there are no additional values
            var enumValues = EmotionStatusEnum.GetValues(typeof(EmotionStatusEnum)).Cast <EmotionStatusEnum>();

            foreach (var item in enumValues)
            {
                var expect = Emotion.GetEmotionURI(item);
                Assert.IsNotNull(expect, TestContext.TestName);
            }
        }
Exemple #4
0
        /// <summary>
        /// AttendanceUpdate Page
        /// </summary>
        /// <param name="id">Attendance Id</param>
        /// <returns>Attendance Record as a Attendance Model</returns>
        // GET: Portal

        public ActionResult AttendanceUpdate(string id, string item)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            // Todo: Remove when identity is fully hooked up
            // Hack, to keep the current system working, while the identity system is slowly hooked up everywhere.  If the user is not logged in, then the passed in user will work, if the user is logged in, then the passed in user is ignored.
            if (string.IsNullOrEmpty(CurrentId))
            {
                CurrentId = id;
            }

            ViewBag.StudentId = CurrentId;  //TODO: Remove this when identity is fully hooked up

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.StudentUser))
            {
                return(RedirectToAction("Roster", "Portal"));
            }

            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(item))
            {
                return(RedirectToAction("Error", "Home"));
            }

            //get the attendance with given id
            var myAttendance = DataSourceBackend.Instance.StudentBackend.ReadAttendance(CurrentId, item);

            if (myAttendance == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            //Create a new attendance to hold converted times
            var myReturn = new AttendanceModel
            {
                StudentId  = myAttendance.StudentId,
                Id         = myAttendance.Id,
                In         = UTCConversionsBackend.UtcToKioskTime(myAttendance.In),
                Out        = UTCConversionsBackend.UtcToKioskTime(myAttendance.Out),
                Emotion    = myAttendance.Emotion,
                EmotionUri = Emotion.GetEmotionURI(myAttendance.Emotion),

                IsNew = myAttendance.IsNew
            };

            return(View(myReturn));
        }
Exemple #5
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);
        }
Exemple #6
0
        public ActionResult AttendanceUpdate([Bind(Include =
                                                       "Id," +
                                                       "StudentId," +
                                                       "Emotion," +
                                                       "EmotionUri," +
                                                       "")] AttendanceModel data)
        {
            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            // The emotionURI is passed in as the AttendanceID because of conflicts with the model, it is then converted
            if (string.IsNullOrEmpty(data.EmotionUri))
            {
                // Send back for edit
                return(View(data));
            }
            data.Id = data.EmotionUri;  //copy the ID back to Data.Id

            if (string.IsNullOrEmpty(data.StudentId))
            {
                return(View(data));
            }

            //get the attendance with given id
            var myAttendance = DataSourceBackend.Instance.StudentBackend.ReadAttendance(data.StudentId, data.Id);

            if (myAttendance == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            //update the emotion
            myAttendance.Emotion    = data.Emotion;
            myAttendance.EmotionUri = Emotion.GetEmotionURI(myAttendance.Emotion);
            DataSourceBackend.Instance.StudentBackend.UpdateAttendance(myAttendance);

            return(RedirectToAction("Attendance", new { id = myAttendance.StudentId, item = myAttendance.Id }));
        }
Exemple #7
0
        // GET: Attendance/Read/. Read the attendance history of the student
        public ActionResult Read(string id)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(id);

            if (myStudent == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var myReturn = new StudentDisplayViewModel(myStudent);

            var attendanceListOrdered = myReturn.Attendance.OrderByDescending(m => m.In);

            //Deep copy Attendance list and convert time zone
            var myAttendanceModels = new List <AttendanceModel>();

            foreach (var item in attendanceListOrdered)
            {
                var myAttendance = new AttendanceModel()
                {
                    //deep copy the AttendanceModel and convert time zone
                    In         = UTCConversionsBackend.UtcToKioskTime(item.In),
                    Out        = UTCConversionsBackend.UtcToKioskTime(item.Out),
                    Id         = item.Id,
                    StudentId  = myStudent.Id,
                    Emotion    = item.Emotion,
                    EmotionUri = Emotion.GetEmotionURI(item.Emotion)
                };

                myAttendance.Id = item.Id;

                myAttendanceModels.Add(myAttendance);
            }

            myReturn.Attendance = myAttendanceModels;

            return(View(myReturn));
        }
Exemple #8
0
        // GET: Attendance/Detail
        // Read the details of the attendance(time in, time out).
        public ActionResult Details(string id, string item)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (string.IsNullOrEmpty(id))
            {
                return(RedirectToAction("Error", "Home"));
            }

            if (string.IsNullOrEmpty(item))
            {
                return(RedirectToAction("Error", "Home"));
            }

            //get the attendance with given id
            var myAttendance = DataSourceBackend.Instance.StudentBackend.ReadAttendance(id, item);

            if (myAttendance == null)
            {
                return(RedirectToAction("Error", "Home"));
            }

            //Create a new attendance to hold converted times
            var myReturn = new AttendanceModel
            {
                StudentId  = myAttendance.StudentId,
                Id         = myAttendance.Id,
                In         = UTCConversionsBackend.UtcToKioskTime(myAttendance.In),
                Out        = UTCConversionsBackend.UtcToKioskTime(myAttendance.Out),
                Emotion    = myAttendance.Emotion,
                EmotionUri = Emotion.GetEmotionURI(myAttendance.Emotion),

                IsNew = myAttendance.IsNew
            };

            return(View(myReturn));
        }
Exemple #9
0
        /// <summary>
        /// Attendance Page
        /// </summary>
        /// <param name="id">Student Id</param>
        /// <returns>Student Record as a Student View Model</returns>
        // GET: Portal
        public ActionResult Attendance(string id = null)
        {
            // Temp hold the Student Id for the Nav, until the Nav can call for Identity.
            //ViewBag.StudentId = id;

            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            // Todo: Remove when identity is fully hooked up
            // Hack, to keep the current system working, while the identity system is slowly hooked up everywhere.  If the user is not logged in, then the passed in user will work, if the user is logged in, then the passed in user is ignored.
            if (string.IsNullOrEmpty(CurrentId))
            {
                CurrentId = id;
            }

            ViewBag.StudentId = CurrentId;  //TODO: Remove this when identity is fully hooked up

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.StudentUser))
            {
                return(RedirectToAction("Roster", "Portal"));
            }

            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(CurrentId);

            if (myStudent == null)
            {
                return(RedirectToAction("Roster", "Portal"));
            }

            var myReturn = new StudentDisplayViewModel(myStudent);

            var attendanceListOrdered = myReturn.Attendance.OrderByDescending(m => m.In);

            //Set the last log in time and emotion status img uri
            if (attendanceListOrdered.Any())
            {
                myReturn.LastLogIn = UTCConversionsBackend.UtcToKioskTime(attendanceListOrdered.FirstOrDefault().In);
            }

            //Deep copy Attendance list and convert time zone
            var myAttendanceModels = new List <AttendanceModel>();

            foreach (var item in attendanceListOrdered)
            {
                var myAttendance = new AttendanceModel()
                {
                    //deep copy the AttendanceModel and convert time zone
                    In         = UTCConversionsBackend.UtcToKioskTime(item.In),
                    Out        = UTCConversionsBackend.UtcToKioskTime(item.Out),
                    Id         = item.Id,
                    StudentId  = myStudent.Id,
                    Emotion    = item.Emotion,
                    EmotionUri = Emotion.GetEmotionURI(item.Emotion)
                };

                myAttendance.Id = item.Id;

                myAttendanceModels.Add(myAttendance);
            }

            myReturn.Attendance = myAttendanceModels;

            return(View(myReturn));
        }
Exemple #10
0
        public ActionResult Update([Bind(Include =
                                             "Id," +
                                             "StudentId," +
                                             "In," +
                                             "Out," +
                                             "Emotion," +
                                             "IsNew," +
                                             "EmotionUri," +
                                             "")] AttendanceModel data)
        {
            var CurrentId = DataSourceBackend.Instance.IdentityBackend.GetCurrentStudentID(HttpContext);

            if (DataSourceBackend.Instance.IdentityBackend.BlockExecptForRole(CurrentId, UserRoleEnum.TeacherUser))
            {
                return(RedirectToAction("Login", "Admin"));
            }

            if (!ModelState.IsValid)
            {
                // Send back for edit
                return(View(data));
            }

            if (data == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            // The emotionURI is passed in as the AttendanceID because of conflicts with the model, it is then converted
            if (string.IsNullOrEmpty(data.EmotionUri))
            {
                // Send back for edit
                return(View(data));
            }
            data.Id = data.EmotionUri;  //copy the ID back to Data.Id

            if (string.IsNullOrEmpty(data.StudentId))
            {
                return(View(data));
            }

            //get the attendance with given id
            var myAttendance = DataSourceBackend.Instance.StudentBackend.ReadAttendance(data.StudentId, data.Id);

            if (myAttendance == null)
            {
                // Send to Error Page
                return(RedirectToAction("Error", "Home"));
            }

            //update the time
            myAttendance.In  = UTCConversionsBackend.KioskTimeToUtc(data.In);
            myAttendance.Out = UTCConversionsBackend.KioskTimeToUtc(data.Out);

            //update the emotion
            myAttendance.Emotion    = data.Emotion;
            myAttendance.EmotionUri = Emotion.GetEmotionURI(myAttendance.Emotion);
            DataSourceBackend.Instance.StudentBackend.UpdateAttendance(myAttendance);

            return(RedirectToAction("Details", new { id = myAttendance.StudentId, item = myAttendance.Id }));
        }
Exemple #11
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());
        }
Exemple #12
0
        /// <summary>
        /// Generate attendance records for student of given name from the start date to the end date
        /// </summary>
        /// <param name="index">The index of the student in studentBackend index</param>
        /// <param name="dateStart"></param>
        /// <param name="dateEnd"></param>
        private static void GenerateAttendance(string studentId, int StudentType, DateTime dateStart, DateTime dateEnd)
        {
            var myStudent = DataSourceBackend.Instance.StudentBackend.Read(studentId);

            // Set current date to be 1 less than the start day, because will get added in the for loop
            DateTime currentDate = dateStart;

            //To generate random numbers, since seed is fixed, the numbers generated will be same in every run
            Random r = new Random(0);

            while (currentDate.CompareTo(dateEnd) < 0)
            {
                // Create an attendance model for this student
                var temp = new AttendanceModel
                {
                    StudentId = myStudent.Id,
                    //Status = StudentStatusEnum.Out
                };

                // Get the school day info for current date
                var myToday = DataSourceBackend.Instance.SchoolCalendarBackend.ReadDate(currentDate);

                // if the day is a school day
                if (myToday.SchoolDay)
                {
                    //generate a random number 0-4 inclusive, use this to randomly generate 5 scenarios
                    int rn = r.Next(0, 5);

                    switch (StudentType)
                    {
                    case 0:     //Perfect
                        temp.In         = InGood(currentDate, r);
                        temp.Out        = OutAuto(currentDate);
                        temp.Emotion    = (EmotionStatusEnum)(rn + 1);
                        temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                        myStudent.Attendance.Add(temp);
                        break;

                    case 1:     //Good
                    {
                        switch (rn)
                        {
                        case 0:
                            temp.In         = InLate(currentDate, r);
                            temp.Out        = OutLate(currentDate);
                            temp.Emotion    = EmotionStatusEnum.Happy;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        case 1:
                            temp.In         = InGood(currentDate, r);
                            temp.Out        = OutEarly(currentDate, r);
                            temp.Emotion    = EmotionStatusEnum.Sad;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        default:
                            temp.In         = InGood(currentDate, r);
                            temp.Out        = OutAuto(currentDate);
                            temp.Emotion    = EmotionStatusEnum.VeryHappy;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;
                        }
                    }
                    break;

                    case 2:     //Average
                    {
                        switch (rn)
                        {
                        case 0:
                            temp.In         = InLate(currentDate, r);
                            temp.Out        = OutEarly(currentDate, r);
                            temp.Emotion    = EmotionStatusEnum.Happy;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        case 1:
                            break;

                        case 2:
                            temp.In         = InLate(currentDate, r);
                            temp.Out        = OutAuto(currentDate);
                            temp.Emotion    = EmotionStatusEnum.Neutral;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        case 3:
                            temp.In         = InLate(currentDate, r);
                            temp.Out        = OutAuto(currentDate);
                            temp.Emotion    = EmotionStatusEnum.Sad;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        default:
                            temp.In         = InGood(currentDate, r);
                            temp.Out        = OutAuto(currentDate);
                            temp.Emotion    = EmotionStatusEnum.VeryHappy;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;
                        }
                    }
                    break;

                    case 3:     //Bad
                    {
                        switch (rn)
                        {
                        case 0:
                            temp.In         = InVeryLate(currentDate, r);
                            temp.Out        = OutAuto(currentDate);
                            temp.Emotion    = EmotionStatusEnum.Neutral;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        case 1:
                            temp.In         = InLate(currentDate, r);
                            temp.Out        = OutEarly(currentDate, r);
                            temp.Emotion    = EmotionStatusEnum.VerySad;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;

                        case 2:
                            temp.In         = InLate(currentDate, r);
                            temp.Out        = OutAuto(currentDate);
                            temp.Emotion    = EmotionStatusEnum.Sad;
                            temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                            myStudent.Attendance.Add(temp);
                            break;
                        }
                    }
                    break;

                    case 4:     //None
                        break;
                    }
                }

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

            // Update the data
            DataSourceBackend.Instance.StudentBackend.Update(myStudent);
        }