public static Dictionary <string, float> EvaulateExam(RealExam studentExam, RealExam modelExam)
        {
            Dictionary <string, float> questionScores = new Dictionary <string, float>();

            RealExamQuestion[] allQuestions = modelExam.examElements;
            float totalScore   = 0;
            float perfectScore = 0;

            for (int i = 0; i < allQuestions.Count(); i++)
            {
                perfectScore = perfectScore + allQuestions[i].score;
                float questionPoints     = 0;
                float totalQuestionScore = allQuestions[i].score;
                float individualPoints   = totalQuestionScore / allQuestions[i].answer.Count();
                foreach (string validAnswer in allQuestions[i].answer)
                {
                    if (studentExam.examElements[i].answer.Contains(validAnswer))
                    {
                        questionPoints = questionPoints + individualPoints;
                    }
                }
                questionScores.Add(studentExam.examElements[i].title, questionPoints);
                totalScore = totalScore + questionPoints;
            }
            totalScore = (totalScore / perfectScore) * 100;
            questionScores.Add("~totalScore", totalScore);
            return(questionScores);
        }
Beispiel #2
0
 // GET: api/Exams/5
 public IHttpActionResult Get(int id, bool student)
 {
     if (student == false)
     {
         var result = realExamProxy.GetRealExam(id);
         if (result == null)
         {
             EditExamController.currentExam = null;
             EditExamController.Editing     = false;
             return(NotFound());
         }
         RealExamProxy.UpdateRealExam(result.Id);
         EditExamController.currentExam = result;
         EditExamController.Editing     = true;
         return(Ok(result));
     }
     else
     {
         RealExam result = realExamProxy.GetRealExam(id);
         if (result == null)
         {
             StudentExamController.currentExam = null;
             return(NotFound());
         }
         foreach (RealExamQuestion question in result.examElements)
         {
             question.answerCount = question.answer.Count();
             question.answer      = new string[] { };
         }
         RealExamProxy.UpdateRealExam(id);
         StudentExamController.currentExam = result;
         return(Ok());
     }
 }
        public RealExam GetStaticExamModel(Exam exam)
        {
            List <QuestionAssign> allExamQuestions = questionAssignController.GetAllExamQuestions(exam.Id);
            RealExam realExam = GetRealExam(exam, allExamQuestions);

            return(GetRealExam(exam, allExamQuestions));
        }
Beispiel #4
0
        private RealExam GetRandomExam(DAL.Exam exam)
        {
            RealExam randomExam = realExamController.GetRandomExam(exam);

            realExamsCache.Add(randomExam);
            System.Diagnostics.Debug.WriteLine("Exam fetched is:" + randomExam.title);
            return(randomExam);
        }
 public static StudentExam NewRealExamToStudentExam(RealExam exam, int score, int studentId)
 {
     return(new StudentExam
     {
         examId = exam.Id,
         score = score,
         studentId = studentId
     });
 }
        public RealExam GetStudentExam(StudentExam exam)
        {
            Exam modelExam = examController.GetById(exam.examId);
            List <QuestionAssign> allStudentExamQuestions = GetStudentExamQuestions(exam.Id);

            RealExamQuestion[] questions = StudentExamUtils.GetAllStudentExamElements(exam.Id, examController, allStudentExamQuestions, questionAssignController, optionAssignController, studentExamQuestionController);
            RealExam           realExam  = ExamUtils.ExamToRealExam(modelExam, questions, new SubAreaController(), new AreaController());

            realExam.studentTotalScore = exam.score;
            return(realExam);
        }
Beispiel #7
0
        public static Exam EditedRealToExam(RealExam editedReal, ExamController examController)
        {
            Exam editedExam = examController.GetById(editedReal.Id);

            editedExam.fromDate        = DateTime.Parse(editedReal.fromDate);
            editedExam.untilDate       = DateTime.Parse(editedReal.untilDate);
            editedExam.subAreaId       = editedReal.subAreaId;
            editedExam.staticQuestions = editedReal.staticQuestions;
            editedExam.numberQuestions = editedReal.numberQuestions;
            editedExam.title           = editedReal.title;
            return(editedExam);
        }
Beispiel #8
0
 public static Exam NewRealExamToExam(RealExam exam)
 {
     return(new Exam
     {
         fromDate = DateTime.Parse(exam.fromDate),
         untilDate = DateTime.Parse(exam.untilDate),
         subAreaId = exam.subAreaId,
         title = exam.title,
         numberQuestions = exam.numberQuestions,
         staticQuestions = exam.staticQuestions,
     });
 }
        private void EvaluateAndRegister(RealExam studentExam, RealExam modelExam)
        {
            OptionAssignController     optionAssignController = new OptionAssignController();
            Dictionary <string, float> questionScores         = StudentExamUtils.EvaulateExam(studentExam, modelExam);
            StudentExam exam          = StudentExamUtils.NewRealExamToStudentExam(studentExam, (int)questionScores["~totalScore"], studentExam.studentId);
            int         studentExamId = studentExamController.AddStudentExam(exam);
            StudentExamQuestionController studentExamQuestionController = new StudentExamQuestionController();

            foreach (RealExamQuestion question in studentExam.examElements)
            {
                StudentQuestionTable studentQuestion = StudentExamUtils.RealQuestionToStudentQuestion(question, (int)questionScores[question.title], studentExamId, optionAssignController);
                studentExamQuestionController.AddStudentExamQuestion(studentQuestion);
            }
        }
Beispiel #10
0
        public RealExam GetStudentExam(int id)
        {
            RealExam cachedExam = studentExamsCache.Find(studentExam => studentExam.Id == id);

            if (cachedExam == null)
            {
                RealExam newExam = realExamController.GetStudentExam(studentExamController.GetById(id));
                studentExamsCache.Add(newExam);
                System.Diagnostics.Debug.WriteLine("Exam fetched is:" + newExam.title);
                return(newExam);
            }
            System.Diagnostics.Debug.WriteLine("Exam cached is:" + cachedExam.title);
            return(cachedExam);
        }
        public void Post([FromBody] object realExam)
        {
            JObject  juser             = realExam as JObject;
            RealExam recievingRealExam = juser.ToObject <RealExam>();
            Exam     modelExam         = examController.GetById(recievingRealExam.Id);
            RealExam realModelExam;

            if (!modelExam.staticQuestions)
            {
                realModelExam = realExamController.GetRandomExamModel(recievingRealExam);
            }
            else
            {
                realModelExam = realExamController.GetStaticExamModel(modelExam);
            }
            EvaluateAndRegister(recievingRealExam, realModelExam);
        }
        public RealExam GetRandomExamModel(RealExam exam)
        {
            RealExam studentExamCopy = new RealExam(exam);

            foreach (RealExamQuestion question in studentExamCopy.examElements)
            {
                List <string>       answers      = new List <string>();
                List <OptionAssign> modelOptions = optionAssignController.GetAllQuestionOptions(question.questionId);
                foreach (OptionAssign option in modelOptions)
                {
                    if (option.answer == true)
                    {
                        answers.Add(option.optionTitle);
                    }
                }
                question.answer = answers.ToArray();
            }
            return(studentExamCopy);
        }
        public void Post(object realExam, bool edit)
        {
            JObject  juser             = realExam as JObject;
            RealExam recievingRealExam = juser.ToObject <RealExam>();

            if (edit == false)
            {
                Exam exam = ExamUtils.NewRealExamToExam(recievingRealExam);
                realExamController.AddExam(exam, recievingRealExam.examElements);
            }
            else
            {
                Exam exam = ExamUtils.EditedRealToExam(recievingRealExam, examController);
                examController.EditExam(exam.Id, exam);
                if (recievingRealExam.staticQuestions)
                {
                    realExamController.EditExamQuestions(recievingRealExam.examElements, exam.Id);
                }
            }
        }
Beispiel #14
0
        public RealExam GetRealExam(int id)
        {
            RealExam cachedExam = realExamsCache.Find(realExam => realExam.Id == id);

            if (cachedExam == null)
            {
                DAL.Exam exam = examController.GetById(id);
                if (!exam.staticQuestions)
                {
                    return(GetRandomExam(exam));
                }
                RealExam newExam = realExamController.GetStaticExamModel(exam);
                realExamsCache.Add(newExam);
                System.Diagnostics.Debug.WriteLine("Exam fetched is:" + newExam.title);
                return(newExam);
            }
            if (!cachedExam.staticQuestions)
            {
                return(GetRandomExam(examController.GetById(id)));
            }
            System.Diagnostics.Debug.WriteLine("Exam cached is:" + cachedExam.title);
            return(cachedExam);
        }