Пример #1
0
        private async void SubmitButton_Clicked(object sender, EventArgs e)
        {
            if (AreAllMandatoryQuestionsCompleted())
            {
                Dictionary <int, string> AllAnswers      = GetAllAnswers();
                ISurveyAnswerHandler     SurveyAnswer    = new SurveyAnswerHandler();
                IAnswersHandler          _QuestionAnswer = new AnswerHandler();

                if (Reachability.IsHostReachable("http://www.google.co.uk"))
                {
                    string SurveyAnswerId = "";
                    await Task.Run(() => SurveyAnswerId = SurveyAnswer.InsertSurveyAnswer(new cSurveyAnswer {
                        Platform = Device.Idiom.ToString(), SurveyId = SurveyId, AppVersion = App.Version, SurveyVersion = SurveyVersion
                    }));

                    foreach (var QuestionAnswer in AllAnswers)
                    {
                        await Task.Run(() => _QuestionAnswer.InsertAnswer(new cAnswer {
                            AnswerId = int.Parse(SurveyAnswerId), Answer = QuestionAnswer.Value, QuestionId = QuestionAnswer.Key, AnswerDateTime = DateTime.Now
                        }));
                    }
                    await DisplayAlert("Message", "Thank You For Completing This Survey.", "OK");

                    await App.Current.MainPage.Navigation.PopModalAsync();
                }
            }
        }
Пример #2
0
        public void Method_DCEventHandler()
        {
            // arrange
            string id        = "keyDCEventHandler";
            bool   isAnswer  = default(bool);
            string name      = "name";
            var    argValues = new Dictionary <int, object>()
            {
                { 0, "value1" }, { 1, "value2" }
            };

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name, null, argValues));
            }).GetAwaiter().GetResult();
            var answer = answerHelper.GetAnswerData(id, out isAnswer);

            // assert
            Assert.IsTrue(isAnswer);
            Assert.AreEqual(id, answer.AnswerKey);
            Assert.IsNotNull(answer.ArgValues);
            Assert.AreEqual("value1", answer.ArgValues[0]);
            Assert.AreEqual("value2", answer.ArgValues[1]);
        }
Пример #3
0
        public void Method_GetAnswerData()
        {
            // arrange
            AnswerInfo answer   = default(AnswerInfo);
            string     id       = "key";
            bool       isAnswer = default(bool);
            string     name     = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name));
                answer = answerHelper.GetAnswerData(id, out isAnswer);
            }).GetAwaiter().GetResult();

            // assert
            Assert.IsTrue(isAnswer);
            Assert.AreEqual(id, answer.AnswerKey);
        }
Пример #4
0
        public void MethodAsync_RemoveOneAnswerItem()
        {
            // arrange
            string id       = "key";
            bool   isAnswer = default(bool);
            string name     = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                // act
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name, null, null));
                isAnswer = await answerHelper.CheckAnswerAsync(id);
                await answerHelper.RemoveAnswerAsync(id);
                isAnswer = await answerHelper.CheckAnswerAsync(id);
            }).GetAwaiter().GetResult();

            // assert
            Assert.AreEqual(isAnswer, false);
        }
Пример #5
0
        public void MethodAsync_PushOneAnswerItem()
        {
            // arrange
            string idTrue   = "keyTrue";
            string idFalse  = "keyFalse";
            string name     = "name";
            bool   isAnswer = default(bool);

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();
            Task.Run(async() =>
            {
                // act 1
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(idTrue, string.Empty, name, null, null));
                isAnswer = await answerHelper.CheckAnswerAsync(idTrue);

                // assert 1
                Assert.AreEqual(isAnswer, true);

                // act 2
                isAnswer = await answerHelper.CheckAnswerAsync(idFalse);

                // assert 2
                Assert.AreEqual(isAnswer, false);
            }).GetAwaiter().GetResult();
        }
Пример #6
0
 private static void RegisterHandlers(IEventPublisher eventPublisher)
 {
     var questionHandler = new QuestionHandler();
     var answerHandler = new AnswerHandler();
     
     eventPublisher.RegisterHandler<QuestionAsked>(questionHandler.Handle);
     eventPublisher.RegisterHandler<QuestionAmended>(questionHandler.Handle);
     
     eventPublisher.RegisterHandler<AnswerSuggested>(answerHandler.Handle);
     eventPublisher.RegisterHandler<AnswerAmended>(answerHandler.Handle);
     eventPublisher.RegisterHandler<AnswerUpvoted>(answerHandler.Handle);
     eventPublisher.RegisterHandler<AnswerDownvoted>(answerHandler.Handle);
 }
Пример #7
0
        //
        // START-InferenceProcedure

        public InferenceResult ask(FOLKnowledgeBase kb, Sentence aQuery)
        {
            //
            // Get the background knowledge - are assuming this is satisfiable
            // as using Set of Support strategy.
            List <Clause> bgClauses  = new List <Clause>(kb.getAllClauses());
            List <Clause> removeList = SubsumptionElimination.findSubsumedClauses(bgClauses);

            foreach (Clause c in removeList)
            {
                bgClauses.Remove(c);
            }
            List <Chain> background = createChainsFromClauses(bgClauses);

            // Collect the information necessary for constructing
            // an answer (supports use of answer literals).
            AnswerHandler ansHandler = new AnswerHandler(kb, aQuery, maxQueryTime, this);

            IndexedFarParents ifps = new IndexedFarParents(ansHandler
                                                           .getSetOfSupport(), background);

            // Iterative deepening to be used
            for (int maxDepth = 1; maxDepth < int.MaxValue; maxDepth++)
            {
                // Track the depth actually reached
                ansHandler.resetMaxDepthReached();

                if (null != tracer)
                {
                    tracer.reset();
                }

                foreach (Chain nearParent in ansHandler.getSetOfSupport())
                {
                    recursiveDLS(maxDepth, 0, nearParent, ifps, ansHandler);
                    if (ansHandler.isComplete())
                    {
                        return(ansHandler);
                    }
                }
                // This means the search tree
                // has bottomed out (i.e. finite).
                // Return what I know based on exploring everything.
                if (ansHandler.getMaxDepthReached() < maxDepth)
                {
                    return(ansHandler);
                }
            }

            return(ansHandler);
        }
Пример #8
0
        //
        // START-InferenceProcedure

        public InferenceResult ask(FOLKnowledgeBase kb, Sentence aQuery)
        {
            //
            // Get the background knowledge - are assuming this is satisfiable
            // as using Set of Support strategy.
            List<Clause> bgClauses = new List<Clause>(kb.getAllClauses());
            List<Clause> removeList = SubsumptionElimination.findSubsumedClauses(bgClauses);
            foreach (Clause c in removeList)
            {
                bgClauses.Remove(c);
            }
            List<Chain> background = createChainsFromClauses(bgClauses);

            // Collect the information necessary for constructing
            // an answer (supports use of answer literals).
            AnswerHandler ansHandler = new AnswerHandler(kb, aQuery, maxQueryTime,this);

            IndexedFarParents ifps = new IndexedFarParents(ansHandler
                    .getSetOfSupport(), background);

            // Iterative deepening to be used
            for (int maxDepth = 1; maxDepth < int.MaxValue; maxDepth++)
            {
                // Track the depth actually reached
                ansHandler.resetMaxDepthReached();

                if (null != tracer)
                {
                    tracer.reset();
                }

                foreach (Chain nearParent in ansHandler.getSetOfSupport())
                {
                    recursiveDLS(maxDepth, 0, nearParent, ifps, ansHandler);
                    if (ansHandler.isComplete())
                    {
                        return ansHandler;
                    }
                }
                // This means the search tree
                // has bottomed out (i.e. finite).
                // Return what I know based on exploring everything.
                if (ansHandler.getMaxDepthReached() < maxDepth)
                {
                    return ansHandler;
                }
            }

            return ansHandler;
        }
Пример #9
0
 /// Make active answers clickable
 private void EnableAnswersRaycast()
 {
     foreach (Transform child in answerFolder.transform)                         // Get current answers list from answers folder
     {
         AnswerHandler answerHandler = child.gameObject.GetComponent <AnswerHandler>();
         if (answerHandler != null)
         {
             if (answerHandler.active)                                           // If answer setted as clickable
             {
                 Text text = child.gameObject.GetComponent <Text>();
                 if (text != null)
                 {
                     text.raycastTarget = true;                                  // Enable text raycast
                 }
             }
         }
     }
 }
Пример #10
0
    void Start()
    {
        //Making an instance of the QuestionsHandler and loading the questions
        handler     = gameObject.AddComponent <QuestionsHandler>();
        ans_handler = GetComponent <AnswerHandler>();
        handler.loadQuestions();
        _questions = handler.GetQuestions().questions;

        _inventory = FindObjectOfType <InventoryManager>();
        player     = GameObject.Find("Player");
        audioData  = GetComponent <AudioSource>();

        UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents = !UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents;

        for (int i = 0; i < progress; ++i)
        {
            ans_handler.executeAnswer(i);
        }
    }
Пример #11
0
    /// Add answer into answer folder
    /// <param name="name"> Answer name </param>
    /// <param name="answer"> Answer text </param>
    /// <param name="isActive"> true - answer is interactive, false - answer is inactive </param>
    private void AddAnswer(string name, string answer, bool isActive)
    {
        if (name == null || answer == null)
        {
            Debug.Log("Wrong input data");
            return;
        }
        GameObject newAnswer = Instantiate(answerPrefab) as GameObject;             // Clone answer prefab

        if (newAnswer != null)
        {
            newAnswer.transform.SetParent(answerFolder.transform);                  // Place it into anwer folder
            newAnswer.name = name;                                                  // Set answer name
            Text text = newAnswer.GetComponent <Text>();
            if (text != null)
            {
                answersCounter++;                                                   // Increase answers counter (cleared by ClearAnswers)
                AnswerHandler answerHandler = newAnswer.GetComponent <AnswerHandler>();
                if (isActive == false)                                              // If answer inactive
                {
                    answerHandler.active = false;                                   // Make answer not clickable
                    text.color           = inactiveAnswerColor;                     // Set inactive color
                }
                else
                {
                    answerHandler.active = true;                                    // Make answer clickable
                }
                if (playerTextRoutine != null)
                {
                    StopCoroutine(playerTextRoutine);  // Stop current coroutine if it is
                }
                text.text         = " ";               // Display answer counter
                playerTextRoutine = PlayerAnswerCoroutine(answer, text);
                StartCoroutine(playerTextRoutine);     // Start coroutine
            }
        }
    }
Пример #12
0
        // Recursive Depth Limited Search
        private void recursiveDLS(int maxDepth, int currentDepth, Chain nearParent, IndexedFarParents indexedFarParents, AnswerHandler ansHandler)
        {
            // Keep track of the maximum depth reached.
            ansHandler.updateMaxDepthReached(currentDepth);

            if (currentDepth == maxDepth)
            {
                return;
            }

            int noCandidateFarParents = indexedFarParents
                                        .getNumberCandidateFarParents(nearParent);

            if (null != tracer)
            {
                tracer.increment(currentDepth, noCandidateFarParents);
            }
            indexedFarParents.standardizeApart(nearParent);
            for (int farParentIdx = 0; farParentIdx < noCandidateFarParents; farParentIdx++)
            {
                // If have a complete answer, don't keep
                // checking candidate far parents
                if (ansHandler.isComplete())
                {
                    break;
                }

                // Reduction
                Chain nextNearParent = indexedFarParents.attemptReduction(
                    nearParent, farParentIdx);

                if (null == nextNearParent)
                {
                    // Unable to remove the head via reduction
                    continue;
                }

                // Handle Canceling and Dropping
                bool cancelled = false;
                bool dropped   = false;
                do
                {
                    cancelled = false;
                    Chain nextParent = null;
                    while (nextNearParent != (nextParent = tryCancellation(nextNearParent)))
                    {
                        nextNearParent = nextParent;
                        cancelled      = true;
                    }

                    dropped = false;
                    while (nextNearParent != (nextParent = tryDropping(nextNearParent)))
                    {
                        nextNearParent = nextParent;
                        dropped        = true;
                    }
                } while (dropped || cancelled);

                // Check if have answer before
                // going to the next level
                if (!ansHandler.isAnswer(nextNearParent))
                {
                    // Keep track of the current # of
                    // far parents that are possible for the next near parent.
                    int noNextFarParents = indexedFarParents
                                           .getNumberFarParents(nextNearParent);
                    // Add to indexed far parents
                    nextNearParent = indexedFarParents.addToIndex(nextNearParent);

                    // Check the next level
                    recursiveDLS(maxDepth, currentDepth + 1, nextNearParent,
                                 indexedFarParents, ansHandler);

                    // Reset the number of far parents possible
                    // when recursing back up.
                    indexedFarParents.resetNumberFarParentsTo(nextNearParent,
                                                              noNextFarParents);
                }
            }
        }
Пример #13
0
        // Recursive Depth Limited Search
        private void recursiveDLS(int maxDepth, int currentDepth, Chain nearParent,
                IndexedFarParents indexedFarParents, AnswerHandler ansHandler)
        {

            // Keep track of the maximum depth reached.
            ansHandler.updateMaxDepthReached(currentDepth);

            if (currentDepth == maxDepth)
            {
                return;
            }

            int noCandidateFarParents = indexedFarParents
                    .getNumberCandidateFarParents(nearParent);
            if (null != tracer)
            {
                tracer.increment(currentDepth, noCandidateFarParents);
            }
            indexedFarParents.standardizeApart(nearParent);
            for (int farParentIdx = 0; farParentIdx < noCandidateFarParents; farParentIdx++)
            {
                // If have a complete answer, don't keep
                // checking candidate far parents
                if (ansHandler.isComplete())
                {
                    break;
                }

                // Reduction
                Chain nextNearParent = indexedFarParents.attemptReduction(
                        nearParent, farParentIdx);

                if (null == nextNearParent)
                {
                    // Unable to remove the head via reduction
                    continue;
                }

                // Handle Canceling and Dropping
                bool cancelled = false;
                bool dropped = false;
                do
                {
                    cancelled = false;
                    Chain nextParent = null;
                    while (nextNearParent != (nextParent = tryCancellation(nextNearParent)))
                    {
                        nextNearParent = nextParent;
                        cancelled = true;
                    }

                    dropped = false;
                    while (nextNearParent != (nextParent = tryDropping(nextNearParent)))
                    {
                        nextNearParent = nextParent;
                        dropped = true;
                    }
                } while (dropped || cancelled);

                // Check if have answer before
                // going to the next level
                if (!ansHandler.isAnswer(nextNearParent))
                {
                    // Keep track of the current # of
                    // far parents that are possible for the next near parent.
                    int noNextFarParents = indexedFarParents
                            .getNumberFarParents(nextNearParent);
                    // Add to indexed far parents
                    nextNearParent = indexedFarParents.addToIndex(nextNearParent);

                    // Check the next level
                    recursiveDLS(maxDepth, currentDepth + 1, nextNearParent,
                            indexedFarParents, ansHandler);

                    // Reset the number of far parents possible
                    // when recursing back up.
                    indexedFarParents.resetNumberFarParentsTo(nextNearParent,
                            noNextFarParents);
                }
            }
        }