public ActionListViewItem(ActivityEntry entry, int imgIndex, ActivitySummary summary, ListViewItem header) { this.summary = summary; this.header = header; this.entry = entry; ImageIndex = imgIndex; ForeColor = entry.Share >= 20.0 ? Color.Black : entry.Share >= 10.0 ? Color.FromArgb(64, 64, 64) : Color.FromArgb(128, 128, 128); // Remove uneccesary extension var processedName = entry.App.Name.ToLower().Replace(".exe", ""); Text = processedName; /* process: */ AddColumn(entry.ApplicationTitle); /* title: */ AddColumn(entry.Subtitle); /* subtitle: */ AddColumn(entry.Share); /* share: */ AddColumn(entry.KeyboardIntensity); /* keyboard: */ AddColumn(entry.MouseIntensity); /* mouse: */ AddColumn(entry.Category); /* category: */ UseItemStyleForSubItems = false; for (int i = 0; i < SubItems.Count - 1; ++i) { SubItems[i].ForeColor = ForeColor; } SubItems[SubItems.Count - 1].ForeColor = Chart.GetColor(entry.CategoryIndex + 1); }
private static void LoadPart(GetAppDelegate getApp, string path, List <ActivitySummary> data, List <string> errorLines) { TextReader reader = new StreamReader(path); string header = reader.ReadLine(); // csv header bool hasSubtitle; bool hasDocument; if (header == "time;span;process;title;subtitle;document;share;keyboard-intensity;mouse-intensity;") { hasSubtitle = true; hasDocument = true; } else if (header == "time;span;process;title;subtitle;share;keyboard-intensity;mouse-intensity;") { hasSubtitle = true; hasDocument = false; } else if (header == "time;span;process;title;share;keyboard-intensity;mouse-intensity;") { hasSubtitle = false; hasDocument = false; } else { throw new ApplicationException("Incorrect log file format."); } int lineNumber = 0; ActivitySummary lastSummary = null; while (true) { string line = reader.ReadLine(); lineNumber++; if (line == null) { break; } try { List <string> parts = new List <string>(line.Split(new char[] { ';' })); while (parts.Count < 9) { parts.Add(""); } if (hasSubtitle == false) { parts[7] = parts[6]; parts[6] = parts[5]; parts[5] = parts[4]; parts[4] = ""; // subtitle } if (hasDocument == false) { parts[8] = parts[7]; parts[7] = parts[6]; parts[6] = parts[5]; parts[5] = parts[4]; parts[4] = ""; // document } CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); DateTimeStyles styles = DateTimeStyles.None; double keyboardIntensity; double mouseIntensity; if (double.TryParse(parts[7], out keyboardIntensity) == false) { // Try English if (double.TryParse(parts[7], NumberStyles.Float, culture, out keyboardIntensity) == false) { throw new ApplicationException("Cannot parse a real number."); } } if (double.TryParse(parts[8], out mouseIntensity) == false) { // Try English if (double.TryParse(parts[8], NumberStyles.Float, culture, out mouseIntensity) == false) { throw new ApplicationException("Cannot parse a real number."); } } double share; if (double.TryParse(parts[6], out share) == false) { // Try English if (double.TryParse(parts[6], NumberStyles.Float, culture, out share) == false) { throw new ApplicationException("Cannot parse a real number."); } } if (parts[0] != "") { DateTime date; if (DateTime.TryParse(parts[0], out date) == false) { // Try English if (DateTime.TryParse(parts[0], culture, styles, out date) == false) { throw new ApplicationException("Cannot parse a date string."); } } ActivitySummary summary = new ActivitySummary(); summary.TimePoint = date; summary.Span = TimeSpan.Parse(parts[1]); summary.TotalShare = share; summary.TotalKeyboardIntensity = keyboardIntensity; summary.TotalMouseIntensity = mouseIntensity; summary.Entries = new List <ActivityEntry>(); data.Add(summary); lastSummary = summary; } else { if (lastSummary == null) { throw new ApplicationException("First entry in the log file is not a summary."); } ActivityEntry entry = new ActivityEntry() { App = getApp(parts[2]), ApplicationTitle = parts[3], WindowTitle = parts[4], DocumentName = parts[5] }; System.Diagnostics.Debug.Assert(entry.DocumentName != null); entry.Share = share; entry.KeyboardIntensity = keyboardIntensity; entry.MouseIntensity = mouseIntensity; entry.SetCategory(); lastSummary.Entries.Add(entry); } } catch (Exception) { errorLines.Add(lineNumber.ToString("D3") + ":" + (line ?? "UNKNOWN")); } } reader.Close(); }
private static ActivitySummary GetActivitySummary(List <ActivitySnapshot> snapshots, DateTime timePoint) { ActivitySummary summary; if (snapshots.Count >= 1) { double keyboardIntensity = snapshots.Count >= 1 ? (from x in snapshots select x.KeyboardIntensity).Average() : 0.0; double mouseIntensity = snapshots.Count >= 1 ? (from x in snapshots select x.MouseIntensity).Average() : 0.0; summary = new ActivitySummary { TimePoint = timePoint, Span = new TimeSpan(0, 0, Parameters.LogTimeUnit), TotalShare = 100.0 * snapshots.Count / Parameters.LogSamplingRate, TotalKeyboardIntensity = keyboardIntensity, TotalMouseIntensity = mouseIntensity, Entries = new List <ActivityEntry>() }; } else { summary = new ActivitySummary { TimePoint = timePoint, Span = new TimeSpan(0, 0, Parameters.LogTimeUnit), TotalShare = 0, TotalKeyboardIntensity = 0, TotalMouseIntensity = 0, Entries = new List <ActivityEntry>() }; } Dictionary <string, double> processShare = new Dictionary <string, double>(); bool[] done = new bool[snapshots.Count]; for (int i = 0; i < snapshots.Count; ++i) { string thisApp = snapshots[i].App.Name; string thisTitle = snapshots[i].ApplicationTitle; string thisSubtitle = snapshots[i].WindowTitle; string thisDocument = snapshots[i].ValidDocumentName; if (done[i] == false) { int count = 1; double sumKeyboard = snapshots[i].KeyboardIntensity; double sumMouse = snapshots[i].MouseIntensity; for (int j = i + 1; j < snapshots.Count; ++j) { string commonTitle; if (snapshots[j].App.Name == thisApp && snapshots[j].WindowTitle == thisSubtitle && snapshots[j].ValidDocumentName == thisDocument && AreTitlesNearlyEqual(snapshots[j].ApplicationTitle, thisTitle, out commonTitle)) { count++; sumKeyboard += snapshots[j].KeyboardIntensity; sumMouse += snapshots[j].MouseIntensity; done[j] = true; thisTitle = commonTitle; } } Debug.Assert(count >= 1); ActivityEntry newEntry = new ActivityEntry { Share = 100 * count / Parameters.LogSamplingRate, App = snapshots[i].App, ApplicationTitle = thisTitle, WindowTitle = thisSubtitle, DocumentName = thisDocument, KeyboardIntensity = sumKeyboard / count, MouseIntensity = sumMouse / count }; newEntry.SetCategory(); summary.Entries.Add(newEntry); // Counting the total share per process path if (processShare.Keys.Contains(newEntry.App.Path)) { processShare[newEntry.App.Path] += newEntry.Share; } else { processShare.Add(newEntry.App.Path, newEntry.Share); } } } summary.Entries.Sort ( (a, b) => processShare[a.App.Path] != processShare[b.App.Path] ? (int)(1000 * (processShare[b.App.Path] - processShare[a.App.Path])) : (int)(1000 * (b.Share - a.Share)) ); return(summary); }