Ejemplo n.º 1
0
        public ReportViewModel(int questionID, IDictionary<String, int> demoResponses, IDictionary<String, int> compareResponses)
        {
            this.questionID = questionID;

            this.demoResponses = demoResponses;
            this.compareResponses = compareResponses;
            var questionRepository = new QuestionRepository(NHibernateHelper.GetCurrentSession());
            Question question = questionRepository.GetQuestionByID<Question>(questionID);
            this.text = question.question;

            QuestionChart chart = question.comparisonChart;
            this.chartType = chart.GetQuestionChartType();

            this.valueType = chart.valueType;

            String[] coloursArray = chart.colours.Split(new char[] { ',', ' ' });

            String chartColours = "";
            int i = 0;
            foreach (String colour in coloursArray)
            {
                if (colour != "")
                {
                    chartColours += "'" + colour + "'";
                    if (i < coloursArray.Length - 1)
                    {
                        chartColours += ", ";
                    }
                    i++;
                }
            }
            this.chartColours = chartColours;
        }
Ejemplo n.º 2
0
        public ReportViewModel(int questionID, IDictionary<String, int> responses, IList<String> correct)
        {
            this.questionID = questionID;
            this.responses = responses;
            var questionRepository = new QuestionRepository(NHibernateHelper.GetCurrentSession());
            Question question = questionRepository.GetQuestionByID<Question>(questionID);
            if (question.correctAnswerIndicator.active)
            {
                this.correct = correct;
            }
            else
            {
                this.correct = null;
            }
            this.text = question.question;

            QuestionChart chart = question.resultsChart;
            this.chartType = chart.GetQuestionChartType();

            this.valueType = chart.valueType;

            String[] coloursArray = chart.colours.Split(new char[] {',', ' '});

            String chartColours = "";
            int i = 0;
            foreach (String colour in coloursArray) {
                if (colour != "")
                {
                    chartColours += "'" + colour + "'";
                    if (i < coloursArray.Length - 1)
                    {
                        chartColours += ", ";
                    }
                    i++;
                }
            }
            this.chartColours = chartColours;
        }
Ejemplo n.º 3
0
        // Only call this on MCQ questions
        public virtual IList<String> getCorrect()
        {
            var questionRepository = new QuestionRepository(NHibernateHelper.GetCurrentSession());
            MultipleChoiceQuestion multipleQuestion = questionRepository.GetQuestionByID<MultipleChoiceQuestion>(this.questionID);
            IList<String> correctOptions = new List<String>();

            if (multipleQuestion != null)
            {
                foreach (var option in multipleQuestion.options)
                {
                    // If the answer is correct, store it
                    if (option.correctCurrent)
                    {
                        correctOptions.Add(option.answer);
                    }
                }
            }
            return correctOptions;
        }
Ejemplo n.º 4
0
        public int[] GetQuestionResults(int questionID)
        {
            var pollRepository = new PollRepository(session);
            var questionRepository = new QuestionRepository(session);
            var question = questionRepository.GetQuestionByID<Question>(questionID);
            IDictionary<String, int> responses = new Dictionary<String, int>();
            IList<String> correctOptions = new List<String>();
            int[] responseStatistics = new int[2];
            var poll = pollRepository.GetPollContainingQuestion(question);

            if (question.type == QuestionType.Numeric)
            {
                // If the question is numeric
                var numericQuestion = questionRepository.GetQuestionByID<NumericQuestion>(questionID);

                int numCorrect = 0;
                int numIncorrect = 0;

                foreach (var response in numericQuestion.responses)
                {

                    // Check if the answer is correct
                    if ((Convert.ToInt32(response.response) < numericQuestion.lessThan) &&
                        (Convert.ToInt32(response.response) > numericQuestion.greaterThan))
                    {
                        numCorrect++;
                    }
                    else
                    {
                        numIncorrect++;
                    }
                }

                responses.Add("Correct [" + numericQuestion.greaterThan.ToString() +
                            " - " + numericQuestion.lessThan.ToString() + "]", numCorrect);
                responses.Add("Incorrect", numIncorrect);
                responseStatistics[0] = numCorrect + numIncorrect;
                responseStatistics[1] = numCorrect;
            }
            else if (question.type == QuestionType.Alphanumeric)
            {
                // If the question is alphanumeric
                var alphaQuestion = questionRepository.GetQuestionByID<AlphanumericQuestion>(questionID);

                //  Get correct responses
                int numCorrect = 0;
                int numIncorrect = 0;
                int total = 0;

                foreach (var response in alphaQuestion.responses)
                {

                    foreach (var answer in alphaQuestion.answers)
                    {
                        if (response.response.Equals(answer.answer))
                        {
                            numCorrect++;
                        }
                    }
                    total++;
                }

                // Build a string of correct answers
                String correctAnswers = "";
                foreach (var answer in alphaQuestion.answers)
                {
                    if (correctAnswers != "")
                    {
                        correctAnswers += ", ";
                    }
                    correctAnswers += answer.answer;
                }

                responses.Add("Correct [" + correctAnswers + "]", numCorrect);
                numIncorrect = total - numCorrect;
                responses.Add("Incorrect", numIncorrect);
                responseStatistics[0] = total;
                responseStatistics[1] = numCorrect;
            }
            else
            {
                var multipleQuestion = questionRepository.GetQuestionByID<MultipleChoiceQuestion>(questionID);
                int numCorrect = 0;
                int total = 0;

                foreach (var option in multipleQuestion.options)
                {
                    total += option.responses.Count;
                    if (option.correctCurrent)
                    {
                        numCorrect += option.responses.Count;
                    }
                }
                total = total / multipleQuestion.allowedAnswers;
                numCorrect = numCorrect / multipleQuestion.allowedAnswers;
                responseStatistics[0] = total;
                responseStatistics[1] = numCorrect;
            }
            return responseStatistics;
        }
 public String points(Participant participant)
 {
     var questionRepository = new QuestionRepository(NHibernateHelper.GetCurrentSession());
     double points=0;
     double total = 0;
     IList<Question> multip = poll.questions.Where(m => m.type != QuestionType.Alphanumeric && m.type != QuestionType.Numeric).ToList();
     IList<MultipleChoiceQuestion> multi = new List<MultipleChoiceQuestion>();
     foreach (Question multipl in multip) multi.Add(questionRepository.GetQuestionByID<MultipleChoiceQuestion>(multipl.questionID));
     foreach (MultipleChoiceQuestion ques in multi)
     {
         foreach (QuestionOption option in ques.options)
         {
             total += option.pointsCurrent;
             foreach (OptionResponse res in option.responses) if (res.participant == participant) points += option.pointsCurrent;
         }
     }
     return points + "/" + total;
 }
 public int participating(Participant participant)
 {
     var questionRepository = new QuestionRepository(NHibernateHelper.GetCurrentSession());
     IList<Question> shortre = poll.questions.Where(m => m.type == QuestionType.Alphanumeric || m.type == QuestionType.Numeric).ToList();
     IList<Question> multip = poll.questions.Where(m => m.type != QuestionType.Alphanumeric && m.type != QuestionType.Numeric).ToList();
     IList<ShortResponseQuestion> shortr = new List<ShortResponseQuestion>();
     IList<MultipleChoiceQuestion> multi = new List<MultipleChoiceQuestion>();
     foreach (Question shorty in shortre) shortr.Add(questionRepository.GetQuestionByID<ShortResponseQuestion>(shorty.questionID));
     foreach (Question multipl in multip) multi.Add(questionRepository.GetQuestionByID<MultipleChoiceQuestion>(multipl.questionID));
     int total = shortr.Count() + multi.Count();
     int answered = 0;
     foreach (ShortResponseQuestion ques in shortr)
         foreach (ShortResponse res in ques.responses) if (res.participant == participant) answered++;
     foreach (MultipleChoiceQuestion ques in multi)
     {
         bool breaking = false;
         foreach (QuestionOption option in ques.options)
         {
             foreach (OptionResponse res in option.responses) if (res.participant == participant) { answered++; breaking = true; break; }
             if (breaking) break;
         }
     }
     return answered;
 }
 public double onlytotal()
 {
     var questionRepository = new QuestionRepository(NHibernateHelper.GetCurrentSession());
     double total = 0;
     IList<Question> multip = poll.questions.Where(m => m.type != QuestionType.Alphanumeric && m.type != QuestionType.Numeric).ToList();
     IList<MultipleChoiceQuestion> multi = new List<MultipleChoiceQuestion>();
     foreach (Question multipl in multip) multi.Add(questionRepository.GetQuestionByID<MultipleChoiceQuestion>(multipl.questionID));
     foreach (MultipleChoiceQuestion ques in multi)
     {
         foreach (QuestionOption option in ques.options)
         {
             total += option.pointsCurrent;
         }
     }
     return total;
 }
 public QuestionOption GetOptionByResponse(int responseID, int questionID)
 {
     var questionRepository = new QuestionRepository(session);
     IList<QuestionOption> options = questionRepository.GetQuestionByID<MultipleChoiceQuestion>(questionID).options;
     return (from item in options where item.responses.Any(r => r.responseID == responseID) select item).FirstOrDefault();
 }