Exemple #1
0
        // Compute aggregates for each feedback question in template based on all responses in feedback table
        internal List <QuestionStats> GetFeedbackQuestionStats(QuestionTemplate[] questionTemplate, FeedbackReportHelper[] feedbackTable)
        {
            List <QuestionStats> questionStats = new List <QuestionStats>();

            foreach (QuestionTemplate question in questionTemplate)
            {
                if (question.Type != "likert")
                {
                    continue;
                }

                List <int> answers = new List <int>();
                foreach (var response in feedbackTable.Where(f => f.Submitted || true))
                {
                    var answer = response.IdToAnswer.GetValueOrDefault(question.Id, null);
                    if (answer != null)
                    {
                        answers.Add(Int32.Parse(answer));
                    }
                }
                var newStat = new QuestionStats {
                    Id        = question.Id,
                    Prompt    = question.Prompt,
                    ShortName = question.ShortName,
                    Required  = question.Required,
                    ScaleMin  = question.Min,
                    ScaleMax  = question.Max,
                    Count     = answers.Count(),
                };
                if (newStat.Count > 0)
                {
                    newStat.Average = answers.Average();
                    newStat.Lowest  = answers.Min();
                    newStat.Highest = answers.Max();
                }
                questionStats.Add(newStat);
            }
            return(questionStats);
        }
Exemple #2
0
        // Get: Questionnarie/RegisterAnswer
        public ActionResult RegisterAnswer(int questionnarieId, List <QuestionDTO> questionsRes)
        {
            var answers = new List <AnswerDTO>();

            foreach (var question in questionsRes)
            {
                foreach (var answer in question.Answers)
                {
                    if (answer.Text is object)
                    {
                        answers.Add(answer);
                    }
                }
            }
            _qestionnarieService.AddAnswers(answers);
            var questionnarie = _qestionnarieService.GetQuestionnarie(questionnarieId);
            var questions     = questionnarie.Questions;
            List <QuestionStats> questionStats = new List <QuestionStats>();

            foreach (var question in questions)
            {
                var aStats = question.Answers.GroupBy(a => a.Text)
                             .Select(ag => new AnswerStat {
                    Text = ag.Key, Count = ag.Count()
                });
                var qStats = new QuestionStats {
                    Question = question, AnswerStats = aStats.ToList()
                };
                questionStats.Add(qStats);
            }
            var viewModel = new ResultViewModel {
                Questionnarie = questionnarie, QuestionStats = questionStats
            };

            return(View("Result", viewModel));
        }