7

I am trying to build something like Manic Time - which is an application that tracks what the user is currently working on. It worked flawlessly on Windows, but doesn't support Linux.

It has mad features, but the core is basically just tracking what the current 'active' window is, it's process, window title etc.

I've been thinking about this problem for some time and here's the Pythonic pseudo-code that I've come up with, but I'm not sure if this is the way to go.

# The script will probably run as a daemon
while True:

    # Get process, window title, etc.
    wnd_details = get_active_window_details()

    # Save the current timestamp and the details to a database (SQLite)
    insert_in_db(current_timestamp, wnd_details)

    # Wait for a second
    sleep(1000)

Will executing a write query per second affect performance?

An optimization might be to remember what the previous window details were and write to database only when the window changes (the user has switched to another application) but that will add unnecessary complexity to the code.

Yet another thing to look into might be some sort of hooks or callbacks, so my Python code gets called whenever a Window change occurs (like a new window is created or active window is changed) I guess Windows had something similar to this, but have no idea about Linux.

dufferZafar
  • 107
  • 1
  • 6
  • 3
    "Will executing a write query [into an Sqlite DB] per second affect performance?" - probably not much, but this depends on where the DB is stored (in main memory, on a hard disk, on an USB stick, on the network). You will have to find out by profiling. – Doc Brown Jun 25 '15 at 11:28
  • 1
    I'm just curious how you aggregate this at the end? To work on a task at work (Windows FTR) I may open and flip between 6 or more apps... Browser (multiple tabs/windows), IDE, text editor, exploring windows, terminal window(s), grep/regex tools, SCP/FTP, source control GUI windows, more browser windows for bug tracking tools, wiki documentation, stackoverflow... – scunliffe Jun 25 '15 at 11:40
  • @scunliffe I'm not actually interested in grouping things by a task (like a project or work related stuff.) I just need simple statistics on how much I use a particular application. I'll then create 'tags' like 'social-networking' for window titles that have 'facebook', 'twitter' etc. But thats far from now. – dufferZafar Jun 25 '15 at 12:04
  • @DocBrown The database will be on a hard disk. But yeah, since coding this *seems* straightforward, I think I'll just try profiling. – dufferZafar Jun 25 '15 at 12:06
  • Do you have to write to disk every second? If you had a 30 second or so queue and then wrote to the database, the worse thing that could happen is you lose 30 seconds of activity if someone pulls the plug on your machine. – JeffO Jun 25 '15 at 23:35

1 Answers1

2

I have found an open source application that seems to be doing EXACTLY what I wanted. https://github.com/gurgeh/selfspy/

dufferZafar
  • 107
  • 1
  • 6