public IHttpActionResult PutUserAnswersViewModel(int id, UserAnswersViewModel userAnswersViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != userAnswersViewModel.Id)
            {
                return(BadRequest());
            }

            UserAnswers UserAnswers = new UserAnswers();

            Mapper.CreateMap <UserAnswersViewModel, UserAnswers>();
            UserAnswers = Mapper.Map <UserAnswersViewModel, UserAnswers>(userAnswersViewModel);
            db.Entry(UserAnswers).State = EntityState.Modified;
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserAnswersExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IActionResult SingQuestion()
        {
            int          Id     = int.Parse(this.RouteData.Values["id"].ToString());
            int?         userId = HttpContext.Session.GetInt32("UserId");
            var          user   = _dbContext.Users.First(a => a.Id == userId);
            PropertyInfo info   = user.GetType().GetProperty($"Answer{Id}");


            var          waveResampler    = new Resampler(null);
            Sound        freqencyDetector = new Sound();
            List <float> result           = freqencyDetector.DetectFrequency(waveResampler);
            float        mainFrequency    = FrequencyFilter.CalculateMainFreq(result);

            if (Id == 19)
            {
                FrequencyClassificator FreqClass = new FrequencyClassificator(330);
                UserAnswers.AddAnswer(FreqClass.Validate(mainFrequency));
                info.SetValue(user, FreqClass.Validate(mainFrequency));
                _dbContext.SaveChanges();
                return(RedirectToAction("Question", new { Id = Id + 1 }));
            }
            else if (Id == 20)
            {
                FrequencyClassificator FreqClass = new FrequencyClassificator(440);
                UserAnswers.AddAnswer(FreqClass.Validate(mainFrequency));
                info.SetValue(user, FreqClass.Validate(mainFrequency));
                _dbContext.SaveChanges();
                return(RedirectToAction("YourResult"));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public IEvaluationResult Evaluate(UserAnswers userAnswer)
        {
            var result = this.CreateEvaluation(userAnswer);
            var answersByQuestionId = this.GetAnswersByQuestionId(userAnswer);

            return(this.AddSelectedAnswers(answersByQuestionId, result));
        }
Ejemplo n.º 4
0
        public IActionResult Question(string firstbtn, string secondbtn)
        {
            int?userId    = HttpContext.Session.GetInt32("UserId");
            int id        = int.Parse(this.RouteData.Values["id"].ToString());
            var audiofile = AudioRepository.Audiofiles[id - 1];

            var          user = _dbContext.Users.First(a => a.Id == userId);
            PropertyInfo info = user.GetType().GetProperty($"Answer{id}");

            if (firstbtn != null)
            {
                UserAnswers.AddAnswer(audiofile.Question.FirstAnswer.IsRight);
                info.SetValue(user, audiofile.Question.FirstAnswer.IsRight);
                _dbContext.SaveChanges();
            }
            if (secondbtn != null)
            {
                UserAnswers.AddAnswer(audiofile.Question.SecondAnswer.IsRight);
                info.SetValue(user, audiofile.Question.SecondAnswer.IsRight);
                _dbContext.SaveChanges();
            }

            if (id < 21)
            {
                return(RedirectToAction("Question", new { Id = id + 1 }));
            }
            else
            {
                return(RedirectToAction("YourResult"));
            }
        }
        protected override string QuestionTemplate()
        {
            string selectTemplate = "<input type='hidden' name='{0}' value='__Multi__' /><select class='form-control' id='{0}' name='{0}'>{1}</select>";
            string template       = "<option value='{0}' {2}>{1}</option>";

            StringBuilder builder = new StringBuilder();

            foreach (var option in base.Answers)
            {
                string isChecked = string.Empty;
                //check if it has a value selected
                var userHasSelection = UserAnswers.Where(x => x.Item1 == QuestionUniqueID && x.Item2 == option.Value.ToString()).FirstOrDefault();

                if (userHasSelection != null)
                {
                    isChecked = "selected";
                }
                builder.AppendFormat(template, option.Value, option.Text, isChecked);
            }

            var    boundSelect = string.Format(selectTemplate, QuestionUniqueID, builder.ToString());
            string allChoices  = string.Format(base.BaseTemplate, base.QuestionUniqueID, base.QuestionText, boundSelect);

            return(allChoices);
        }
Ejemplo n.º 6
0
        public void CheckAnswers()
        {
            for (uint i = 1; i <= Questions.Count; i++)
            {
                List <string> userAnswers = new List <string>();
                if (UserAnswers.ContainsKey(i))
                {
                    userAnswers = UserAnswers[i];
                }
                else
                {
                    UserAnswers.Add(i, new List <string>());
                }
                List <bool> correctAnswers         = CorrectAnswers[i];
                List <bool> userCorrectnessAnswers = new List <bool>();

                for (int j = 0; j < userAnswers.Count; j++)
                {
                    if (correctAnswers[GetIdAnswer(userAnswers[j], i)])
                    {
                        userCorrectnessAnswers.Add(true);
                    }
                    else
                    {
                        userCorrectnessAnswers.Add(false);
                    }
                }
                UserCorrectnessAnswers.Add(i, userCorrectnessAnswers);
            }
        }
Ejemplo n.º 7
0
        public IActionResult Sing()
        {
            var file       = Request.Form.Files[0];
            var questionId = Request.Form["param"].FirstOrDefault();

            byte[] audioArray = _service.GetAudioArray(file);
            bool   answer;

            if (Int32.Parse(questionId) == 19)
            {
                answer = _service.ProcessRecording(audioArray, 330);
            }
            else if (Int32.Parse(questionId) == 20)
            {
                answer = _service.ProcessRecording(audioArray, 440);
            }
            else
            {
                answer = false;
            }


            int?         userId = HttpContext.Session.GetInt32("UserId");
            var          user   = _dbContext.Users.First(a => a.Id == userId);
            PropertyInfo info   = user.GetType().GetProperty($"Answer{questionId}");

            UserAnswers.AddAnswer(answer);
            info.SetValue(user, answer);
            _dbContext.SaveChanges();



            return(Json("Ok"));
        }
Ejemplo n.º 8
0
        public UserAnswers SaveSolution(QuizEvaluationDto quizSolution, string userId)
        {
            var quiz = this.quizzes.GetById(quizSolution.ForQuizId);

            if (quizSolution.SelectedAnswerIds.Count != quiz.NumberOfQuestions &&
                quizSolution.SelectedAnswerIds.Count != quiz.Questions.Count)
            {
                throw new Exception("Invalid Solution: Questions count mismatch");
            }

            List <Solutions> selectedAnswers = this.ExtractSelectedAnswers(quiz, quizSolution);

            var newSolution = new UserAnswers
            {
                ByUserId        = userId,
                ForQuiz         = quiz,
                SelectedAnswers = selectedAnswers
            };

            try
            {
                this.solutions.Add(newSolution);
                this.solutions.Save();
            }
            catch (Exception ex)
            {
                throw new Exception("Something went wrong while saving your solution.", ex);
            }

            return(newSolution);
        }
Ejemplo n.º 9
0
        public async Task <UserAnswers> Create(UserAnswers userAnswer)
        {
            dbContext.UserAnswers.Add(userAnswer);
            await dbContext.SaveChangesAsync();

            return(userAnswer);
        }
Ejemplo n.º 10
0
 public static AnswerEntity ToAnswerEntity(this UserAnswers userAnswer)
 {
     return(new AnswerEntity()
     {
         Id = userAnswer.Id,
         IsSolved = userAnswer.TrueAnswer,
         Count = userAnswer.Count,
         TaskId = userAnswer.TaskId
     });
 }
Ejemplo n.º 11
0
 public void AddToUserAnswers(uint key, string val)
 {
     if (UserAnswers.ContainsKey(key))
     {
         UserAnswers[key].Add(val);
     }
     else
     {
         UserAnswers.Add(key, new List <string>());
         UserAnswers[key].Add(val);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Saves the answer for the current question
        /// </summary>
        /// <param name="answer">The answer itself</param>
        public void SaveAnswer(Answer answer)
        {
            // Save the answer
            UserAnswers.Add(answer);

            DI.Logger.Log($"User answer saved for question nr {CurrentQuestionString}.");

            // Create view data from the results page if it is allowed to be shown
            if (AreResultsAllowed)
            {
                QuestionViewModels.Add(Questions[mCurrentQuestion - 1].ToViewModel(answer, QuestionViewModels.Count));
            }
        }
        public List <UserAnswers> ReadAnswers(Worksheet sheet)
        {
            int numPeople = GetNumPeople(sheet);

            List <UserAnswers> answersList = new List <UserAnswers>();

            for (int i = 0; i < numPeople; i++)
            {
                UserAnswers userAnswers = ReadPerson(sheet, i + RowOffset);
                answersList.Add(userAnswers);
            }

            return(answersList);
        }
Ejemplo n.º 14
0
        private void OnChange(Answer answer)
        {
            var IsChecked = UserAnswers.FirstOrDefault(p => p.AnswerId == answer.AnswerId);

            if (IsChecked == null)
            {
                UserAnswers.Add(answer);
            }
            else
            {
                UserAnswers.Remove(IsChecked);
            }
            StateHasChanged();
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Formularz(List <FieldWithValue> fields, int formId, int patientId)
        {
            MyUser user = await GetUser();

            foreach (var field in fields)
            {
                UserAnswers answer = new UserAnswers
                {
                    IdForm    = formId,
                    IdField   = field.Field.Id,
                    IdPatient = patientId,
                    IdUser    = user.CustomID
                };

                switch (field.Field.Type)
                {
                case "checkbox":
                    answer.Answer = field.BoolValue.ToString();
                    break;

                case "text":
                    answer.Answer = field.TextValue;
                    break;

                case "number":
                    answer.Answer = field.TextValue;
                    break;

                case "select":
                    answer.Answer = field.TextValue;
                    break;
                }
                _context.Add(answer);

                for (int i = 0; i < field.Dependencies.RelatedFields.Count; i++)
                {
                    UserAnswers pomik = new UserAnswers
                    {
                        Answer    = field.Dependencies.RelatedFields[i].Type == "checkbox" ? field.DepndenciesValue[i].boolVal.ToString() : field.DepndenciesValue[i].textVal,
                        IdField   = field.Dependencies.RelatedFields[i].Id,
                        IdForm    = formId,
                        IdPatient = patientId,
                        IdUser    = user.CustomID
                    };
                    _context.Add(pomik);
                }
            }
            _context.SaveChanges();
            return(View("WyslanoFormularz", fields));
        }
Ejemplo n.º 16
0
        public async Task <CommonResult> FillSurvey(string surveyId, List <UserAnswerModel> UserAnswerModelsList, string user)
        {
            try
            {
                var validationFillSurvey = ValidationFillSurvey(UserAnswerModelsList, surveyId);

                if (validationFillSurvey.StateMessage == CommonResultState.OK)
                {
                    foreach (var userAnswer in UserAnswerModelsList)
                    {
                        UserAnswers usAnswer = new UserAnswers();
                        usAnswer.Content        = userAnswer.Content;
                        usAnswer.UserAnswerList = new List <UserAnswers_List>();
                        usAnswer.UserLinkL      = new List <UsersLink>();

                        usAnswer.UserAnswerList.Add(new UserAnswers_List {
                            QuestionId = int.Parse(userAnswer.questionId)
                        });

                        var userId = dbContext.Users.FirstOrDefault(x => x.Id == user);

                        if (userId != null)
                        {
                            usAnswer.UserLinkL.Add(new UsersLink {
                                UserId = userId.Id
                            });
                        }
                        else
                        {
                            return(new CommonResult(CommonResultState.Error, Properties.Resources.UserNotExist));
                        }

                        dbContext.UserAnswers.Add(usAnswer);
                    }


                    await dbContext.SaveChangesAsync();

                    validationFillSurvey.Message = Properties.Resources.FillSurvey;
                    return(validationFillSurvey);
                }

                return(validationFillSurvey);
            }
            catch (Exception)
            {
                return(new CommonResult(CommonResultState.Error, Properties.Resources.Error));
            }
        }
        private UserAnswers ReadPerson(Worksheet sheet, int personRowIndex)
        {
            string itemRange   = "A" + IdRowIndex + ":" + FinalColumn + IdRowIndex;
            string personRange = "A" + personRowIndex + ":" + FinalColumn + personRowIndex;
            string scaleRange  = "A" + ScaleRowIndex + ":" + FinalColumn + ScaleRowIndex;

            List <string> scaleRow   = CellReader.GetRange(scaleRange, sheet);
            List <string> itemRow    = CellReader.GetRange(itemRange, sheet).Skip(NumEmptyScores).ToList();
            List <string> scoresRow  = CellReader.GetRange(personRange, sheet);
            string        personName = scoresRow[0];

            scoresRow = scoresRow.Skip(NumEmptyScores).ToList();

            List <string> scaleNames = scaleRow.Distinct().ToList();

            List <ScaleAnswers> scaleAnswersList = new List <ScaleAnswers>();

            foreach (var scaleName in scaleNames)
            {
                List <int> indices = Enumerable.Range(0, scaleRow.Count)
                                     .Where(index => scaleRow[index] == scaleName)
                                     .ToList();

                Dictionary <string, int> itemsToAnswersMap = new Dictionary <string, int>();
                for (int k = 0; k < indices.Count; k++)
                {
                    var index    = indices[k];
                    var itemName = itemRow[index];
                    itemsToAnswersMap[itemName] = Convert.ToInt32(scoresRow[index]);
                }

                ScaleAnswers scaleAnswers = new ScaleAnswers()
                {
                    ScaleName       = scaleName,
                    ItemToAnswerMap = itemsToAnswersMap
                };

                scaleAnswersList.Add(scaleAnswers);
            }


            UserAnswers answers = new UserAnswers()
            {
                PersonName   = personName,
                ScaleAnswers = scaleAnswersList
            };

            return(answers);
        }
Ejemplo n.º 18
0
        public IActionResult YourResult()
        {
            ViewBag.Count  = UserAnswers.Answers.Count(a => a);
            ViewBag.Result = UserAnswers.CalculateResult();
            int?userId = HttpContext.Session.GetInt32("UserId");

            var user = _dbContext.Users.First(a => a.Id == userId);

            user.Result = (int)UserAnswers.CalculateResult();
            _dbContext.SaveChanges();

            var ans = Models.UserAnswers.Answers;

            return(View());
        }
Ejemplo n.º 19
0
        private async void SubmitSurvey()
        {
            var answers = new List <SurveyAnswer>();

            if (UserAnswers.Count > 0 && !string.IsNullOrEmpty(UserId))
            {
                //Submit UserSurvey
                var userSurvey = await AccountSurveyRepository.AddAccountSurvey(new AccountSurvey
                {
                    Id               = UserId,
                    SurveyId         = Survey.SurveyId,
                    Risk             = UserAnswers.Sum(p => p.Percentage),
                    SurveyDate       = DateTime.Now,
                    UserSurveyStatus = SurveyResult(UserAnswers.Sum(p => p.Percentage))
                });

                if (userSurvey != null)
                {
                    foreach (var userAnswer in UserAnswers)
                    {
                        answers.Add(new SurveyAnswer
                        {
                            AccountSurveyId = userSurvey.AccountSurveyId,
                            Answer          = userAnswer.UserAnswer,
                            Question        = userAnswer.Question.SurveyQuestion
                        });
                    }
                    var added = await QuestionAnswerRepository.AddRange(answers);

                    if (added)
                    {
                        Open = false;
                        StateHasChanged();
                        await SweetAlertMessage.SuccessMessage();

                        //Navigate to show results
                    }
                    else
                    {
                        await SweetAlertMessage.ErrorMessage();
                    }
                }
            }
            else
            {
                await SweetAlertMessage.ErrorMessage(Text : "Survey not completed, please answer atleast one question");
            }
        }
Ejemplo n.º 20
0
        protected override string QuestionTemplate()
        {
            string template = "<input class='form-control' type='text' id='{0}' name='{0}' placeholder='{1}' value='{2}'></input>";
            string value    = string.Empty;
            //check if it has a value selected
            var userHasSelection = UserAnswers.Where(x => x.Item1 == QuestionUniqueID).FirstOrDefault();

            if (userHasSelection != null)
            {
                value = userHasSelection.Item2;
            }
            var control = string.Format(template, base.QuestionUniqueID, !string.IsNullOrEmpty(PlaceHolder) ? PlaceHolder : string.Empty, value);

            string allChoices = string.Format(base.BaseTemplate, base.QuestionUniqueID, base.QuestionText, control);

            return(allChoices);
        }
Ejemplo n.º 21
0
        protected override string QuestionTemplate()
        {
            //string template = @"<input type='checkbox' id='{1}' value='{1}' name='{0}'>{2}</input>";
            string template = @"<div class='checkbox' style='padding-left:35px; padding-right:35px;'><label>
                                <input type='hidden' name='{0}' value='__Multi__' />
                                <input type='checkbox' id='{1}-{0}' value='{1}' name='{0}' {3} {7} />{5}
                                <input type='text' id='{1}-{0}other' name='{1}-{0}other' value='{4}' {6}/></label></div>";
            //string template = @"<div class='form-check'>
            //                  <input class='form-check-input' type='checkbox' name='{0}' id='{1}' value='{1}' checked=''>
            //                  <label class='form-check-label' for='{1}'>
            //                    {2}
            //                  </label>
            //                </div>";
            StringBuilder builder = new StringBuilder();

            foreach (var checkbox in base.Answers)
            {
                string isChecked  = string.Empty;
                string isOther    = "class='hidden'";
                string strScript  = string.Empty;
                string strIsOther = string.Empty;
                //check if it has a value selected
                var userHasSelection = UserAnswers.Where(x => x.Item1 == QuestionUniqueID && x.Item2 == checkbox.Value.ToString()).FirstOrDefault();
                if (checkbox.isOther.HasValue && checkbox.isOther.Value)
                {
                    strIsOther = "Other";
                    strScript  = @"onclick='showCustomText(this)'";
                }
                else
                {
                    strIsOther = checkbox.Text;
                    strScript  = string.Empty;
                }

                if (userHasSelection != null)
                {
                    isChecked = "checked=''";
                    isOther   = string.Empty;
                }

                builder.AppendFormat(template, QuestionUniqueID, checkbox.Value, checkbox.Text, isChecked, checkbox.Text, strIsOther, isOther, strScript);
            }
            string allChoices = string.Format(base.BaseTemplate, base.QuestionUniqueID, base.QuestionText, builder.ToString());

            return(allChoices);
        }
Ejemplo n.º 22
0
        protected override string QuestionTemplate()
        {
            //string template = "<input type='number' id='{0}' name='{0}' placeholder='{1}'></input>";
            string template  = @"<div class='input-group'>
                                <div class='hidden'>
                                     <input class='form-control' id='{0}' type='number' min='{2}' max='{3}' class='form-control hidden' name='{0}' placeholder='{1}' style='z-index:1;' value='{4}'>
                                </div></div>


<div class='selectgroup' id='{0}selectable'>
{5}
</div>";
            string value     = string.Empty;
            string listItems = string.Empty;
            double?step      = Step.HasValue ? Step : 1;
            //check if it has a value selected
            var userHasSelection = UserAnswers.Where(x => x.Item1 == QuestionUniqueID).FirstOrDefault();

            if (userHasSelection != null)
            {
                value = userHasSelection.Item2;
            }

            From = From.HasValue? From.Value: 0;
            To   = To.HasValue? To.Value: 100;

            for (double?i = From; i < To; i += step)
            {
                //listItems += @"<li class=""selectgroup-item"" onclick=""$('#" + base.QuestionUniqueID + "').val('"+ i + "');$(this).addClass('class', 'selectgroup-button').removeClass('selectgroup-item')\"> " + i + " </li>";
                listItems += @"<label class='selectgroup-item' onclick=""debugger;$('#" + base.QuestionUniqueID + "').val('" + i + "');$(this).siblings().removeClass('selectgroup-item-selected');$(this).addClass('selectgroup-item-selected').removeClass('selectgroup-item')\"><span class='selectgroup-button'>" + i + "</span></label>";
            }

            var control = string.Format(template,
                                        base.QuestionUniqueID,
                                        !string.IsNullOrEmpty(PlaceHolder) ? PlaceHolder : string.Empty,
                                        From,
                                        To,
                                        value,
                                        listItems);

            string allChoices = string.Format(base.BaseTemplate, base.QuestionUniqueID, base.QuestionText, control);

            return(allChoices);
        }
        protected override string QuestionTemplate()
        {
            //string template = "<input type='number' id='{0}' name='{0}' placeholder='{1}'></input>";
            string template = @"<div class='input-group'>
                                     <input id='{0}' type='number' min='0' max='100' class='form-control' name='{0}' placeholder='{1}' style='z-index:1;' value='{2}'>
                                     <span class='input-group-addon' style='display: inline;padding: 8px 12px;'><i class='glyphicon glyphicon-percentage'>%</i></span>
                                </div>";
            string value    = string.Empty;
            //check if it has a value selected
            var userHasSelection = UserAnswers.Where(x => x.Item1 == QuestionUniqueID).FirstOrDefault();

            if (userHasSelection != null)
            {
                value = userHasSelection.Item2;
            }
            var control = string.Format(template, base.QuestionUniqueID, !string.IsNullOrEmpty(PlaceHolder) ? PlaceHolder : string.Empty, value);

            string allChoices = string.Format(base.BaseTemplate, base.QuestionUniqueID, base.QuestionText, control);

            return(allChoices);
        }
Ejemplo n.º 24
0
 public virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             Answers.Dispose();
             Questions.Dispose();
             Results.Dispose();
             Tests.Dispose();
             Themes.Dispose();
             UserInfoes.Dispose();
             TempResults.Dispose();
             UserQuestions.Dispose();
             UserAnswers.Dispose();
             ApplicationRoleManagers.Dispose();
             ApplicationRoleManagers.Dispose();
         }
         _disposed = true;
     }
 }
Ejemplo n.º 25
0
        public async Task <IActionResult> Quiz(int?id, HomeQuizViewModel data)
        {
            if (ModelState.IsValid)
            {
                var userAnswer = new UserAnswers
                {
                    OptionChosen = data.ChosenOption,
                    UserId       = id,
                    QuestionId   = data.QuestionId
                };

                await userAnswersRepository.Create(userAnswer);

                return(RedirectToAction("Quiz", new { id }));
            }

            var allUserAnswers  = userAnswersRepository.GetByUserId(id);
            var allQuestions    = questionsRepository.GetAll();
            var questionOptions = optionsRepository.GetByQuestionId(allQuestions[allUserAnswers.Count].QuestionId);

            data.Question = allQuestions[allUserAnswers.Count];
            data.Options  = new List <Option>
            {
                new Option {
                    Id = 1, OptionText = questionOptions[0].OptionText
                },
                new Option {
                    Id = 2, OptionText = questionOptions[1].OptionText
                },
                new Option {
                    Id = 3, OptionText = questionOptions[2].OptionText
                },
                new Option {
                    Id = 4, OptionText = questionOptions[3].OptionText
                }
            };
            data.QuestionId = allQuestions[allUserAnswers.Count].QuestionId;
            return(View(data));
        }
        private static ScoringOutput GetScores(List <string> scaleNames, List <ItemInformation> itemInformationList, List <string> personNames, List <UserAnswers> answersInput,
                                               CATParameters catParameters)
        {
            List <ScoreDetails>         scores           = new List <ScoreDetails>();
            List <List <QuestionInfo> > questionInfoList = new List <List <QuestionInfo> >();

            foreach (var scaleName in scaleNames)
            {
                List <ItemInformation> itemInfoForScale = itemInformationList.Where(x => x.ScaleName.Equals(scaleName)).ToList();
                IQuestionLoader        questionLoader   = new ExcelQuestionLoader(itemInfoForScale, catParameters.MistakeProbability);
                foreach (var personName in personNames)
                {
                    UserAnswers        personAnswers     = answersInput.Single(x => x.PersonName.Equals(personName));
                    ScaleAnswers       answers           = personAnswers.ScaleAnswers.Single(x => x.ScaleName.Equals(scaleName));
                    IAnswerSheetLoader answerSheetLoader = new ExcelAnswerSheetLoader(answers);

                    LocationEstimator   locationEstimator = new LocationEstimator(questionLoader, answerSheetLoader, catParameters);
                    List <QuestionInfo> output            = locationEstimator.EstimatePersonLocation();
                    questionInfoList.Add(output);

                    ScoreDetails scoreDetails = new ScoreDetails()
                    {
                        PersonName = personName,
                        ScaleName  = scaleName,
                        Score      = (double)output.Last().ThetaEstimate
                    };
                    scores.Add(scoreDetails);
                }
            }

            ScoringOutput scoringOutput = new ScoringOutput()
            {
                FirstPersonQuestionInfo = questionInfoList.First(),
                ScoreDetails            = scores
            };

            return(scoringOutput);
        }
Ejemplo n.º 27
0
 public bool Save(UserAnswers userAnswers)
 {
     foreach (KeyValuePair <string, int[]> entry in userAnswers.Answers)
     {
         foreach (int optionId in entry.Value)
         {
             _questionnaireContext.Answers
             .Add(
                 new Answer()
             {
                 QuestionId = int.Parse(entry.Key),
                 OptionId   = optionId,
                 UserName   = userAnswers.User,
                 Stamp      = DateTime.Now,
                 IsCorrect  = _questionnaireContext.QuestionsOptions
                              .Where(o => o.QuestionId == int.Parse(entry.Key))
                              .Any(o => o.isCorrect && o.Id == optionId)
             });
             _questionnaireContext.SaveChanges();
         }
     }
     return(true);
 }
Ejemplo n.º 28
0
        public ActionResult AddAnswers()
        {
            var userAnswers = new UserAnswers();

            var length = Request.Form.Count;

            if (length < 20)
            {
                return(RedirectToAction("Index"));
            }
            var dataString = new List <string>();
            var data       = new List <int>();

            foreach (var key in Request.Form.AllKeys)
            {
                dataString.Add(Request.Form[key]);
            }

            foreach (string s in dataString)
            {
                data.Add(s.Contains("-") ? -((int)(s[s.Length - 1]) - '0')  : (int)(s[s.Length - 1]) - '0');
            }

            var dictionary = new Dictionary <string, int>
            {
                { "I", 0 }, { "E", 0 }, { "S", 0 }, { "N", 0 }, { "T", 0 }, { "F", 0 }, { "J", 0 }, { "P", 0 }
            };

            var person = new Personality();
            var round  = 1;

            foreach (var s in data)
            {
                if (round == 1 | round == 4 | round == 5)
                {
                    if (s == -1)
                    {
                        dictionary["I"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["I"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["E"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["E"] += 2;
                    }
                }
                else if (round == 2 | round == 3)
                {
                    if (s == -1)
                    {
                        dictionary["E"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["E"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["I"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["I"] += 2;
                    }
                }
                else if (round == 6 | round == 7 | round == 10)
                {
                    if (s == -1)
                    {
                        dictionary["N"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["N"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["S"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["S"] += 2;
                    }
                }
                else if (round == 8 | round == 9)
                {
                    if (s == -1)
                    {
                        dictionary["S"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["S"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["N"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["N"] += 2;
                    }
                }
                else if (round == 11 | round == 14 | round == 15)
                {
                    if (s == -1)
                    {
                        dictionary["F"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["F"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["T"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["T"] += 2;
                    }
                }
                else if (round == 12 | round == 13)
                {
                    if (s == -1)
                    {
                        dictionary["T"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["T"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["F"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["F"] += 2;
                    }
                }
                else if (round == 16 | round == 17 | round == 18 | round == 20)
                {
                    if (s == -1)
                    {
                        dictionary["P"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["P"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["J"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["J"] += 2;
                    }
                }
                else if (round == 19)
                {
                    if (s == -1)
                    {
                        dictionary["J"] += 1;
                    }
                    if (s == -2)
                    {
                        dictionary["J"] += 2;
                    }
                    if (s == 1)
                    {
                        dictionary["P"] += 1;
                    }
                    if (s == 2)
                    {
                        dictionary["P"] += 2;
                    }
                }

                round++;
            }

            if (dictionary["I"] >= dictionary["E"])
            {
                person.personalityType += "I";
            }
            else
            {
                person.personalityType += "E";
            }
            if (dictionary["N"] >= dictionary["S"])
            {
                person.personalityType += "N";
            }
            else
            {
                person.personalityType += "S";
            }
            if (dictionary["F"] >= dictionary["T"])
            {
                person.personalityType += "F";
            }
            else
            {
                person.personalityType += "T";
            }
            if (dictionary["J"] >= dictionary["P"])
            {
                person.personalityType += "J";
            }
            else
            {
                person.personalityType += "P";
            }

            if (person.personalityType == "ISTJ")
            {
                person.personality += "The Inspector";
            }
            else if (person.personalityType == "ISTP")
            {
                person.personality += "The Crafter";
            }
            else if (person.personalityType == "ISFJ")
            {
                person.personality += "The Protector";
            }
            else if (person.personalityType == "ISFP")
            {
                person.personality += "The Artist";
            }

            else if (person.personalityType == "INFJ")
            {
                person.personality += "The Advocate";
            }
            else if (person.personalityType == "INFP")
            {
                person.personality += "The Mediator";
            }
            else if (person.personalityType == "INTJ")
            {
                person.personality += "The Architect";
            }
            else if (person.personalityType == "INTP")
            {
                person.personality += "The Thinker";
            }

            else if (person.personalityType == "ESTP")
            {
                person.personality += "The Persuader";
            }
            else if (person.personalityType == "ESTJ")
            {
                person.personality += "The Director";
            }
            else if (person.personalityType == "ESFP")
            {
                person.personality += "The Performer";
            }
            else if (person.personalityType == "ESFJ")
            {
                person.personality += "The Caregiver";
            }

            else if (person.personalityType == "ENFP")
            {
                person.personality += "The Champion";
            }
            else if (person.personalityType == "ENFJ")
            {
                person.personality += "The Giver";
            }
            else if (person.personalityType == "ENTP")
            {
                person.personality += "The Debater";
            }
            else if (person.personalityType == "ENTJ")
            {
                person.personality += "The Commander";
            }

            userAnswers.AnswerList = Request.Form.ToString();
            userAnswers.UserName   = TempData["UserData"].ToString();

            _piDbContext.UserAnswers.Add(userAnswers);
            _piDbContext.SaveChanges();

            TempData["Type"] = person.personality;

            return(View(person));
        }
Ejemplo n.º 29
0
        private IEvaluationResult CreateEvaluation(UserAnswers userAnswer)
        {
            var result = this.mapper.Map <EvaluationResult>(userAnswer.ForQuiz);

            return(result);
        }
Ejemplo n.º 30
0
        private IDictionary <int, Solutions> GetAnswersByQuestionId(UserAnswers userAnswer)
        {
            var result = userAnswer.SelectedAnswers.ToDictionary(key => key.ForQuestionId);

            return(result);
        }