private void RecalculateTimeTotalsForActivity(TotalsForActivity summary) { if (!summary.HasChildren()) { // This is a leaf node. return; } var timeSpentPerDay = new TimeSpan[_numDays]; for (int i = 0; i < _numDays; i++) { timeSpentPerDay[i] = TimeSpan.Zero; } foreach (var child in summary.Children) { RecalculateTimeTotalsForActivity(child); for (int i = 0; i < _numDays; i++) { timeSpentPerDay[i] += child.TimeSpentPerPeriod[i]; } } summary.TimeSpentPerPeriod = timeSpentPerDay; }
private TotalsForActivity BuildSummaryForActivity(ActivityGroup activityGroup) { var summary = new TotalsForActivity(_numDays) { ActivityGroupId = activityGroup.Id, Key = "id|" + activityGroup.Id, Name = activityGroup.Name, Position = activityGroup.Position, ParentActivityGroupId = activityGroup.ParentId, TracksPollResponseText = !string.IsNullOrEmpty(activityGroup.MatchResponseText) }; var children = new List <TotalsForActivity>(); // Add this summary to the ResponseText lookup table. if (!string.IsNullOrEmpty(activityGroup.MatchResponseText)) { if (activityGroup.HasChildren()) { // We need to create another made-up activity group that represents the // exact ResponseText matches. var matchedResponseSummary = new TotalsForActivity(_numDays) { Key = "name|" + activityGroup.MatchResponseText, Name = activityGroup.MatchResponseText, Position = 0, TracksPollResponseText = true, TracksExactParentMatches = true }; _summariesByResponseText[activityGroup.MatchResponseText] = matchedResponseSummary; children.Add(matchedResponseSummary); } else { // This is a leaf node. _summariesByResponseText[activityGroup.MatchResponseText] = summary; } } // Populate the children if (activityGroup.HasChildren()) { foreach (var childGroup in activityGroup.Children) { var childSummary = BuildSummaryForActivity(childGroup); children.Add(childSummary); } } if (children.Any()) { summary.Children = children; } return(summary); }
public TotalsForActivity GetOrAddActivity(string responseText) { // Check if we've been this way already. _summariesByResponseText.TryGetValue(responseText, out var summary); if (summary != null) { return(summary); } // There is no activity group that matches this response text. // That means that the user has not categorized this activity yet. summary = new TotalsForActivity(_numDays) { Key = "name|" + responseText, Name = responseText, Position = 0, TracksPollResponseText = true }; _summariesByResponseText[responseText] = summary; _activities.Add(summary); return(summary); }