예제 #1
0
        private async Task <DialogTurnResult> StartDialogAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            Debug.WriteLine("in root");
            bool userExists = SaveConversationData.CheckUserExists(stepContext.Context.Activity.From.Id);

            // check if user is new (if so, send welcome message)
            if (!userExists)
            {
                AddDialog(new WelcomeDialog(userState));
                return(await stepContext.BeginDialogAsync(nameof(WelcomeDialog)));
            }
            else
            {
                UserDataCollection user = SaveConversationData.GetUserDataCollection(stepContext.Context.Activity.From.Id).Result;
                await _userStateAccessor.SetAsync(stepContext.Context, user);

                Debug.WriteLine("sending to how 1");
                AddDialog(new HowAreYou(userState));
                return(await stepContext.ReplaceDialogAsync(nameof(HowAreYou)));
            }
        }
예제 #2
0
        private async Task <DialogTurnResult> CheckCourses(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            UserDataCollection user = await SaveConversationData.GetUserDataCollection(stepContext.Context.Activity.From.Id);

            List <UserCourse> courses        = user.PastCourses;
            UserCourse        current_course = new UserCourse();
            Random            rnd            = new Random();
            int  start  = user.PastCourses.Count - 1;
            int  random = 0;
            bool found  = false;

            while (start >= 0)
            {
                random         = rnd.Next(0, start);
                current_course = courses[random];
                courses.RemoveAt(random);
                courses.Add(current_course);
                start--;
                DateTime now  = DateTime.Now;
                TimeSpan diff = now - current_course.Date;

                if (!current_course.InProgress && !current_course.Taken && !current_course.Queried && diff.TotalDays >= 700)
                {
                    found = true;

                    break;
                }
            }

            if (found)
            {
                // return await stepContext.BeginDialogAsync(nameof(CheckCourseDialog));
                // stepContext.ActiveDialog.State["stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                // return await stepContext.NextAsync();
            }

            return(await stepContext.NextAsync());
        }
예제 #3
0
        private async Task <DialogTurnResult> StartAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            UserDataCollection user = await SaveConversationData.GetUserDataCollection(stepContext.Context.Activity.From.Id);

            UserDataCollection userProfile = await _userStateAccessor.GetAsync(stepContext.Context, () => new UserDataCollection());

            string            language     = userProfile.language;
            List <CourseList> course       = new List <CourseList>();
            List <string>     interest     = user.interests;
            List <UserCourse> past_courses = user.PastCourses;

            if (past_courses.Count > 0)
            {
                string[] course_to_sub = CourseToInterest(past_courses);

                interest.AddRange(course_to_sub);
            }

            if (interest.Count == 0)
            {
                // If no interest present, then recommend the most populaar course (or random course)
                // RecommendMostPopular();
                // return;
            }


            Random rnd = new Random();

            int restrictive = 0;
            List <CourseList> course_current = new List <CourseList>();

            // make sure all interests have a chance to be checked for courses
            // we will cull the list down later at random so it doesn't get too long for the user
            for (int i = 0; i < interest.Count; i++)
            {
                // only select element from all the 'live' elements
                int index = rnd.Next(i, interest.Count);

                string current_interest = interest[index];
                // if an interest has been 'used' move to the front of list, element is now dead and will not be considered by the rng
                interest.Insert(0, interest[index]);
                interest.RemoveAt(index + 1);

                course_current = SaveConversationData.TryMatchCourse(current_interest, user.accreditation, user.delivery, true, user.PreferedLang, user.education, restrictive);

                course.AddRange(course_current);

                if (i == interest.Count - 1 && course.Count == 0)
                {
                    if (restrictive == 3)
                    {
                        // we've had 3 failed passes, give up without finding any courses
                        // later we should instead recommend the most popular course (collabartive filtering)

                        break;
                    }
                    // first 'pass' has failed to find any courses, start a new 'pass' with less restrictive parameters
                    i = 0;
                    i--; // cancel out the i++
                    restrictive++;
                }
            }

            course = ReduceLength(course);

            // string language = context.UserData.GetValue<string>("inputLanguage");
            if (course.Count == 0)
            {
                //RecommendMostPopular();
                await stepContext.Context.SendActivityAsync(MessageFactory.Text("Sorry, I couldn't find any courses for you, but you can look through all the topics and subtopics I know about if you like."));

                //context.Done(true);
            }
            else
            {
                string text = "Based on some of the preferences you have shared with me, here are all the courses I think you might like";
                if (restrictive != 0)
                {
                    await stepContext.Context.SendActivityAsync(MessageFactory.Text("I couldn't find any courses that exactly matched you preferences so I had to leave out the following preferences during my search: "));

                    switch (restrictive)
                    {
                    case 1:
                        await stepContext.Context.SendActivityAsync("\u2022 Your education level");

                        goto case 2;

                    case 2:
                        await stepContext.Context.SendActivityAsync("\u2022 Your prefered language");

                        goto case 3;

                    case 3:
                        await stepContext.Context.SendActivityAsync("\u2022 Your self paced preference");

                        break;

                    default:
                        break;
                    }
                }
                // var reply = context.MakeMessage();

                var reply = stepContext.Context.Activity.CreateReply();
                List <CardAction> course_suggestions = new List <CardAction>();
                for (int i = 0; i < course.Count; i++)
                {
                    if (course[i] == null)
                    {
                        break;
                    }

                    if (language.ToLower() == "english")
                    {
                        course_suggestions.Add(new CardAction()
                        {
                            Title = course[i].courseName, Type = ActionTypes.ImBack, Value = course[i].courseName
                        });
                    }
                    else
                    {
                        course_suggestions.Add(new CardAction()
                        {
                            Title = course[i].courseNameArabic, Type = ActionTypes.ImBack, Value = course[i].courseNameArabic
                        });
                    }
                }
                if (language.ToLower() == "english")
                {
                    reply.Text = "Based on some of the preferences you have shared with me, here are all the courses I think you might like";
                    course_suggestions.Add(new CardAction()
                    {
                        Title = "Start Over", Type = ActionTypes.ImBack, Value = "Start Over"
                    });
                }
                else
                {
                    reply.Text = "استنادًا إلى بعض التفضيلات التي قمت بمشاركتها معي ، إليك جميع الدورات التدريبية التي قد تعجبك";
                    course_suggestions.Add(new CardAction()
                    {
                        Title = "ابدأ من جديد", Type = ActionTypes.ImBack, Value = "ابدأ من جديد"
                    });
                }
                reply.SuggestedActions = new SuggestedActions()
                {
                    Actions = course_suggestions
                };
                await stepContext.Context.SendActivityAsync(reply);
            }

            return(await stepContext.EndDialogAsync());
        }