public void StoreQuestionToUsersAnswers(Question question)
        {
            Answer selectedAnswer   = CurrentAnswers.Where(x => x.IsSelected == true).Single();
            Answer dbSelectedAnswer = QuizEntities.Answers.Where(x => x.Id == selectedAnswer.Id).Single();

            UsersAnswers.Add(question, dbSelectedAnswer);
        }
Exemple #2
0
        public void SaveQuestionVM()
        {
            CurrentQuestion.ChaperId = currentChapterVM.ChapterId;
            CurrentQuestion.Text     = QuestionText;
            if (this.QuestionId > 0)
            {
                CurrentQuestion.ID = this.QuestionId;
            }
            CurrentQuestion.CorrectAnswer = CorrectAnswerText;
            CurrentQuestion.FakeAnswer1   = FakeAnswerText1;
            CurrentQuestion.FakeAnswer2   = FakeAnswerText2;
            CurrentQuestion.FakeAnswer3   = FakeAnswerText3;

            if (!string.IsNullOrEmpty(CorrectAnswerText.Trim()))
            {
                CurrentAnswers.Add(CorrectAnswerText);
                //Answer correctAnswer = new Answer();
                //correctAnswer.IsCorrect = true;
                //correctAnswer.QuestionId = CurrentQuestion.
            }
            if (!string.IsNullOrEmpty(FakeAnswerText1.Trim()))
            {
                CurrentAnswers.Add(FakeAnswerText1);
            }
            if (!string.IsNullOrEmpty(FakeAnswerText2.Trim()))
            {
                CurrentAnswers.Add(FakeAnswerText2);
            }
            if (!string.IsNullOrEmpty(FakeAnswerText3.Trim()))
            {
                CurrentAnswers.Add(FakeAnswerText3);
            }
            Repository.SaveQuestion(CurrentQuestion);
        }
Exemple #3
0
        // 'get_question_result'
        // This action is executed from 'get_next_question'

        // This shows the result of the question that they answered

        // A timer is set for 3 seconds
        // When the timer runs out, the action 'try_get_next_question' is executed
        private void GetQuestionResult(GameContext ctx)
        {
            // set all currently playing displays to freq. 10
            foreach (ServerConnection connection in ctx.Server.GetConnectionsInState(GameState.Playing))
            {
                connection.Frequency = 11;
            }
            ctx.Session.SpectateFrequency = 11;

            //session.CancelQueuedAction();

            int currentQuestion = ctx.Session.ValueOf <int>("current_question");

            ctx.Session.SetValue("players_answered", 0);

            DisplayContent content = ctx.Server.GetBroadcast(11).Content;

            content
            .GetComponent("result")
            .Draw(ctx.Session.ValueOf <int>("current_question"),
                  ctx.Session.GetConfigValue <int>("questioncount"),
                  CurrentQuestion.Question,
                  CurrentAnswers.Select((x, i) => x.IsCorrect ? $"[**{GetLetter(i).ToUpper()}**] {x.Response}" : null)
                  .First(x => !string.IsNullOrWhiteSpace(x)));

            foreach (PlayerData playerData in ctx.Session.Players)
            {
                bool hasAnswered = playerData.ValueOf <bool>("has_answered");

                if (!hasAnswered)
                {
                    playerData.ResetProperty("streak");
                }
                else
                {
                    bool isCorrect = playerData.ValueOf <bool>("is_correct");


                    if (isCorrect)
                    {
                        int points = GetPoints(CurrentQuestion.Value,
                                               playerData.ValueOf <int>("streak"),
                                               playerData.ValueOf <int>("answer_position"),
                                               CurrentQuestion.Difficulty);

                        playerData.AddToValue("score", points);
                    }
                }

                playerData.ResetProperty("has_answered");
                playerData.ResetProperty("is_correct");
            }

            ctx.Session.QueueAction(TimeSpan.FromSeconds(5), "try_get_next_question");
        }
Exemple #4
0
        private void GetNextQuestion(GameContext ctx)
        {
            // set all currently playing displays to freq. 10
            foreach (ServerConnection connection in ctx.Server.GetConnectionsInState(GameState.Playing))
            {
                connection.Frequency = 10;
            }
            ctx.Session.SpectateFrequency = 10;

            int currentQuestion = ctx.Session.ValueOf <int>("current_question");

            CurrentQuestion = QuestionPool[currentQuestion];
            ctx.Session.AddToValue("current_question", 1);

            DisplayContent content = ctx.Server.GetBroadcast(10).Content;

            content.GetComponent("question_header")
            .Draw(
                Format.Counter(ctx.Session.GetConfigValue <double>("questionduration")),
                ctx.Session.ValueOf <int>("current_question"),
                ctx.Session.GetConfigValue <int>("questioncount"),
                CurrentQuestion.Question);

            // select only 3 random answers and shuffle with the correct answer in there
            CurrentAnswers = Randomizer.Shuffle(Randomizer
                                                .ChooseMany(CurrentQuestion.Answers.Where(x => !x.IsCorrect), Math.Min(3, CurrentQuestion.Answers.Count(x => !x.IsCorrect)))
                                                .Append(CurrentQuestion.Answers.First(x => x.IsCorrect)));

            content
            .GetComponent("answers")
            .Draw(CurrentAnswers.Select((x, i) => $"[**{GetLetter(i).ToUpper()}**] {x.Response}"));

            content
            .GetComponent("footer")
            .Draw(CurrentQuestion.Difficulty.ToString(),
                  string.IsNullOrWhiteSpace(CurrentQuestion.TopicOverride) ? CurrentQuestion.Topic.ToString() : CurrentQuestion.TopicOverride,
                  $"{CurrentQuestion.Value} {Format.TryPluralize("Point", CurrentQuestion.Value)}");

            ctx.Session.QueueAction(TimeSpan.FromSeconds(ctx.Session.GetConfigValue <double>("questionduration")), "get_question_result");
        }
Exemple #5
0
        private async void NextQuestion()
        {
            // Add empty answers if necessary
            var questionResponse = _response.Item.QuestionResponses.FirstOrDefault(r => r.QuestionID == CurrentQuestion?.QuestionID);

            if (questionResponse == null)
            {
                _response.Item.QuestionResponses.Add(new SurveyQuestionResponseModel
                {
                    QuestionID = CurrentQuestion.QuestionID,
                });
            }

            // Check if we should prompt in case the user did not fill out the additional information field
            var shouldPrompt    = false;
            var questionAnswers = CurrentQuestion.AnswerChoices.ToDictionary(a => a.AnswerChoiceID, a => a);

            foreach (var answer in CurrentAnswers)
            {
                if (string.IsNullOrEmpty(answer.AdditionalAnswerData))
                {
                    SurveyQuestionAnswerChoiceModel questionAnswer;
                    if (questionAnswers.TryGetValue(answer.AnswerChoiceID, out questionAnswer) && questionAnswer.AdditionalAnswerDataFormat != AnswerFormat.None)
                    {
                        shouldPrompt = true;
                        break;
                    }
                }
            }

            // Prompt the user if any additional information entries are empty
            if (shouldPrompt)
            {
                var shouldContinue = await App.DisplayAlertAsync(
                    "Incomplete Answer",
                    "At least one answer requires more information, are you sure you want to continue?",
                    "Yes",
                    "No");

                if (!shouldContinue)
                {
                    return;
                }
            }

            var properties = new Dictionary <string, string>
            {
                { "CurrentQuestionID", CurrentQuestion?.QuestionID.ToString() },
            };

            DependencyService.Get <IMetricsManagerService>().TrackEvent("SurveyNextQuestion", properties, null);

            // Save the response
            await _response.SaveAsync();

            // Create a lookup table for all the currently selected answers
            var currentAnswerIds = new HashSet <int>(CurrentAnswers.Select(a => a.AnswerChoiceID));

            // Get a reference to any matching question answer model from the survey question
            var matchingAnswer = CurrentQuestion.AnswerChoices.FirstOrDefault(a => currentAnswerIds.Contains(a.AnswerChoiceID));

            // Set the next question to the next question identifier from the question answer model if available;
            // otherwise, set the next question to the next highest question number
            var nextQuestionIndex = QuestionIndex(matchingAnswer?.NextQuestionID) ?? NextQuestion(CurrentQuestion.QuestionNum);

            _index = nextQuestionIndex ?? _index + 1;

            // End the survey if the matching question answer disqualifies the survey, or if there are no more questions
            if ((matchingAnswer?.EndSurvey ?? false) || nextQuestionIndex == null)
            {
                EndSurvey();
            }

            UpdateCommands();
            QuestionChanged?.Invoke(this, new EventArgs());
        }