示例#1
0
 public override void PreviewSuggestion(ActivitiesSuggestion suggestion)
 {
     foreach (ActivitySuggestion child in suggestion.Children)
     {
         this.SuggestionDatabase.AddSuggestion(child);
     }
 }
 public bool CanMatch(ActivitiesSuggestion other)
 {
     foreach (ActivitySuggestion child in this.Children)
     {
         if (other.CanMatch(child.ActivityDescriptor))
         {
             return(true);
         }
     }
     return(false);
 }
        private void updateSuggestion()
        {
            ActivitySuggestion   suggestion;
            string               text    = null;
            ActivitiesSuggestion choices = this.engine.MakeRecommendation();

            if (choices != null)
            {
                suggestion = choices.Children[0];
                string name = suggestion.ActivityDescriptor.ActivityName;
                text = "How about " + name + "?";
                this.suggestedActivityName = name;
            }
            else
            {
                this.suggestedActivityName = null;
            }
            this.suggestionLayout.setText(text);
        }
        public LayoutChoice_Set MakeLayout(LayoutStack layoutStack)
        {
            Vertical_GridLayout_Builder builder = new Vertical_GridLayout_Builder();

            if (this.SuggestedBadIdea)
            {
                string apology;
                if (this.PredictedValue > 1)
                {
                    // A fun idea that we didn't expect the user to do
                    // We expected the user to get distracted while considering the fun idea
                    apology = "Sorry, I didn't expect you to actually do this! I thought that this suggestion would help you think of a better idea!";
                }
                else
                {
                    // An annoying idea that we didn't expect the user to do
                    // We expected the user to remember how annoying this was and to avoid it and things like it
                    apology = "Sorry, I didn't expect you to actually do this! I thought that this suggestion would remind you to look harder for something better!";
                }
                builder.AddLayout(new TextblockLayout(apology));
            }
            builder.AddLayout(new TextblockLayout(ChosenActivity.Name));
            builder.AddLayout(new TextblockLayout("From " + this.StartDate + " to " + this.EndDate + ", " + ParticipationDurationDividedByAverage + " as long as average. I predict:"));

            GridLayout_Builder nowBuilder = new Horizontal_GridLayout_Builder().Uniform();

            nowBuilder.AddLayout(
                new Vertical_GridLayout_Builder().Uniform()
                .AddLayout(
                    new HelpButtonLayout("Fun (vs average):",
                                         new TextblockLayout("This column shows the amount of happiness you are expected to have while doing this activity at this time, divided by the average amount of happiness you usually have doing other things"),
                                         layoutStack)
                    )
                .AddLayout(coloredRatio(PredictedValue, ComparisonPredictedValue, PredictedCurrentValueStddev))
                .Build()
                );
            nowBuilder.AddLayout(
                new Vertical_GridLayout_Builder().Uniform()
                .AddLayout(
                    new HelpButtonLayout("Future Fun (days):",
                                         new TextblockLayout("This column shows an estimate of the net present value of your happiness at this time after doing this activity, compared to what it usually is. " +
                                                             "This is very similar to computing how many days of happiness you will gain or lose over the next " + Math.Round(UserPreferences.DefaultPreferences.HalfLife.TotalDays / Math.Log(2), 0) +
                                                             " days after doing this."),
                                         layoutStack)
                    )
                .AddLayout(signedColoredValue(ExpectedFutureFun, ComparisonExpectedFutureFun, ExpectedFutureFunStddev))
                .Build()
                );
            nowBuilder.AddLayout(
                new Vertical_GridLayout_Builder().Uniform()
                .AddLayout(
                    new HelpButtonLayout("Future Efficiency (hours):",
                                         new TextblockLayout("This column shows an estimate of the net present value of your efficiency at this time after doing this activity, compared to what it usually is. " +
                                                             "This is very similar to computing how many hours of efficiency you will gain or lose over the next " + Math.Round(UserPreferences.DefaultPreferences.EfficiencyHalflife.TotalDays / Math.Log(2), 0) +
                                                             " days after doing this."),
                                         layoutStack)
                    )
                .AddLayout(signedColoredValue(ExpectedEfficiency, ComparisonExpectedEfficiency, ExpectedEfficiencyStddev))
                .Build()
                );
            builder.AddLayout(nowBuilder.Build());

            builder.AddLayout(new TextblockLayout("If you had done this at " + this.ComparisonDate + ":"));

            GridLayout_Builder laterBuilder = new Horizontal_GridLayout_Builder().Uniform();

            laterBuilder.AddLayout(coloredRatio(ComparisonPredictedValue, 1, 0));
            laterBuilder.AddLayout(signedColoredValue(ComparisonExpectedFutureFun, 1, 0));
            laterBuilder.AddLayout(signedColoredValue(ComparisonExpectedEfficiency, 0, 0));
            builder.AddLayout(laterBuilder.Build());

            ActivityRequest request = new ActivityRequest();

            request.ActivityToBeat = this.ChosenActivity.MakeDescriptor();
            request.Date           = this.StartDate;
            //request.RequestedProcessingTime = TimeSpan.FromSeconds(0.5);
            ActivitiesSuggestion suggestion       = this.engine.MakeRecommendation(request);
            Activity             betterActivity   = this.ActivityDatabase.ResolveDescriptor(suggestion.ActivityDescriptors[0]);
            Prediction           betterPrediction = this.engine.Get_OverallHappiness_ParticipationEstimate(betterActivity, request);
            string       redirectionText;
            Color        redirectionColor;
            Distribution betterFutureHappinessImprovementInDays = this.engine.compute_longtermValue_increase_in_days(betterPrediction.Distribution, this.StartDate, this.StartDate);
            double       improvementInDays = Math.Round(betterFutureHappinessImprovementInDays.Mean - this.ExpectedFutureFun, 1);

            if (improvementInDays <= 0)
            {
                string noIdeasText = "I don't have any better suggestions for things to do at this time.";
                if (ExpectedFutureFun >= 0)
                {
                    if (PredictedValue >= 1)
                    {
                        redirectionText = "Nice! " + noIdeasText; // Happy now, happy later
                    }
                    else
                    {
                        redirectionText = noIdeasText + " Sorry!"; // Happy later, not happy now
                    }
                }
                else
                {
                    if (PredictedValue >= 1)
                    {
                        redirectionText = noIdeasText; // Happy now, not happy later
                    }
                    else
                    {
                        redirectionText = "How about adding a new activity? " + noIdeasText; // Not happy now or later
                    }
                }
                redirectionColor = Color.Green;
            }
            else
            {
                string improvementText = improvementInDays.ToString();
                if (this.Suggested)
                {
                    redirectionText  = "I thought of a better idea: " + betterActivity.Name + ", better by +" + improvementText + " days fun. Sorry for not mentioning this earlier!";
                    redirectionColor = Color.Yellow;
                }
                else
                {
                    if (ExpectedFutureFun >= 0)
                    {
                        redirectionText  = "I suggest that " + betterActivity.Name + " would be even better: +" + improvementText + " days fun.";
                        redirectionColor = Color.Yellow;
                    }
                    else
                    {
                        redirectionText  = "I suggest that " + betterActivity.Name + " would improve your future happiness by " + improvementText + " days.";
                        redirectionColor = Color.Red;
                    }
                }
            }
            builder.AddLayout(new TextblockLayout(redirectionText, redirectionColor));


            return(builder.BuildAnyLayout());
        }
示例#5
0
        public override void PreviewSuggestion(ActivitiesSuggestion suggestion)
        {
            string text = this.textConverter.ConvertToString(suggestion);

            this.addText(text);
        }
示例#6
0
 public virtual void PreviewSuggestion(ActivitiesSuggestion suggestion)
 {
 }
示例#7
0
 public void AddSuggestion(ActivitiesSuggestion suggestion)
 {
     this.PreviewSuggestion(suggestion);
     this.engine.PutSuggestionInMemory(suggestion);
 }
示例#8
0
        public SuggestionView(ActivitiesSuggestion suggestion, bool isFirstSuggestion, Dictionary <ActivitySuggestion, bool> repeatingDeclinedSuggestion, LayoutStack layoutStack)
        {
            this.suggestion  = suggestion;
            this.layoutStack = layoutStack;

            bool allWorseThanAverage = true;

            foreach (ActivitySuggestion child in suggestion.Children)
            {
                if (!child.WorseThanRootActivity)
                {
                    allWorseThanAverage = false;
                }
            }

            GridLayout_Builder fullBuilder   = new Vertical_GridLayout_Builder();
            string             startTimeText = suggestion.Children[0].StartDate.ToString("HH:mm");

            bool badSuggestion = (allWorseThanAverage && suggestion.Skippable);

            if (badSuggestion)
            {
                fullBuilder.AddLayout(new TextblockLayout("Best ideas at " + startTimeText + ":", 24).AlignHorizontally(TextAlignment.Center));
            }
            else
            {
                fullBuilder.AddLayout(new TextblockLayout("At " + startTimeText + ":", 24).AlignHorizontally(TextAlignment.Center));
            }

            List <LayoutChoice_Set> specificFont_contentChoices = new List <LayoutChoice_Set>(); // list of layouts we might use, each with a different font size

            this.explainButtons = new Dictionary <Button, ActivitySuggestion>();
            this.doButtons      = new Dictionary <Button, ActivitySuggestion>();
            for (int mainFontSize = 20; mainFontSize >= 12; mainFontSize -= 8)
            {
                // grid containing the specific activities the user could do
                GridLayout activityOptionsGrid = GridLayout.New(new BoundProperty_List(3), BoundProperty_List.Uniform(suggestion.Children.Count), LayoutScore.Zero);

                for (int i = 0; i < suggestion.Children.Count; i++)
                {
                    ActivitySuggestion child = suggestion.Children[i];

                    // set up the options for the text
                    string          mainText  = this.summarize(child, repeatingDeclinedSuggestion[child]);
                    TextblockLayout mainBlock = new TextblockLayout(mainText, mainFontSize);
                    TextAlignment   horizontalAlignment;
                    TextAlignment   verticalAlignment;
                    if (i == 0)
                    {
                        horizontalAlignment = TextAlignment.Start;
                        if (suggestion.Children.Count == 1)
                        {
                            verticalAlignment = TextAlignment.Start;
                        }
                        else
                        {
                            verticalAlignment = TextAlignment.End;
                        }
                    }
                    else
                    {
                        if (i == suggestion.Children.Count - 1)
                        {
                            horizontalAlignment = TextAlignment.End;
                            verticalAlignment   = TextAlignment.Start;
                        }
                        else
                        {
                            horizontalAlignment = TextAlignment.Center;
                            verticalAlignment   = TextAlignment.Center;
                        }
                    }
                    mainBlock.AlignHorizontally(horizontalAlignment);
                    mainBlock.AlignVertically(verticalAlignment);
                    activityOptionsGrid.PutLayout(mainBlock, i, 0);

                    // set up the buttons
                    GridLayout_Builder buttonsBuilder = new Horizontal_GridLayout_Builder().Uniform();
                    double             buttonFontSize = mainFontSize * 0.9;
                    // make a doNow button if needed
                    if (isFirstSuggestion)
                    {
                        Button doNowButton = new Button();
                        doNowButton.Clicked        += DoNowButton_Clicked;
                        this.doButtons[doNowButton] = child;
                        ButtonLayout doButtonLayout = new ButtonLayout(doNowButton, "OK", buttonFontSize);
                        buttonsBuilder.AddLayout(doButtonLayout);
                    }
                    if (child.PredictedScoreDividedByAverage != null)
                    {
                        Button explainButton = new Button();
                        explainButton.Clicked += explainButton_Clicked;
                        this.explainButtons[explainButton] = child;
                        ButtonLayout explainLayout = new ButtonLayout(explainButton, "?", buttonFontSize);
                        buttonsBuilder.AddLayout(explainLayout);
                    }
                    activityOptionsGrid.PutLayout(buttonsBuilder.BuildAnyLayout(), i, 1);
                    if (child.ExpectedReaction != null)
                    {
                        TextblockLayout reactionLayout = new TextblockLayout(child.ExpectedReaction, buttonFontSize * 0.9);
                        reactionLayout.AlignHorizontally(horizontalAlignment);
                        reactionLayout.AlignVertically(verticalAlignment);
                        activityOptionsGrid.PutLayout(reactionLayout, i, 2);
                    }
                }

                LayoutChoice_Set optionsAtThisFontSize;
                if (badSuggestion)
                {
                    // If the suggestion is bad and we don't really want the user to do it, then we also show the user some convenient buttons for making more activities
                    GridLayout wrapper = GridLayout.New(new BoundProperty_List(1), BoundProperty_List.WithRatios(new List <double>()
                    {
                        suggestion.Children.Count, 1
                    }), LayoutScore.Zero);
                    wrapper.AddLayout(activityOptionsGrid);                            // activity suggestions
                    wrapper.AddLayout(this.make_otherActivities_layout(mainFontSize)); // layout for making new activities
                    optionsAtThisFontSize = wrapper;
                }
                else
                {
                    // If the suggestion isn't bad, then the options we give are just the activities being suggested
                    optionsAtThisFontSize = activityOptionsGrid;
                }
                specificFont_contentChoices.Add(optionsAtThisFontSize);
            }

            LayoutChoice_Set contentGrid = LayoutUnion.New(specificFont_contentChoices);

            // Add cancel buttons to the bottom
            this.cancelButton                         = new Button();
            this.cancelButton.Clicked                += cancelButton_Click;
            this.explainWhyYouCantSkipButton          = new Button();
            this.explainWhyYouCantSkipButton.Clicked += ExplainWhyYouCantSkipButton_Clicked;
            ButtonLayout cancelLayout;

            if (suggestion.Skippable)
            {
                cancelLayout = new ButtonLayout(this.cancelButton, "X");
            }
            else
            {
                cancelLayout = new ButtonLayout(this.explainWhyYouCantSkipButton, "!");
            }



            fullBuilder.AddLayout(contentGrid)
            .AddLayout(cancelLayout);

            this.SubLayout = fullBuilder.BuildAnyLayout();
        }