private void RefreshCategories() { categoriesListView.Items.Clear(); Dictionary <string, CategoryStats> stats = new Dictionary <string, CategoryStats>(); double totalShareOfAll = 0; double centerNom = 0; double centerDen = 0; foreach (var summary in ActivityTracker.SelectedLog) { int k = 0; foreach (var entry in summary.Entries) { string category = RuleManager.MatchCategory(entry); if (stats.ContainsKey(category) == false) { stats[category] = new CategoryStats(); } stats[category].TotalActiveTime += Parameters.LogTimeUnit * entry.Share / 100.0; if (k++ == 0) { stats[category].TotalPresentTime += Parameters.LogTimeUnit; } stats[category].ShareSum += entry.Share; totalShareOfAll += entry.Share; } centerNom += summary.TimePoint.TimeOfDay.TotalMinutes * summary.TotalShare; centerDen += summary.TotalShare; } TimeSpan center = TimeSpan.FromMinutes(centerNom / (centerDen + 0.01)); TimeSpan totalSpan; if (ActivityTracker.SelectedLog.Count == 0) { totalSpan = TimeSpan.Zero; } else { totalSpan = ActivityTracker.SelectedLog.Last().TimePoint - ActivityTracker.SelectedLog.First().TimePoint; } List <KeyValuePair <string, CategoryStats> > statsList = stats.ToList(); statsList.Sort((a, b) => (int)(1000 * (b.Value.ShareSum - a.Value.ShareSum))); TimeSpan totalActiveTime = TimeSpan.Zero; TimeSpan totalPresentTime = TimeSpan.Zero; foreach (var skv in statsList) { string name = skv.Key; CategoryStats cs = skv.Value; TimeSpan activeTime = TimeSpan.FromSeconds(cs.TotalActiveTime); TimeSpan presentTime = TimeSpan.FromSeconds(cs.TotalPresentTime); string[] content = new string[] { name, activeTime.ToString(), presentTime.ToString(), (100.0 * cs.ShareSum / totalShareOfAll).ToString("F1") }; ListViewItem item = new ListViewItem(content); categoriesListView.Items.Add(item); totalActiveTime += activeTime; totalPresentTime += presentTime; } { string[] content = new string[] { "Total Time", totalActiveTime.ToString(), totalPresentTime.ToString(), "100.0" }; ListViewItem item = new ListViewItem(content); item.Font = boldFont; categoriesListView.Items.Add(item); } { double intensityActive = totalSpan.TotalSeconds >= 1 ? (100.0 * totalActiveTime.TotalSeconds / totalSpan.TotalSeconds) : 0; double intensityPresent = totalSpan.TotalSeconds >= 1 ? (100.0 * totalPresentTime.TotalSeconds / totalSpan.TotalSeconds) : 0; string[] content = new string[] { "Intensity", intensityActive.ToString("F2"), intensityPresent.ToString("F2") }; ListViewItem item = new ListViewItem(content); item.Font = boldFont; categoriesListView.Items.Add(item); } { string[] content = new string[] { "Total Span", totalSpan.ToString() }; ListViewItem item = new ListViewItem(content); item.Font = boldFont; categoriesListView.Items.Add(item); } { string[] content = new string[] { "Intensity Center", center.ToString(@"hh\:mm\:ss") }; ListViewItem item = new ListViewItem(content); item.Font = boldFont; categoriesListView.Items.Add(item); } }
public void SetCategory() { Category = RuleManager.MatchCategory(this); CategoryIndex = RuleManager.Categories.IndexOf(Category); }