Example #1
0
        public string Summarize(DateTime startDate, DateTime endDate)
        {
            // add an overall summary
            List <LifeSummaryItem> components = new List <LifeSummaryItem>();
            List <Participation>   containedParticipations = this.engine.ActivityDatabase.RootActivity.getParticipationsSince(startDate);

            // summarize some individual participations
            List <Participation> sampleParticipations = this.chooseRandomParticipations(containedParticipations, 80);

            foreach (Participation participation in sampleParticipations)
            {
                components.Add(this.summarizeParticipation(participation));
            }
            // find the most interesting summaries and remove the rest
            components.Sort(new LifeSummaryItem_InterestComparer());
            components.Reverse();
            int maxCount = 20;

            if (components.Count > maxCount)
            {
                components = components.GetRange(0, maxCount);
            }
            // reorder the summaries based on the order we want to display them
            components.Sort(new LifeSummaryItem_DateComparer());

            // compute very brief summary
            List <string> texts = new List <string>();

            texts.Add(this.EvaluateQualityOfLife(engine, startDate, endDate).text);
            // join all the summaries with newlines
            LifeSummaryItem previousItem = null;

            foreach (LifeSummaryItem item in components)
            {
                texts.Add(this.summaryWithConnector(item, previousItem));
                previousItem = item;
            }
            texts.Add("Sincerely, " + persona.Name);
            return(string.Join("\n\n", texts));
        }
Example #2
0
        private string summaryWithConnector(LifeSummaryItem item, LifeSummaryItem prev)
        {
            if (prev == null)
            {
                return(item.text);
            }

            List <String> happinessConnectors = new List <string>();

            double baseline    = 0.5;
            bool   prevGood    = prev.happiness >= baseline;
            bool   currentGood = item.happiness >= baseline;

            // If the user did something sad followed by something happy, we can say "X was mediocre. However, Y was great!"
            if (prevGood != currentGood)
            {
                happinessConnectors.Add("However");
            }

            List <String> temporalConnectors = new List <string>();
            TimeSpan      timeBetween        = item.startDate.Subtract(prev.endDate);
            // both events occurred on the same day
            bool overlapping  = prev.endDate.CompareTo(item.startDate) > 0;
            int  numDaysLater = (int)(item.startDate.Date.Subtract(prev.endDate.Date).TotalDays + 0.5);

            if (overlapping)
            {
                temporalConnectors.Add("Meanwhile");
                temporalConnectors.Add("At the same time");
            }
            else
            {
                if (timeBetween.CompareTo(TimeSpan.FromMinutes(5)) < 0)
                {
                    temporalConnectors.Add("Then");
                    temporalConnectors.Add("Next");
                    temporalConnectors.Add("After that");
                }
                else
                {
                    if (timeBetween.CompareTo(TimeSpan.FromHours(1)) < 0)
                    {
                        temporalConnectors.Add("A little while later");
                        temporalConnectors.Add("Not long after that");
                        if (numDaysLater == 0)
                        {
                            temporalConnectors.Add("Later that day");
                        }
                        else
                        {
                            temporalConnectors.Add("Then, a little bit after midnight");
                        }
                    }
                    else
                    {
                        if (numDaysLater == 0)
                        {
                            temporalConnectors.Add("Later that day");
                        }
                        else if (numDaysLater == 1)
                        {
                            temporalConnectors.Add("The next day");
                        }
                        else if (numDaysLater == 2)
                        {
                            temporalConnectors.Add("A couple days later");
                        }
                        else if (numDaysLater < 5)
                        {
                            temporalConnectors.Add("A few days later");
                        }
                        else if (numDaysLater < 10)
                        {
                            temporalConnectors.Add("About a week later");
                        }
                        else if (numDaysLater < 18)
                        {
                            temporalConnectors.Add("A couple weeks later");
                        }
                        else if (numDaysLater < 40)
                        {
                            temporalConnectors.Add("About a month later");
                        }
                        else if (numDaysLater < 80)
                        {
                            temporalConnectors.Add("A couple months later");
                        }
                        else if (numDaysLater < 120)
                        {
                            temporalConnectors.Add("A few months later");
                        }
                    }
                }
            }

            string connector = "";

            if (happinessConnectors.Count > 0 && this.generator.NextDouble() < 0.33)
            {
                connector = this.randomString(happinessConnectors) + ", ";
            }
            else
            {
                if (temporalConnectors.Count > 0 && this.generator.NextDouble() < 0.33)
                {
                    connector += this.randomString(temporalConnectors) + ", ";
                }
            }

            string summary = connector + item.text;

            return(summary);
        }