AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Computer usage analysis

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
hamoid



Joined: 17 Mar 2005
Posts: 19
Location: 10247 Berlin

PostPosted: Sun Dec 11, 2005 8:00 pm    Post subject: Computer usage analysis Reply with quote

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...
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
toralf



Joined: 31 Jan 2005
Posts: 3910
Location: Bremen, Germany

PostPosted: Mon Dec 12, 2005 9:11 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
BoBo
Guest





PostPosted: Mon Dec 12, 2005 9:34 am    Post subject: Reply with quote

@hamoid
Shocked gestern noch Berlin heute schon Mallorca, Respekt!
Back to top
hamoid



Joined: 17 Mar 2005
Posts: 19
Location: 10247 Berlin

PostPosted: Mon Dec 12, 2005 10:45 am    Post subject: Reply with quote

Quote:
gestern noch Berlin heute schon Mallorca, Respekt!


Laughing 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 Smile (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 Wink (getting old?)
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
banker1



Joined: 09 Jan 2006
Posts: 7

PostPosted: Fri Jan 13, 2006 2:47 pm    Post subject: Great file Reply with quote

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
Back to top
View user's profile Send private message
hamoid



Joined: 17 Mar 2005
Posts: 19
Location: 10247 Berlin

PostPosted: Sat Jan 28, 2006 12:37 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
PCWacht



Joined: 21 May 2007
Posts: 2

PostPosted: Mon May 21, 2007 12:45 pm    Post subject: Reply with quote

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 Thu May 31, 2007 9:14 am; edited 1 time in total
Back to top
View user's profile Send private message
Helpy
Guest





PostPosted: Mon May 21, 2007 12:57 pm    Post subject: Reply with quote

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.).
Back to top
hamoid



Joined: 17 Mar 2005
Posts: 19
Location: 10247 Berlin

PostPosted: Mon May 21, 2007 1:17 pm    Post subject: Reply with quote

[url=http://www.hamoid.com/files/logging_work_with_ahk(sql-php).zip]file in zip format.[/url]

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

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...
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
PCWacht



Joined: 21 May 2007
Posts: 2

PostPosted: Mon May 21, 2007 2:38 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
tg3793



Joined: 19 Jan 2010
Posts: 12
Location: Philippines

PostPosted: Tue Jan 19, 2010 12:33 pm    Post subject: Is anyone still working on this? Reply with quote

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!
Back to top
View user's profile Send private message
tg3793



Joined: 19 Jan 2010
Posts: 12
Location: Philippines

PostPosted: Tue Jan 19, 2010 1:39 pm    Post subject: Mucho Gratitude & VERY Minor Code edit Reply with quote

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.
Back to top
View user's profile Send private message
MrShortcut



Joined: 21 Jul 2009
Posts: 112

PostPosted: Mon Feb 15, 2010 10:59 pm    Post subject: Reply with quote

Quote:
[url=http://www.hamoid.com/files/logging_work_with_ahk(sql-php).zip]file in zip format.[/url]

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?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group