Example #1
0
        private void RefreshSummary(DateTime start, TimeSpan timeSpan)
        {
            summaryListView.Items.Clear();
            Dictionary <ActivityId, ActivityDaySummary> summaryItems = new Dictionary <ActivityId, ActivityDaySummary>();

            foreach (var summary in ActivityTracker.SelectedLog.Activities)
            {
                bool isFirst = true;
                foreach (var entry in summary.Entries)
                {
                    ActivityId id = new ActivityId
                    {
                        ProcessName      = entry.App.Path,
                        ApplicationTitle = entry.ApplicationTitle,
                        WindowTitle      = entry.WindowTitle
                    };

                    if (summaryItems.ContainsKey(id) == false)
                    {
                        summaryItems[id] =
                            new ActivityDaySummary
                        {
                            App = entry.App,
                            ApplicationTitle = entry.ApplicationTitle,
                            WindowTitle      = "",  // ignored in day summary
                            DocumentName     = entry.DocumentName
                        };
                    }
                    summaryItems[id].TotalTime += Parameters.LogTimeUnit * entry.Share / 100.0;
                    if (isFirst)
                    {
                        summaryItems[id].TopTime += Parameters.LogTimeUnit;
                    }
                    isFirst = false;
                }
            }

            List <ActivityDaySummary> summaryList1 = summaryItems.Values.ToList();

            summaryList1.Sort((a, b) => a.App.Name.CompareTo(b.App.Name));

            List <ActivityDaySummary> summaryList2 = new List <ActivityDaySummary>();

            // merge
            // FIXME: O(n^2) within an application
            bool[] done = new bool[summaryList1.Count];
            for (int i = 0; i < summaryList1.Count; ++i)
            {
                if (done[i] == false)
                {
                    string thisApp      = summaryList1[i].App.Name;
                    string thisTitle    = summaryList1[i].ApplicationTitle;
                    string thisDocument = summaryList1[i].ValidDocumentName;
                    string commonTitle;

                    ActivityDaySummary newSummary = summaryList1[i];

                    for (int j = i + 1; j < summaryList1.Count; ++j)
                    {
                        if (summaryList1[j].App.Name != thisApp)
                        {
                            break;
                        }
                        if (summaryList1[j].ValidDocumentName == thisDocument &&
                            ActivityTracker.AreTitlesNearlyEqual(summaryList1[j].ApplicationTitle, thisTitle, out commonTitle))
                        {
                            thisTitle = commonTitle;
                            newSummary.ApplicationTitle = commonTitle;
                            newSummary.TotalTime       += summaryList1[j].TotalTime;
                            newSummary.TopTime         += summaryList1[j].TopTime;
                            done[j] = true;
                        }
                    }
                    summaryList2.Add(newSummary);
                }
            }

            summaryList2.Sort((a, b) => (int)(a.TopTime != b.TopTime ? b.TopTime - a.TopTime : b.TotalTime - a.TotalTime));

            TimeSpan totalTime = TimeSpan.Zero;

            try
            {
                summaryListView.BeginUpdate();

                foreach (var ads in summaryList2)
                {
                    TimeSpan span    = TimeSpan.FromSeconds(ads.TotalTime);
                    TimeSpan topSpan = TimeSpan.FromSeconds(ads.TopTime);
                    string[] content = new string[]
                    {
                        ads.App.Name,
                        ads.ApplicationTitle,
                        ads.Subtitle,
                        span.ToString(),
                        topSpan.ToString()
                    };
                    ListViewItem item = new ListViewItem(content, GetIconIndex(ads.App));
                    summaryListView.Items.Add(item);
                    totalTime += span;
                }
            }
            finally
            {
                summaryListView.EndUpdate();
            }
        }
Example #2
0
        private void RefreshSummary(DateTime start, TimeSpan timeSpan)
        {
            summaryListView.Items.Clear();
            Dictionary <ActivityId, ActivityDaySummary> summaryItems = new Dictionary <ActivityId, ActivityDaySummary>();

            foreach (var summary in ActivityTracker.SelectedLog.Activities)
            {
                bool isFirst = true;
                foreach (var entry in summary.Entries)
                {
                    ActivityId id = new ActivityId
                    {
                        ProcessName      = entry.App.Path,
                        ApplicationTitle = entry.ApplicationTitle
                    };

                    if (summaryItems.ContainsKey(id) == false)
                    {
                        summaryItems[id] =
                            new ActivityDaySummary
                        {
                            App = entry.App,
                            ApplicationTitle = entry.ApplicationTitle,
                            DocumentUrl      = entry.DocumentUrl
                        };
                    }
                    summaryItems[id].TotalTime += Parameters.LogTimeUnit * entry.Share / 100.0;
                    if (isFirst)
                    {
                        summaryItems[id].TopTime += Parameters.LogTimeUnit;
                    }
                    isFirst = false;
                }
            }

            List <ActivityDaySummary> summaryList1 = summaryItems.Values.ToList();

            summaryList1.Sort((a, b) => a.App.Name.CompareTo(b.App.Name));

            List <ActivityDaySummary> summaryList2 = new List <ActivityDaySummary>();

            // merge
            // FIXME: O(n^2) within an application
            bool[] done = new bool[summaryList1.Count];
            Dictionary <string, double> leaderTime = new Dictionary <string, double>();

            if (mergeSecondary)
            {
                for (int i = 0; i < summaryList1.Count; ++i)
                {
                    if (summaryList1[i].TopTime == 0)
                    {
                        if (summaryList1[i].DocumentUrl != "")
                        {
                            summaryList1[i].DocumentUrl = summaryList1[i].ValidDocumentSite + "/...";
                        }
                        summaryList1[i].ApplicationTitle = "(Other)";
                    }
                }
            }

            for (int i = 0; i < summaryList1.Count; ++i)
            {
                string thisProcess      = summaryList1[i].App.Name;
                string thisDocumentUrl  = summaryList1[i].ValidDocumentUrl;
                string thisDocumentSite = summaryList1[i].ValidDocumentSite;

                if (done[i] == false)
                {
                    string thisTitle = summaryList1[i].ApplicationTitle;

                    ActivityDaySummary newSummary = summaryList1[i].Clone();

                    for (int j = i + 1; j < summaryList1.Count; ++j)
                    {
                        if (summaryList1[j].App.Name != thisProcess)
                        {
                            break;
                        }

                        string commonTitle;
                        if (summaryList1[j].ValidDocumentSite == thisDocumentSite &&
                            ActivityTracker.AreTitlesNearlyEqual(summaryList1[j].ApplicationTitle, thisTitle, out commonTitle))
                        {
                            thisTitle       = commonTitle;
                            thisDocumentUrl = ActivityTracker.CommonUrlPart(thisDocumentUrl, summaryList1[j].DocumentUrl);

                            newSummary.ApplicationTitle = commonTitle;
                            newSummary.DocumentUrl      = thisDocumentUrl;
                            newSummary.TotalTime       += summaryList1[j].TotalTime;
                            newSummary.TopTime         += summaryList1[j].TopTime;

                            done[j] = true;
                        }
                    }
                    summaryList2.Add(newSummary);

                    string leaderName = (thisDocumentSite != "" ? thisDocumentSite : thisProcess);

                    if (leaderName != "")
                    {
                        if (leaderTime.ContainsKey(leaderName) == false ||
                            leaderTime[leaderName] < newSummary.TopTime * 100 + newSummary.TotalTime)
                        {
                            leaderTime[leaderName] = newSummary.TopTime * 100 + newSummary.TotalTime;
                        }
                    }
                }
            }

            summaryList2.Sort((a, b) =>
            {
                double leaderTimeA = a.TopTime * 100 + a.TotalTime;
                double leaderTimeB = b.TopTime * 100 + b.TotalTime;

                string leaderNameA = (a.ValidDocumentSite != "" ? a.ValidDocumentSite : a.App.Name);
                string leaderNameB = (b.ValidDocumentSite != "" ? b.ValidDocumentSite : b.App.Name);

                if (leaderNameA != "")
                {
                    leaderTimeA = Math.Max(leaderTimeA, leaderTime[leaderNameA]);
                }
                if (leaderNameB != "")
                {
                    leaderTimeB = Math.Max(leaderTimeB, leaderTime[leaderNameB]);
                }

                return((int)(leaderTimeA != leaderTimeB ? leaderTimeB - leaderTimeA : a.TopTime != b.TopTime ? b.TopTime - a.TopTime : b.TotalTime - a.TotalTime));
            });

            TimeSpan totalTime = TimeSpan.Zero;

            try
            {
                summaryListView.BeginUpdate();

                foreach (var ads in summaryList2)
                {
                    TimeSpan span    = TimeSpan.FromSeconds(ads.TotalTime);
                    TimeSpan topSpan = TimeSpan.FromSeconds(ads.TopTime);
                    string[] content = new string[]
                    {
                        ads.App.Name,
                        ads.ApplicationTitle,
                        ads.ValidDocumentUrl,
                        span.ToString(),
                        topSpan != TimeSpan.Zero ? topSpan.ToString() : ""
                    };

                    Color color =
                        ads.TopTime >= 600.0 ? Color.Black :
                        ads.TopTime >= 300.0 ? Color.FromArgb(80, 80, 80) :
                        Color.FromArgb(160, 160, 160);

                    ListViewItem item = new ListViewItem(content, GetIconIndex(ads.App));
                    item.ForeColor = color;
                    summaryListView.Items.Add(item);
                    totalTime += span;
                }
            }
            finally
            {
                summaryListView.EndUpdate();
            }
        }