private async Task <DialogTurnResult> AgeStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //PersonalDetails = (PersonalDetails)stepContext.Options;

            //if (PersonalDetails.Name == null)
            //{
            //    luisResult = await MainDialog.Get_luisRecognizer().RecognizeAsync<FlightBooking>(stepContext.Context, cancellationToken);
            //    PersonalDetails.Name = (luisResult.Entities.personName != null ? char.ToUpper(luisResult.Entities.personName[0][0]) + luisResult.Entities.personName[0].Substring(1) : null);
            //    //PersonalDetails.Name = (string)stepContext.Result;
            //}

            // Sand to DB
            MainDialog.WriteToDB(stepContext, cancellationToken);

            // Test for questionnairs
            //MainDialog.WriteQuestionnairesTempAsync(stepContext, cancellationToken);
            //MainDialog.WriteQuestionnairesTemp2Async(stepContext, cancellationToken);

            if (PersonalDetails.Age == null)
            {
                var AgeStepMsgText = MainDialog.Response.AskAge();
                var promptMessage  = MessageFactory.Text(AgeStepMsgText, AgeStepMsgText, InputHints.ExpectingInput);
                var retryText      = MainDialog.Response.RetryAge();
                var retryMessage   = MessageFactory.Text(retryText, retryText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage, RetryPrompt = retryMessage, Validations = Validator.Age }, cancellationToken));
            }

            return(await stepContext.NextAsync(PersonalDetails.Age, cancellationToken));
        }
        private async Task <bool> TextPromptValidatorAsync(PromptValidatorContext <string> promptContext, CancellationToken cancellationToken)
        {
            //throw new NotImplementedException();

            switch (promptContext.Options.Validations != null ? (Validator)promptContext.Options.Validations : (Validator)(-1))
            {
            case Validator.Name:
                luisResult = await MainDialog.Get_luisRecognizer().RecognizeAsync <LuisModel>(promptContext.Context, cancellationToken);

                PersonalDetails.Name = (luisResult.Entities.personName != null ? char.ToUpper(luisResult.Entities.personName[0][0]) + luisResult.Entities.personName[0].Substring(1) : null);

                if (PersonalDetails.Name == null)
                {
                    return(await Task.FromResult(false));
                }
                else
                {
                    return(await Task.FromResult(true));
                }

            case Validator.Age:


                luisResult = await MainDialog.Get_luisRecognizer().RecognizeAsync <LuisModel>(promptContext.Context, cancellationToken);

                //PersonalDetails.Age = (luisResult.Entities.age != null ? luisResult.Entities.age[0].Number.ToString() : Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value);
                if (luisResult.Entities.age != null)
                {
                    PersonalDetails.Age = (int?)luisResult.Entities.age[0].Number;
                }
                else if (Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value != "")
                {
                    //PersonalDetails.Age = Int32.Parse(Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value);
                    // Second check, just in case. Returns null if parse fails
                    PersonalDetails.Age = Int32.TryParse(Regex.Match(promptContext.Context.Activity.Text, @"\d+").Value, out var tempVal) ? tempVal : (int?)null;
                }

                if (PersonalDetails.Age == null)
                {
                    return(await Task.FromResult(false));
                }
                else
                {
                    return(await Task.FromResult(true));
                }

            default:
                return(await Task.FromResult(true));
            }
        }
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (finished)
            {
                finished = false;
                return(await stepContext.BeginDialogAsync(nameof(QuestionnaireChoiceDialog), PersonalDetails, cancellationToken));
            }
            else if ((bool)stepContext.Result)
            {
                //var personalDetails = (PersonalDetails)stepContext.Options;

                // Upload to database

                // Wipe the personalDetails for testing purposes
                //PersonalDetails = new PersonalDetails();


                // Sand to DB
                MainDialog.WriteToDB(stepContext, cancellationToken);
                //var changes = new Dictionary<string, object>() { { PersonalDetails.UserID, PersonalDetails } };
                //try
                //{
                //    MainDialog.CosmosDBQuery.WriteAsync(changes, cancellationToken);
                //    finished = false;
                //}
                //catch (Exception e)
                //{
                //    await stepContext.Context.SendActivityAsync($"Error while connecting to database.\n\n{e}");
                //}

                //return await stepContext.EndDialogAsync(PersonalDetails, cancellationToken);
                return(await stepContext.BeginDialogAsync(nameof(QuestionnaireChoiceDialog), PersonalDetails, cancellationToken));
            }
            else
            {
                //PersonalDetails = new PersonalDetails();
                //PersonalDetails.Name = PersonalDetails.Sex = null;
                //PersonalDetails.Age = null;
                ClearDetails();

                return(await stepContext.BeginDialogAsync(nameof(PersonalDetailsDialog), PersonalDetails, cancellationToken));
            }

            //return await stepContext.EndDialogAsync(null, cancellationToken);
        }
        private async Task <DialogTurnResult> ConfirmStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (PersonalDetails.PhysicalActivity == null)
            {
                PersonalDetails.PhysicalActivity = (int)stepContext.Result;
            }

            //PersonalDetails = (PersonalDetails)stepContext.Options;

            //if(Regex.IsMatch((string)stepContext.Result, "female", RegexOptions.IgnoreCase))
            //    PersonalDetails.Sex = "Female";
            //else if (Regex.IsMatch((string)stepContext.Result, "male", RegexOptions.IgnoreCase))
            //    PersonalDetails.Sex = "Male";
            //else
            //    PersonalDetails.Sex = null;


            //if (PersonalDetails.Sex == null)
            //    PersonalDetails.Sex = ((FoundChoice)stepContext.Result).Value;

            //    //PersonalDetails.Sex = stepContext.Result.ToString();
            //    PersonalDetails.Sex = char.ToUpper(stepContext.Context.Activity.Text[0]) + stepContext.Context.Activity.Text.Substring(1).ToLower();

            //var choice = (FoundChoice)stepContext.Result;
            //PersonalDetails.Sex = choice.Value;

            //var userProfile = (UserProfile)stepContext.Values[UserInfo];
            //userProfile.CompaniesToReview = stepContext.Result as List<string> ?? new List<string>();

            // Sand to DB
            MainDialog.WriteToDB(stepContext, cancellationToken);

            var messageText   = $"Please confirm, this is your personal info:\n\nName: {PersonalDetails.Name}\n\nAge: {PersonalDetails.Age}\n\nSex: {PersonalDetails.Sex}\n\nSmoker: {PersonalDetails.Smoker}\n\nWater Consumption: {PersonalDetails.WaterConsumption} cups per day\n\nSleep: {PersonalDetails.Sleep} hours per day\n\nPhysical Activity: {PersonalDetails.PhysicalActivity} hours per week\n\nIs this correct?";
            var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);

            if (!finished)
            {
                return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync(PersonalDetails, cancellationToken));
            }
        }
        private async Task <DialogTurnResult> SexStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //PersonalDetails= (PersonalDetails)stepContext.Options;

            //PersonalDetails.Age = Regex.Match((string)stepContext.Result, @"\d+").Value;
            //if (PersonalDetails.Age == null)
            //{
            //    luisResult = await MainDialog.Get_luisRecognizer().RecognizeAsync<FlightBooking>(stepContext.Context, cancellationToken);
            //    PersonalDetails.Age = (luisResult.Entities.age != null ? luisResult.Entities.age[0].Number.ToString() : Regex.Match((string)stepContext.Result, @"\d+").Value);
            //}

            //personalDetails.Age = (string)stepContext.Result;

            //if(PersonalDetails.Age == null)
            //{
            //    string errorMessage = "Didnt get that, lets try again.";
            //    var promptMessage = MessageFactory.Text(errorMessage, errorMessage, InputHints.ExpectingInput);
            //    await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);


            //    return await stepContext.ReplaceDialogAsync(nameof(PersonalDetailsDialog.AgeStepAsync), PersonalDetails, cancellationToken);
            //}

            // Sand to DB
            MainDialog.WriteToDB(stepContext, cancellationToken);

            if (PersonalDetails.Sex == null)
            {
                var SexStepMsgText  = MainDialog.Response.AskSex();
                var promptMessage   = MessageFactory.Text(SexStepMsgText, SexStepMsgText, InputHints.ExpectingInput);
                var retryText       = $"Please choose one option.\n\n{SexStepMsgText}";
                var retryPromptText = MessageFactory.Text(retryText, retryText, InputHints.ExpectingInput);
                //return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);

                var sexChoice = new List <Choice>()
                {
                    new Choice("Male"), new Choice("Female")
                };

                return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions { Prompt = promptMessage, Choices = sexChoice, RetryPrompt = retryPromptText, Style = ListStyle.HeroCard }, cancellationToken));
            }

            return(await stepContext.NextAsync(PersonalDetails.Sex, cancellationToken));
        }
Beispiel #6
0
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Send a message the this questionnaire has already been finished
            if (finishedBefore)
            {
                var finishedText        = MainDialog.Response.FinishedQuestionnaire();
                var finishedTextMessage = MessageFactory.Text(finishedText, finishedText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(finishedTextMessage, cancellationToken);
            }

            if (finished)
            {
                await CalculatePersonalityTraitsAsync();

                string tip = await MainDialog.Response.TipMessageAsync();

                MainDialog.WriteToDB(stepContext, cancellationToken);

                var resultCard = CreateAdaptiveCardAttachment();
                var response   = MessageFactory.Attachment(resultCard /*, ssml: "Here are your results!"*/);
                await stepContext.Context.SendActivityAsync(response, cancellationToken);

                // Show results
                //var resultsText = /*$"Here are your results!\n\nExtraversion: {PersonalDetailsDialog.PersonalDetails.Extraversion}\n\nAgreeableness: {PersonalDetailsDialog.PersonalDetails.Agreeableness}\n\nConscientiousness: {PersonalDetailsDialog.PersonalDetails.Conscientiousness}\n\nNeuroticism: {PersonalDetailsDialog.PersonalDetails.Neuroticism}\n\nOpenness: {PersonalDetailsDialog.PersonalDetails.Openness}\n\nCLUSTER: {PersonalDetailsDialog.PersonalDetails.Cluster}\n\n{tip}"*/$"CLUSTER: {PersonalDetailsDialog.PersonalDetails.Cluster}\n\n{tip}";
                //var resultsTextMessage = MessageFactory.Text(resultsText, resultsText, InputHints.IgnoringInput);
                //await stepContext.Context.SendActivityAsync(resultsTextMessage, cancellationToken);

                // Resseting the flag, in case new user comes
                finished       = false;
                finishedBefore = true;
                return(await stepContext.EndDialogAsync(PersonalDetailsDialog.PersonalDetails, cancellationToken));
            }
            else
            {
                //PersonalDetailsDialog.PersonalDetails.QuestionnaireAnswers.Add(new KeyValuePair<string, string>(activeQuestion, ((FoundChoice)stepContext.Result).Value));
                // Adding 1 to the answers index because it starts from 0
                PersonalDetailsDialog.PersonalDetails.QuestionnaireAnswers.Add(activeQuestion, ++((FoundChoice)stepContext.Result).Index);
                MainDialog.WriteToDB(stepContext, cancellationToken);

                return(await stepContext.BeginDialogAsync(nameof(TopFiveDialog), PersonalDetailsDialog.PersonalDetails, cancellationToken));
            }
        }
        private async Task <DialogTurnResult> SmokerStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (PersonalDetails.Sex == null)
            {
                PersonalDetails.Sex = ((FoundChoice)stepContext.Result).Value;
            }

            // Sand to DB
            MainDialog.WriteToDB(stepContext, cancellationToken);

            if (PersonalDetails.Smoker == null)
            {
                var messageText   = MainDialog.Response.AskSmoker();
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync(PersonalDetails, cancellationToken));
            }
        }
        private async Task <DialogTurnResult> PhysicalActivityStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (PersonalDetails.Sleep == null)
            {
                PersonalDetails.Sleep = (int)stepContext.Result;
            }

            // Sand to DB
            MainDialog.WriteToDB(stepContext, cancellationToken);

            if (PersonalDetails.PhysicalActivity == null)
            {
                var messageText     = MainDialog.Response.AskPhysicalActivity();
                var promptMessage   = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                var retryText       = MainDialog.Response.RetryPhysycalActivity();
                var retryPromptText = MessageFactory.Text(retryText, retryText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(NumberPrompt <int>), new PromptOptions { Prompt = promptMessage, RetryPrompt = retryPromptText }, cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync(PersonalDetails, cancellationToken));
            }
        }
Beispiel #9
0
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var result = JsonConvert.DeserializeObject <Tip>(stepContext.Result.ToString());

            NumberOfTipsDialog.TipsUploadList.Add(NullifyFalseValues(result));

            if (--NumberOfTipsDialog.NumberOfTips == 0)
            {
                // Send to database
                MainDialog.SendTipsToDB(NumberOfTipsDialog.TipsUploadList, stepContext, cancellationToken);

                // Show uploading message to the user
                var MsgText       = MainDialog.Response.UploadingDataMessage();
                var promptMessage = MessageFactory.Text(MsgText, MsgText, InputHints.ExpectingInput);
                await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);

                return(await stepContext.EndDialogAsync(PersonalDetailsDialog.PersonalDetails, cancellationToken));
            }
            else
            {
                return(await stepContext.BeginDialogAsync(nameof(UploadTipsDialog), NumberOfTipsDialog.NumberOfTips, cancellationToken));
            }
        }
Beispiel #10
0
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var result = JsonConvert.DeserializeObject <QuestionJSON>(stepContext.Result.ToString());


            NameOfQuestionnaireDialog.QuestionnaireToUpload.Add(ConvertToQuestionTopFive(result));

            if (--NameOfQuestionnaireDialog.NumberOfQuestionsInQuestionnaire == 0)
            {
                // Send to database
                MainDialog.SendQuestionnairesToDB(NameOfQuestionnaireDialog.NameOfQuestionnaire, NameOfQuestionnaireDialog.QuestionnaireToUpload, stepContext, cancellationToken);

                // Show uploading message to the user
                var MsgText       = MainDialog.Response.UploadingDataMessage();
                var promptMessage = MessageFactory.Text(MsgText, MsgText, InputHints.ExpectingInput);
                await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken);

                return(await stepContext.EndDialogAsync(PersonalDetailsDialog.PersonalDetails, cancellationToken));
            }
            else
            {
                return(await stepContext.BeginDialogAsync(nameof(UploadQuestionnairesDialog), NameOfQuestionnaireDialog.NumberOfQuestionsInQuestionnaire, cancellationToken));
            }
        }
        // Begin EndConversation Dialog-Flow
        public EndConversationDialog(ConversationRecognizer luisRecognizer, ILogger <EndConversationDialog> logger, MainDialog mainDialog, ConversationState conversationState)
            : base(nameof(EndConversationDialog))

        {
            ConversationState = conversationState;
            _luisRecognizer   = luisRecognizer;
            Logger            = logger;
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(mainDialog);
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                IntroStepAsync,
                EndStepAsync,
            }));
            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        //  Lecturer Dialog Class
        public LecturerDialog(ConversationRecognizer luisRecognizer, ILogger <LecturerDialog> logger, MainDialog mainDialog, EndConversationDialog endConversationDialog, ExtracurricularDialog extracurricularDialog)
            : base(nameof(LecturerDialog))

        {
            _luisRecognizer = luisRecognizer;
            Logger          = logger;
            // Dialog flow
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(endConversationDialog);
            AddDialog(extracurricularDialog);
            AddDialog(mainDialog);
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                IntroStepAsync,
                GetInfoAsync,
                infoAsync,
                GetAnswerAsync,
            }));
            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
Beispiel #13
0
        private async Task CalculatePersonalityTraitsAsync()
        {
            List <int> extraversionList = new List <int>(), agreeablenessList = new List <int>(), conscientiousnessList = new List <int>(), neuroticismList = new List <int>(), opennessList = new List <int>();
            int        score;

            var questionnairesNames = new List <string>();

            foreach (KeyValuePair <string, List <QuestionTopFive> > kvp in MainDialog.Response.Questionnaires)
            {
                questionnairesNames.Add(kvp.Key);
            }

            foreach (string name in questionnairesNames)
            {
                //List<QuestionTopFive> questionnaire = MainDialog.Response.Questionnaires.Where(kvp => kvp.Key == name); //MainDialog.Response.Questionnaires[name];
                List <QuestionTopFive> questionnaire = (from kvp in MainDialog.Response.Questionnaires where kvp.Key == name select kvp.Value).FirstOrDefault();

                foreach (QuestionTopFive obj in questionnaire)
                {
                    if (PersonalDetailsDialog.PersonalDetails.QuestionnaireAnswers.ContainsKey(obj.Question))
                    {
                        if (obj.reverseLogic)
                        {
                            // Adding 1 because Count() returns 5 and not 6
                            score = obj.Answers.Count() + 1 - PersonalDetailsDialog.PersonalDetails.QuestionnaireAnswers[obj.Question];
                        }
                        else
                        {
                            score = PersonalDetailsDialog.PersonalDetails.QuestionnaireAnswers[obj.Question];
                        }

                        switch (obj.personalityTrait)
                        {
                        case Extraversion:
                            extraversionList.Add(score);
                            break;

                        case Agreeableness:
                            agreeablenessList.Add(score);
                            break;

                        case Conscientiousness:
                            conscientiousnessList.Add(score);
                            break;

                        case Neuroticism:
                            neuroticismList.Add(score);
                            break;

                        case Openness:
                            opennessList.Add(score);
                            break;
                        }
                    }
                }
            }

            if (extraversionList.Count() > 0)
            {
                PersonalDetailsDialog.PersonalDetails.Extraversion = (float)extraversionList.Average();
            }
            if (agreeablenessList.Count() > 0)
            {
                PersonalDetailsDialog.PersonalDetails.Agreeableness = (float)agreeablenessList.Average();
            }
            if (conscientiousnessList.Count() > 0)
            {
                PersonalDetailsDialog.PersonalDetails.Conscientiousness = (float)conscientiousnessList.Average();
            }
            if (neuroticismList.Count() > 0)
            {
                PersonalDetailsDialog.PersonalDetails.Neuroticism = (float)neuroticismList.Average();
            }
            if (opennessList.Count() > 0)
            {
                PersonalDetailsDialog.PersonalDetails.Openness = (float)opennessList.Average();
            }

            // Start the clustering procedure
            PersonalDetailsDialog.PersonalDetails.Cluster = await MainDialog.ClusteringAsync();
        }