Category Archives: C#

Activity Tracker

Do you have to fill timesheet weekly? I have to..Β This small tool can help you to remember what you were doing last week πŸ™‚

You start the tool and minimize it to tray. It tracks activity on your computer and logs it to a file, so you can later see what you were doing. The information, the program tracks every minute, is:

  • was there any activity (mouse or keyboard input),
  • current foreground program,
  • the title of the current foreground program.

Click on the program icon in the tray, opens it. You can pick a date, and you will see the 24 hours activity chart in the bottom, and time statistics in the tree.

The color meaning on the activity chart are the following:

  • White – no information, the computer was turned off or the program was not running.
  • Gray – idle time.
  • Blue – there was some activity.
  • Red – highlights the time when the program selected in the tree was active.

Source Code

https://bukhantsov.org/tools/ActivityTracker.zip

The 64 bit executable is in

ActivityTracker.zip\ActivityTracker\ActivityTracker\bin\x64\Release

Security

The data file is stored in “My Documents” and has name activitytracker.txt.

If other people has access to the file, please think twice before using the tool. The program will log everything you do and every minute. πŸ™‚

TO-DO: Password protection. The data should be stored in password protected zip file. To start the program, the user will have to enter the password for the zip file. If there is no data file, user will have to enter “new” password which will be used for the zip file.

A bit of code

The code builds a histogram and then orders the array by frequency in descending order.

Histogram:

string[] list = { "x", "b", "b", "x", "x", "z", "c", "x", "b", "c" };
Dictionary<string, int> histogram = new Dictionary<string, int>();
foreach (string s in list)
{
  if (!histogram.ContainsKey(s))
    histogram.Add(s, 1);
  else
    histogram[s] += 1;
}

The following code demonstrates use of lambda expressions for sorting (it was new to me).

List<KeyValuePair<string, int>> sortedlist = new List<KeyValuePair<string, int>>(histogram);
sortedlist.Sort((firstPair, nextPair) => -firstPair.Value.CompareTo(nextPair.Value));

foreach (KeyValuePair<string, int> p in sortedlist)
{
  Console.WriteLine(p.Key + ": " + p.Value);
}

This can also be done using LINQ:

var sortedlist = from s in histogram orderby s.Value descending select s;

foreach (var p in sortedlist)
{
  Console.WriteLine(p.Key + ": " + p.Value);
}

Update, 2011-11-19

Some bugs were corrected
Some enhancements
The new source code uploaded

Alternatives πŸ™‚

Of course, the program was written mostly for fun. Consider ManicTime if you really need activity tracking software.