Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Computer usage analysis


  • Please log in to reply
12 replies to this topic
hamoid
  • Members
  • 19 posts
  • Last active: Nov 06 2006 10:45 AM
  • Joined: 17 Mar 2005
Hello,

I want to share what I did today with AHK, maybe someone finds it interesting.

I've been using a program called Smart Worktime Tracker for two years. I bought this program, but the development stopped long time ago. Some important features were missing. This program allows you to track time of projects, so you know how many minutes you used every day on each project and application.

I decided to try something like this myself, using AHK. The idea is to record application names and window titles at certain interval. In my case, every 5 seconds I write this information in a file with a small script. I also added tracking of key and mouse presses, so we have an indication of how intensely we used the computer.

The small script is like this:
#Persistent
SetTimer, WatchActiveWindow, 5000

Loop
{
 ; !! the next 5 lines should be one very long, modified for readability
  Input myk, L1 V, {ScrollLock}{CapsLock}{NumLock}{TAB}
{Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl}
{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}
{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}
{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}
  KC++
}

; end of auto execute section
return

WatchActiveWindow:
WinGetTitle, Title, A
WinGet, pname, ProcessName, A
line = %A_now%¬%pname%¬%Title%¬%KC%
StringReplace, line, line, `n, %A_SPACE%, All
StringReplace, line, line, `r, , All
FileAppend, %line%`n, C:\work.log
KC=
return

~*LButton::
~*RButton::
   KC++
return
The result is a file called work.log, with lines like this:
20051211192135¬SciTE.exe¬c:\work0.log - SciTE [2 of 2]¬
20051211192140¬SciTE.exe¬c:\work0.log - SciTE [2 of 2]¬67
20051211192145¬SciTE.exe¬c:\work0.log - SciTE [2 of 2]¬126
Each line includes time, exe name, window title and user activity.

Then I created two little PHP programs. Program 1 reads C:\work.log and inserts everything into 3 MySql tables (exe_files, window_titles and work_log).

Program 2 reads these tables and prints formatted information about what happened during the logging. It's unbelievable the amount of information I see there! for example, I can see the subject of the emails I wrote, the name of my friends who I used Skype with, website names I visited...

It was very quick to do. The problem now is that to make it really useful, it should understand which actions belong to different projects.

Is someone interested in it? I can send the PHP files and SQL scheme... With some work it could become a useful tracking tool...

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
Hi Hamoid,

Very nice idea. And thanks for sharing.
two remarks:
Instead of one long line you could write
Input myk, L1 V,
    (Ltrim
       {ScrollLock}{CapsLock}{NumLock}{TAB} 
       {Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl} 
       {LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4} 
       {F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up} 
       {Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}
    )

I guess that you could as well use AHK to do the statistics and formated output. Although I believe it would be more code then in php.

The problem now is that to make it really useful, it should understand which actions belong to different projects.

You could use the tray menu to switch between projects (advantage over an extra GUI: No extra space needed on screen and it's fast). To manage (add/remove/rename) the projects the menu could have an item that starts a small GUI. The menu could as well have a project called lunch break, so the time isn't billed. :)
You could also have a half transparent GUI in the background of you desktop showing the time spend on the different projects today / week / month / year.
The sky isn't the limit.
Have fun.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

BoBo
  • Guests
  • Last active:
  • Joined: --
@hamoid
:shock: gestern noch Berlin heute schon Mallorca, Respekt!

hamoid
  • Members
  • 19 posts
  • Last active: Nov 06 2006 10:45 AM
  • Joined: 17 Mar 2005

gestern noch Berlin heute schon Mallorca, Respekt!


:lol: hahaha! you should be a detective! I moved back to Mallorca two months ago. But soon I should find a new destination. Don't worry, we will also get snow in the mountains this week.

Thanks for the Ltrim tip, Toralf.

I think not using PHP would be good, because it's not a standard program on everybody's computer. But I think a database is anyways necessary. Otherwise you would go crazy processing those logs :) (one could use sqlite or mysql from command line).

The project selector is a good idea, but something really important for me (and my reason to create this) is the posibility to decide afterwards which project you worked on. Because sometimes I forget to say 'hey, i'm on lunch break', and then count more time than it should. The concept is to have the original data, and specify afterwards what it means, how to interpret it. Or maybe use the project selector, but offer some way of correcting the data.

I can imagine the translucid GUI, stats, activity indicator, icons for used apps, activity density by days or months, finger stress warnings... but lately I feel more like the real world is not digital ;) (getting old?)

banker1
  • Members
  • 7 posts
  • Last active: Jul 01 2007 04:09 PM
  • Joined: 09 Jan 2006
I am new to autokey, but this looks like something that I would find useful. Do you think this script could be edited to track the number of times a script is run?
banker1

hamoid
  • Members
  • 19 posts
  • Last active: Nov 06 2006 10:45 AM
  • Joined: 17 Mar 2005
Yes, it can easily be used to track any behaviour.

You just have to decide in which format you save the information to the log file, and then analyze the stored information somehow (in my case it's a php program, but you can use any programming language, or maybe import comma separated fields into excel).

PCWacht
  • Members
  • 2 posts
  • Last active: May 26 2007 03:45 PM
  • Joined: 21 May 2007
I updated this script a bit

Now it will not give multiple lines for the same application but count them into one.
I did this with 2 more variables and a simple test between them, if they are still the same, no line is added to the log thus giving a much more readable log.


#Persistent
SetTimer, WatchActiveWindow, 5000


Loop
{
  Input myk, L1 V, 
    (Ltrim 
       {ScrollLock}{CapsLock}{NumLock}{TAB} 
       {Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl} 
       {LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4} 
       {F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up} 
       {Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins} 
    )
  KC++
}

; end of auto execute section
return

WatchActiveWindow:
WinGetTitle, Title, A
WinGet, pname, ProcessName, A
temp = %pname%¬%Title%
if (temp2 <> temp)
  { 
  line = %A_now%¬%temp2%¬%KC%
  StringReplace, line, line, `n, %A_SPACE%, All
  StringReplace, line, line, `r, , All
  FileAppend, %line%`n, C:\work.log
  KC=
  temp2 = %temp%
  }
return

~*LButton::
~*RButton::
   KC++
return


John


PS, The mentioned sql and php code, are they still available?
I could use them..

edited, typo

Helpy
  • Guests
  • Last active:
  • Joined: --

The mentioned sql and php code, are they still available?
I could use them..

Note that if all you want is database access, there are various wrappers in the forum, eg. for SQLite (or MySQL, etc.).

hamoid
  • Members
  • 19 posts
  • Last active: Nov 06 2006 10:45 AM
  • Joined: 17 Mar 2005
file in zip format.

Sorry for that link, but it looks like the system does not like parenthesis... copy and paste please :)

One of the php files includes a library which I can't post, but it's easy to replace: use "mysql_query" instead of "query", and replace query_array with something that builds an array using a query. I hope you know how...

PCWacht
  • Members
  • 2 posts
  • Last active: May 26 2007 03:45 PM
  • Joined: 21 May 2007

Note that if all you want is database access, there are various wrappers in the forum, eg. for SQLite (or MySQL, etc.).


Thanks,
Am new here but certainly will hunt this forum for that info.

Sorry for that link, but it looks like the system does not like parenthesis... copy and paste please


No prob, thanks.

One of the php files includes a library which I can't post, but it's easy to replace: use "mysql_query" instead of "query", and replace query_array with something that builds an array using a query. I hope you know how...

Yups I sure do.


What I am trying to achieve is following
I work at a school as systemadmin manager
The amount of computers grew a large bit last years, management told sys-admins to install everything on everything (each programm needs to run on each pc)
For licence purpose and for sysadmin's sake it would be handy to see who uses when wich programm on wich pc.
The php code could easely be used with xampp for example to keep updated reports.

Will keep you posted on my progress.

The hunt for some script like this brought me here. So I am very new to AutoHotKey (Been playing with autoit for many years though)

John

tg3793
  • Members
  • 12 posts
  • Last active: Feb 03 2010 06:31 PM
  • Joined: 19 Jan 2010
Wow did development ever continue on this? I'm trying it out now and this looks great. It is 'very' cool how this logs everything I am doing into a simple text file. I can think of a dozen uses for this.

Will have to post back here when I've checked this out some more. Thanks again for the work that's been done here. God bless!

tg3793
  • Members
  • 12 posts
  • Last active: Feb 03 2010 06:31 PM
  • Joined: 19 Jan 2010
Wow, been using this for a few hours now. Played around with the script and made a minor edit so that the log file is placed in the AutoHotkey Scripts directory.

The code that was done here is 'very' readable. Kudos to "hamoid". Although I've edited dos batch files before this is absolutely the first time I've done even the most minor code edit on something like this.


; I only made one very minor edit to the code below. Now instead of having
; a log file that get's put into the root directory of the computer that
; it is on, the log file is placed in the AutoHotkey Scripts directory.
;
; I am making an assumption that is where you will also put all of your scripts.
; 
; ... Tim Gott http://gottmilk.wordpress.com/
;
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         A.N.Other <[email protected]>
;
; Script Function:
;	Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)
;

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


#Persistent
SetTimer, WatchActiveWindow, 5000


Loop
{
  Input myk, L1 V, 
    (Ltrim 
       {ScrollLock}{CapsLock}{NumLock}{TAB} 
       {Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl} 
       {LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4} 
       {F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up} 
       {Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins} 
    )
  KC++
}

; end of auto execute section
return

WatchActiveWindow:
WinGetTitle, Title, A
WinGet, pname, ProcessName, A
temp = %pname%¬%Title%
if (temp2 <> temp)
  { 
  line = %A_now%¬%temp2%¬%KC%
  StringReplace, line, line, `n, %A_SPACE%, All
  StringReplace, line, line, `r, , All
  FileAppend, %line%`n, %ProgramFiles%\AutoHotkey\Extras\Scripts\work.log
  KC=
  temp2 = %temp%
  }
return

~*LButton::
~*RButton::
   KC++
return

Thanks again.

MrShortcut
  • Members
  • 130 posts
  • Last active: May 18 2016 05:46 PM
  • Joined: 21 Jul 2009

file in zip format.

Sorry for that link, but it looks like the system does not like parenthesis... copy and paste please

One of the php files includes a library which I can't post, but it's easy to replace: use "mysql_query" instead of "query", and replace query_array with something that builds an array using a query. I hope you know how...


I've been able to copy the script and the Zip file but I do not know how to perform the replacement for the library which couldnt be posted. Can anyone help to point me towards what I would need to do so that I can determine how long I am in each application each day using a format like how program 2 was shown to be able to do?