public ActionResult CheckAttendanceManual(CheckAttendanceManualBindModel Model)
        {
            AttendanceBusiness AttendanceBO = new AttendanceBusiness();

            AttendanceBO.WriteAttendanceManualLog(Model.Username, Model.RollCallID, Model.Date, Model.AttendanceChecks);

            return(Json(new { message = "Success" }));
        }
        public ActionResult GetRollCallInfo(int RollCallID)
        {
            RollCallBusiness RollBO   = new RollCallBusiness();
            RollCall         rollcall = RollBO.GetRollCallByID(RollCallID);

            AttendanceBusiness AttenBO = new AttendanceBusiness();
            var AttendLog = AttenBO.GetRollCallAttendanceLog(RollCallID);

            var ReturnLog = AttendLog.Where(log => log.LogDate >= DateTime.Today.AddDays(-1)).ToList();//.OrderByDescending(log => log.LogDate);

            //Truong hop hom nay la thu 2
            if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
            {
                //Tim log thu 6 hoac thu 7
                DateTime LastSaturday    = DateTime.Today.AddDays(-2);
                var      LastSaturdayLog = AttendLog.FirstOrDefault(log => log.LogDate == LastSaturday);
                if (LastSaturdayLog != null)
                {
                    ReturnLog.Add(LastSaturdayLog);
                }
                else
                {
                    DateTime LastFriday    = DateTime.Today.AddDays(-3);
                    var      LastFridayLog = AttendLog.FirstOrDefault(log => log.LogDate == LastFriday);
                    if (LastFridayLog != null)
                    {
                        ReturnLog.Add(LastFridayLog);
                    }
                }
            }

            var RollJson = new
            {
                rollID  = rollcall.RollCallID,
                subject = rollcall.Subject.FullName,
                classes = rollcall.Class.ClassName,
                time    = rollcall.StartTime.ToString(@"hh\:mm") + " - " + rollcall.EndTime.ToString(@"hh\:mm"),
                date    = rollcall.BeginDate.ToString("dd-MM-yyyy") + " to " + rollcall.EndDate.ToString("dd-MM-yyyy"),

                studentList = rollcall.Students.Select(st => new
                {
                    studentID   = st.StudentID,
                    studentCode = st.StudentCode,
                    studentName = st.FullName,
                    percentRate = String.Format("{0:0.00}%", AttenBO.GetStudentAbsentRate(st.StudentID, RollCallID))
                }),
                logList = ReturnLog.OrderByDescending(log => log.LogDate).Select(log => new
                {
                    rollID     = log.RollCallID,
                    logID      = log.LogID,
                    logDate    = log.LogDate.ToString("dd-MM-yyyy"),
                    logPresent = log.StudentAttendances.Count(attend => attend.IsPresent) + "/" + log.RollCall.Students.Count,
                }),
            };

            return(Json(RollJson, JsonRequestBehavior.AllowGet));
        }
        public ActionResult RollCallDetail(int id)
        {
            RollCall RollCall = RollBO.GetRollCallByID(id);

            //Lay danh sach nhung log cua roll call nay, tu luc bat dau
            AttendanceBusiness   AttenBO        = new AttendanceBusiness();
            List <AttendanceLog> AttendanceLogs = AttenBO.GetRollCallAttendanceLog(id);

            RollCallDetailViewModel Model = new RollCallDetailViewModel();

            Model.RollCall     = RollCall;
            Model.RollCallLogs = AttendanceLogs;

            return(View(Model));
        }
        // GET: /RollCall/Details/5

        //view attendance roll call
        public ViewResult ViewAttendance(int RollCallID)
        {
            RollCall RollCall = RollBO.GetRollCallByID(RollCallID);

            AttendanceBusiness AttendanceBO = new AttendanceBusiness();
            //Lay danh sach nhung log cua roll call nay, tu luc bat dau
            List <AttendanceLog> AttendanceLogs = AttendanceBO.GetRollCallAttendanceLog(RollCallID);


            RollCallDetailViewModel Model = new RollCallDetailViewModel();

            Model.RollCall     = RollCall;
            Model.RollCallLogs = AttendanceLogs;

            return(View(Model));
        }
        public ActionResult CheckAttendanceManual(CheckAttendanceManualBindModel Model)
        {
            AttendanceBusiness AttendanceBO = new AttendanceBusiness();

            AttendanceBO.WriteAttendanceManualLog(Model.Username, Model.RollCallID, Model.Date, Model.AttendanceChecks);

            String returnUrl = Model.ReturnUrl;

            if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 &&
                returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") &&
                !returnUrl.StartsWith("/\\"))
            {
                return(Redirect(Model.ReturnUrl));
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult LogDetail(int RollCallID, DateTime Date)
        {
            AttendanceBusiness AttenBO = new AttendanceBusiness();

            //1 ngay, 1 roll call co the co 2 loai log, log manual va auto, do do phai lay ca 2
            AttendanceLog AutoLog = AttenBO.GetAttendanceLogAtDate(RollCallID, Date, 1);

            AttendanceLog ManualLog = AttenBO.GetAttendanceLogAtDate(RollCallID, Date, 2);
            RollCall      RollCall  = RollBO.GetRollCallByID(RollCallID);

            LogDetailViewModel Model = new LogDetailViewModel();

            Model.RollCall  = RollCall;
            Model.AutoLog   = AutoLog;
            Model.ManualLog = ManualLog;
            return(PartialView("_LogDetail", Model));
        }
        public ActionResult ChangeSchedule(int id)
        {
            RollCall rollCall = RollBO.GetRollCallByID(id);

            //Fill lai gia tri nhung ngay trong qua khu
            AttendanceBusiness AttenBO = new AttendanceBusiness();

            AttenBO.FillAbsentAttendance(id);


            ViewBag.RollCallID         = id;
            ViewBag.LastAttendanceDate = RollBO.LastAttendanceDate(id);

            //ViewBag.HasAttendance = RollBO.RollCallHasAttendance(id);


            return(View("RollCallSchedule", rollCall));
        }
        public ActionResult CheckAttendanceAuto(int RollCallID, IEnumerable <HttpPostedFileBase> ImageFiles)
        {
            RollCall rollCall = RollBO.GetRollCallByID(RollCallID);

            List <String> ImagePaths = new List <string>();

            foreach (HttpPostedFileBase file in ImageFiles)
            {
                //Save file anh xuong
                String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName);
                file.SaveAs(OldPath);

                //Resize file anh, luu vao thu muc log, ten mon hoc, ten lop
                String NewPath = Server.MapPath("~/Content/Log/"
                                                + rollCall.Class.ClassName + "_"
                                                + rollCall.Subject.ShortName + "_"
                                                + file.FileName);
                FaceBusiness.ResizeImage(OldPath, NewPath);
                ImagePaths.Add(NewPath);
            }
            //Nhan dien tung khuon mat trong anh
            List <RecognizerResult> Result = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths);
            //Dua reseult nay cho AttendanceBO xu ly
            AttendanceBusiness AttenBO = new AttendanceBusiness();
            AttendanceLog      Log     = AttenBO.WriteAttendanceAutoLog(RollCallID, Result);


            //Danh sach sinh vien trong log
            StudentBusiness StuBO    = new StudentBusiness();
            List <Student>  Students = StuBO.Find(stu => stu.StudentAttendances.
                                                  Any(attend => attend.LogID == Log.LogID && attend.IsPresent)).ToList();
            RollCall CurrentRollCall = RollBO.GetRollCallByID(RollCallID);

            //Tao model de show trong view
            AttendanceViewModel model = new AttendanceViewModel();

            model.CurrentRollCall = CurrentRollCall;
            model.PresentStudents = Students;
            model.RecognizeResult = Result;

            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult RollAttendance(int RollCallID, int StudentID)
        {
            Student  Stu  = StuBO.GetStudentByID(StudentID);
            RollCall Roll = RollBO.GetRollCallByID(RollCallID);

            AttendanceBusiness   AttenBO      = new AttendanceBusiness();
            List <AttendanceLog> RollCallLogs = AttenBO.GetRollCallAttendanceLog(RollCallID);

            //Tim nhung attendance cua student, nam trong log, co rollcallID bang RollcallID dua vao
            var StudentAttendances = Stu.StudentAttendances.Where(sa => sa.AttendanceLog.RollCallID == RollCallID &&
                                                                  RollCallLogs.Select(r => r.LogID).Contains(sa.LogID))
                                     .OrderBy(sa => sa.AttendanceLog.LogDate).ToList();


            StudentAttendanceViewModel Model = new StudentAttendanceViewModel();

            Model.InStudent          = Stu;
            Model.InRollCall         = Roll;
            Model.StudentAttendances = StudentAttendances;

            return(PartialView("_RollAttendance", Model));
        }
        public ActionResult GetLogDetail(int LogID)
        {
            AttendanceBusiness AttenBO = new AttendanceBusiness();
            AttendanceLog      Log     = AttenBO.GetLogByID(LogID);

            var LogJson = new
            {
                logID       = Log.LogID,
                rollID      = Log.RollCallID,
                logDate     = Log.LogDate.ToString("dd-MM-yyyy"),
                logPresent  = Log.StudentAttendances.Count(attend => attend.IsPresent) + "/" + Log.RollCall.Students.Count,
                submitDate  = Log.LogDate.ToString("MM-dd-yyyy"),
                studentList = Log.StudentAttendances.Select(sa => new
                {
                    studentID   = sa.StudentID,
                    studentCode = sa.Student.StudentCode,
                    studentName = sa.Student.FullName,
                    isPresent   = sa.IsPresent
                })
            };

            return(Json(LogJson, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Index()
        {
            //Tim instructor da dang nhạp vao
            string     Username             = this.HttpContext.User.Identity.Name;
            User       User                 = AccBO.GetUserByUsername(Username);
            Instructor AuthorizedInstructor = InsBO.GetInstructorByUserID(User.UserID);

            //Nhung mon ma instructor nay dang day, sau nay phai check status
            DateTime Today     = DateTime.Now;
            var      RollCalls = RollBO.GetInstructorCurrentRollCalls(AuthorizedInstructor.InstructorID);

            //Mon dang day vao thoi diem dang nhap
            RollCall CurrentRollCall = null;
            TimeSpan CurrentTime     = DateTime.Now.TimeOfDay;

            if (RollCalls.Count() > 0)
            {
                CurrentRollCall = RollCalls.FirstOrDefault(r => r.StartTime <CurrentTime && r.EndTime> CurrentTime);
            }

            //Neu co mon dang day, lay luon attendanlog log cua mon do
            AttendanceLog CurrentAttendanceLog = null;

            if (CurrentRollCall != null)
            {
                AttendanceBusiness AttendanceBO = new AttendanceBusiness();
                CurrentAttendanceLog = AttendanceBO.GetAttendanceLogAtDate(CurrentRollCall.RollCallID, DateTime.Today);
            }

            InstructorViewModel model = new InstructorViewModel();

            model.AuthorizedInstructor = AuthorizedInstructor;
            model.CurrentRollCall      = CurrentRollCall;
            model.TeachingRollCall     = RollCalls;
            model.CurrentAttendanceLog = CurrentAttendanceLog;
            return(View(model));
        }
        public ActionResult CheckAttendanceAuto(int RollCallID, List <HttpPostedFileBase> ImageFiles, DateTime?AttendanceDate)
        {
            RollCallBusiness RollBO  = new RollCallBusiness();
            var           rollCall   = RollBO.GetRollCallByID(RollCallID);
            List <String> ImagePaths = new List <string>();

            foreach (HttpPostedFileBase file in ImageFiles)
            {
                //Save file anh xuong
                String OldPath = Server.MapPath("~/Content/Temp/" + file.FileName);
                file.SaveAs(OldPath);

                //Resize file anh, luu vao thu muc log, nho them ngay thang truoc
                String NewPath = Server.MapPath("~/Content/Log/"
                                                + rollCall.Class.ClassName + "_"
                                                + rollCall.Subject.ShortName + "_"
                                                + file.FileName);
                FaceBusiness.ResizeImage(OldPath, NewPath);
                ImagePaths.Add(NewPath);

                //Nhan dien tung khuon mat trong anh
            }

            List <RecognizerResult> Results = FaceBusiness.RecognizeStudentForAttendance(RollCallID, ImagePaths);
            //Dua result nay cho AttendanceBO xu ly
            AttendanceBusiness AttenBO = new AttendanceBusiness();
            AttendanceLog      Log     = null;

            if (AttendanceDate == null)
            {
                Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Results);
            }
            else
            {
                Log = AttenBO.WriteAttendanceAutoLog(RollCallID, Results, AttendanceDate.Value);
            }

            //Danh sach sinh vien trong log

            List <int> StudentIDs = AttenBO.GetStudentIDList(Results);

            //Lay danh sach sinh vien ton tai trong log
            StudentBusiness StuBO = new StudentBusiness();
            //List<Student> Students = StuBO.Find(stu => StudentIDs.Contains(stu.StudentID)).ToList();

            /*
             * var StudentsJson = Students.ToList().Select(s => new
             * {
             *  studentID = s.StudentID,
             *  studentCode = s.StudentCode,
             *  studentName = s.FullName
             * });
             */

            var StudentsJson = Log.StudentAttendances.Select(sa => new
            {
                studentID   = sa.StudentID,
                studentCode = sa.Student.StudentCode,
                studentName = sa.Student.FullName,
                isPresent   = sa.IsPresent
            });

            return(Json(StudentsJson, JsonRequestBehavior.AllowGet));
        }
        //Tim xem can bao nhiu hinh thi nhan dien du SV
        static void FindRequiredImageNumber()
        {
            Console.WriteLine("Testing begin. Initialize the Recognizer.");
            Random random = new Random();

            //Set cac gia tri
            int    TestRollCallID      = 24;
            int    StudentPresent      = 17;
            String TestImageFolderPath = @"C:\Users\Hoang\Documents\Visual Studio 2010\Projects\RollSystemMobile\FaceRecAutomationTesting\More Test\Unknown";

            //Tao BO
            RollCall           roll    = new RollCallBusiness().GetRollCallByID(TestRollCallID);
            AttendanceBusiness AttenBO = new AttendanceBusiness();

            //Tao 1 mang luu ket qua
            List <MoreTestSingleResult> FinalResults = new List <MoreTestSingleResult>();
            List <RollSystemMobile.Models.RecognizerResult> AllResult = new List <RollSystemMobile.Models.RecognizerResult>();

            //Doc toan bo anh trong folder, recognize roi dua vao mang
            List <String> ImageFiles = Directory.GetFiles(TestImageFolderPath, "*.jpg", SearchOption.TopDirectoryOnly).ToList();

            foreach (var FilePath in ImageFiles)
            {
                var Result = FaceBusinessForMoreTest.RecognizeStudentForAttendance(TestRollCallID, FilePath);
                AllResult.Add(Result);
                Console.WriteLine(FilePath + " processed.");
            }


            //Chay test 10000 lan
            for (int i = 0; i < 10000; i++)
            {
                List <RollSystemMobile.Models.RecognizerResult> Results = new List <RollSystemMobile.Models.RecognizerResult>();
                int StudentDetected = 0;

                //Sao chep ra mot mang rieng
                List <RollSystemMobile.Models.RecognizerResult> AllResultClone = new List <RollSystemMobile.Models.RecognizerResult>(AllResult);
                List <String> FileUsed = new List <string>();

                while (StudentDetected < StudentPresent)
                {
                    //Lay 1 phan tu ra khoi mang clone
                    int Position  = random.Next(AllResultClone.Count);
                    var GetResult = AllResultClone.ElementAt(Position);
                    AllResultClone.Remove(GetResult);
                    FileUsed.Add(GetResult.ImageLink);


                    Results.Add(GetResult);

                    StudentDetected = AttenBO.GetStudentIDList(Results).Count;
                }
                MoreTestSingleResult SingleResult = new MoreTestSingleResult();
                SingleResult.FileUsed        = FileUsed;
                SingleResult.RunCount        = FileUsed.Count;
                SingleResult.StudentDetected = StudentDetected;
                FinalResults.Add(SingleResult);
                Console.WriteLine("Test run: " + i);
            }

            FinalResults = FinalResults.OrderBy(rs => rs.RunCount).ToList();
            MoreTestSingleResult MinResult = FinalResults.First();

            Console.WriteLine("Minimum image required: " + MinResult.RunCount);
            Console.Write("File Used: ");
            foreach (var FilePath in MinResult.FileUsed)
            {
                Console.WriteLine(Path.GetFileNameWithoutExtension(FilePath) + "|");
            }
            Console.WriteLine();

            MoreTestSingleResult MaxResult = FinalResults.Last();

            Console.WriteLine("Maximum image required: " + MaxResult.RunCount);
            Console.WriteLine("File Used: ");
            foreach (var FilePath in MaxResult.FileUsed)
            {
                Console.WriteLine(Path.GetFileNameWithoutExtension(FilePath) + "|");
            }
            Console.WriteLine();


            for (int i = MinResult.RunCount; i <= MaxResult.RunCount; i++)
            {
                int Times = FinalResults.Count(rs => rs.RunCount == i);
                Console.WriteLine("Required: " + i + ".Times: " + Times);
            }

            double AvgRun = FinalResults.Average(r => r.RunCount);

            Console.WriteLine("Avarage image required: " + AvgRun);
            Console.ReadLine();
        }
        //So luong hinh tang dan, tinh so luong SV detected dc
        static void FindAvarageStudentDetected()
        {
            Random random = new Random();

            //Set cac gia tri
            int    TestRollCallID      = 24;
            String TestImageFolderPath = @"C:\Users\Hoang\Documents\Visual Studio 2010\Projects\RollSystemMobile\FaceRecAutomationTesting\More Test\13 After - Copy";


            //Tao BO
            RollCall           roll    = new RollCallBusiness().GetRollCallByID(TestRollCallID);
            AttendanceBusiness AttenBO = new AttendanceBusiness();

            //Tao 1 mang luu ket qua
            List <MoreTestSingleResult> FinalResults = new List <MoreTestSingleResult>();
            List <RollSystemMobile.Models.RecognizerResult> AllResult = new List <RollSystemMobile.Models.RecognizerResult>();


            //Doc toan bo anh trong folder
            List <String> ImageFiles = Directory.GetFiles(TestImageFolderPath, "*.jpg", SearchOption.TopDirectoryOnly).ToList();

            foreach (var FilePath in ImageFiles)
            {
                var Result = FaceBusinessForMoreTest.RecognizeStudentForAttendance(TestRollCallID, FilePath);
                AllResult.Add(Result);
                Console.WriteLine(FilePath + " processed.");
            }

            //So luong hinh tang dan, tu 5 toi max
            for (int i = 1; i < ImageFiles.Count; i++)
            {
                //Chay 1000 lan
                for (int j = 0; j < 1000; j++)
                {
                    List <RollSystemMobile.Models.RecognizerResult> Results = new List <RollSystemMobile.Models.RecognizerResult>();
                    //Sao chep ra mot mang rieng
                    List <RollSystemMobile.Models.RecognizerResult> AllResultClone = new List <RollSystemMobile.Models.RecognizerResult>(AllResult);
                    List <String> FileUsed = new List <string>();

                    //Lay random i hinh, set result
                    for (int k = 0; k < i; k++)
                    {
                        //Lay 1 phan tu ra khoi mang clone
                        int Position  = random.Next(AllResultClone.Count);
                        var GetResult = AllResultClone.ElementAt(Position);
                        AllResultClone.Remove(GetResult);
                        FileUsed.Add(GetResult.ImageLink);

                        Results.Add(GetResult);
                    }
                    MoreTestSingleResult SingleResult = new MoreTestSingleResult();
                    SingleResult.FileUsed        = FileUsed;
                    SingleResult.RunCount        = FileUsed.Count;
                    SingleResult.StudentDetected = AttenBO.GetStudentIDList(Results).Count;
                    FinalResults.Add(SingleResult);
                }
            }


            //Bat dau tinh, voi so luong hinh tang dan, trung binh nhan dien dc bao nhieu hs
            for (int i = 1; i < ImageFiles.Count; i++)
            {
                Console.WriteLine("Number of image used: " + i);
                double AvgStudentDetected = FinalResults.Where(r => r.RunCount == i).Average(r => r.StudentDetected);
                Console.WriteLine("Average Student Detected: " + AvgStudentDetected);
            }
            Console.ReadLine();
        }