AutoHotkey Community

It is currently May 27th, 2012, 6:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Computer usage analysis
PostPosted: December 11th, 2005, 9:00 pm 
Offline

Joined: March 17th, 2005, 10:25 am
Posts: 19
Location: 10247 Berlin
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:
Code:
#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:
Code:
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2005, 10:11 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Hi Hamoid,

Very nice idea. And thanks for sharing.
two remarks:
Instead of one long line you could write
Code:
  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.

Quote:
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2005, 10:34 am 
@hamoid
:shock: gestern noch Berlin heute schon Mallorca, Respekt!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2005, 11:45 am 
Offline

Joined: March 17th, 2005, 10:25 am
Posts: 19
Location: 10247 Berlin
Quote:
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?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Great file
PostPosted: January 13th, 2006, 3:47 pm 
Offline

Joined: January 9th, 2006, 8:39 pm
Posts: 7
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 28th, 2006, 1:37 pm 
Offline

Joined: March 17th, 2005, 10:25 am
Posts: 19
Location: 10247 Berlin
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2007, 1:45 pm 
Offline

Joined: May 21st, 2007, 1:44 pm
Posts: 2
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.


Code:
#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


Last edited by PCWacht on May 31st, 2007, 10:14 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2007, 1:57 pm 
PCWacht wrote:
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.).


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2007, 2:17 pm 
Offline

Joined: March 17th, 2005, 10:25 am
Posts: 19
Location: 10247 Berlin
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2007, 3:38 pm 
Offline

Joined: May 21st, 2007, 1:44 pm
Posts: 2
Quote:
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.

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

No prob, thanks.

Quote:
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


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 19th, 2010, 1:33 pm 
Offline

Joined: January 19th, 2010, 11:39 am
Posts: 12
Location: Philippines
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!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: January 19th, 2010, 2:39 pm 
Offline

Joined: January 19th, 2010, 11:39 am
Posts: 12
Location: Philippines
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.

Code:

; 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 <myemail@nowhere.com>
;
; 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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2010, 11:59 pm 
Offline

Joined: July 21st, 2009, 8:36 pm
Posts: 121
Quote:
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?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group