private void okClicked() { if (!this.durationLayout.IsDurationValid()) { return; } TimeSpan windowSize = this.durationLayout.GetDuration(); DateTime windowEnd = DateTime.Now; DateTime windowStart = windowEnd.Subtract(windowSize); Activities_HappinessContributions activities = this.engine.GetMostSignificantRecentActivities(windowStart, 12); this.showResults(activities, windowStart, windowEnd); }
private void showResults(Activities_HappinessContributions contributions, DateTime start, DateTime end) { // title string title = "" + (contributions.Best.Count + contributions.Worst.Count) + " Activities adding or subtracting the most happiness from " + start + " to " + end; BoundProperty_List heights = new BoundProperty_List(4); heights.BindIndices(1, 3); GridLayout grid = GridLayout.New(heights, new BoundProperty_List(1), LayoutScore.Zero); grid.AddLayout(new TextblockLayout(title)); // contents GridLayout_Builder topBuilder = new Vertical_GridLayout_Builder().Uniform(); // Show the top activities from best to worst for (int i = 0; i < contributions.Best.Count; i++) { ActivityHappinessContribution item = contributions.Best[i]; topBuilder.AddLayout(this.renderContribution("top " + (i + 1) + ": ", item, start)); } grid.AddLayout(ScrollLayout.New(topBuilder.BuildAnyLayout())); // Use the help button as the divider between the best and worst activities LayoutChoice_Set helpWindow = new HelpWindowBuilder() .AddMessage("Activities that you like more than average are accompanied by positive numbers.") .AddMessage("Activities that you like less than average are accompanied by negative numbers.") .AddMessage("Activities that you participated in for more total time are accompanied by numbers that are further from 0.") .AddMessage("Specifically, each of these numbers is calculated by looking at all of the participations in that activity during this time, " + "computing the difference between the happiness of that participation and your overall average happiness, " + "multiplying each by the duration of its participation, and adding up the results.") .Build(); grid.AddLayout(new HelpButtonLayout("?", helpWindow, this.layoutStack)); GridLayout_Builder bottomBuilder = new Vertical_GridLayout_Builder().Uniform(); // Show the bottom activities, also from best to worst for (int i = contributions.Worst.Count - 1; i >= 0; i--) { bottomBuilder.AddLayout(this.renderContribution("bottom " + (i + 1) + ": ", contributions.Worst[i], start)); } grid.AddLayout(bottomBuilder.BuildAnyLayout()); this.layoutStack.AddLayout(grid, "Significant Activities"); }