Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

here is a script to log what you do during the day...

by gianni (Novice)
on Feb 06, 2011 at 17:02 UTC ( #886532=CUFP: print w/ replies, xml ) Need Help??

This script logs to a file the name of the active windows, so you can keep track of how much time you spend on each activity. It logs only the current session, if you modify it, please post the results :-) If you use firefox, you need to install the "nightly tester tools" adddon to change the title of the window to "firefox", otherwise the script will keep track of each url visited. Currently I embed the resulting text file in conky, it updates only each minute, to prevent writing too often to the disk; maybe there is a way to "pipe" the results to conky.
use feature ':5.10'; # loads all features available in perl 5.10 use IPC::System::Simple qw(system systemx capture capturex); while (1) { $comando = q(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)"| cut -d ' ' -f + 5); $output = capture("$comando"); chomp $output; $titolo = q(xwininfo -id ) . $output . q( |awk 'BEGIN {FS="\""}/xwininfo: Window id/{print $2}' | sed + 's/-[^-]*$//g'); $outTitolo = capture("$titolo"); chomp $outTitolo; sleep 60; if ( $outTitolo =~ /firefox/gsi ) { $outTitolo = 'firefox'; } push( @myNames, $outTitolo ); my %hashActivity = count_unique(@myNames); undef my $oreTotali; while ( my ( $key, $value ) = each(%hashActivity) ) { $oreTotali = $value + $oreTotali; } open FILE, ">.activityLog.txt" or die $!; print FILE " $oreTotali minuti Uptime "; foreach $key ( sort { $hashActivity{$b} <=> $hashActivity{$a} } keys %hashActivity ) { $percentualeOre = int( $hashActivity{$key} / $oreTotali * 100 +); print FILE "\n $hashActivity{$key}\' $key\n "; for ( 0 .. $percentualeOre / 10 ) {print FILE "=="} print FILE " $percentualeOre \%"; } print FILE "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; } sub count_unique { my @array = @_; my %count; map { $count{$_}++ } @array; #print them out: # map {print "$_ = ${count{$_}}\n"} sort keys(%count); #or just return the hash: return %count; }

Comment on here is a script to log what you do during the day...
Download Code
Re: here is a script to log what you do during the day...
by jwkrahn (Monsignor) on Feb 07, 2011 at 08:05 UTC
    $output = capture("$comando"); ... $outTitolo = capture("$titolo");

    Why are you copying $comando and $titolo to strings instead of using them directly?

    What's wrong with always quoting "$vars"?



    undef my $oreTotali;

    Why would you use undef there?    Just because you can?    It is superfluous in that context.



    print FILE "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

    Probably better as:

    print FILE "\n" x 17;


    sub count_unique { my @array = @_; my %count; map { $count{$_}++ } @array;

    Why make a copy of @_ when you don't really have to?    Why use map in void context and create a list that you are not going to use?

    sub count_unique { my %count; $count{$_}++ for @_;
      Thank you very much for your corrections

      Why use map in void context and create a list that you are not going to use?

      No list is built in void context anymore.

      The only thing that got created and not used is the SVs created by post-increment. $x++ automatically gets converted to ++$x in void context, so your for rewrite doesn't suffer from this whereas the original did.

        No list is built in void context anymore.

        Ah yes ... gianni didn't say which version of Perl was used so you can't assume that.    :-)

Re: here is a script to log what you do during the day...
by Fox (Pilgrim) on Feb 07, 2011 at 13:01 UTC
    ... to prevent writing too often to the disk; maybe there is a way to "pipe" the results to conky.
    I don't know about conky, but if you turn activityLog.txt into a named pipe the data won't be written to the disk.

      thanks for your suggestion, I'm confident that it will work.

      I will use this code from the perl cookbook.

      http://docstore.mik.ua/orelly/perl/cookbook/ch16_12.htm

Re: here is a script to log what you do during the day...
by wazoox (Prior) on Feb 07, 2011 at 18:07 UTC
    If you use firefox, you need to install the "nightly tester tools" adddon to change the title of the window to "firefox", otherwise the script will keep track of each url visited.

    It seems to me that all Firefox windows are named "page title - Mozilla Firefox"; so it would be quite easy to create a matching rule and simply keep the two last words:

    if ( $titolo =~ m#.*\s\-\s(Mozilla Firefox)$# ) {$titolo = $1 };

    beware, untested code example!

      I think that it depends on the firefox build, I had to install that addon. Anyway maybe that checking the about:config file after you've installed the addon you can find the variable that changes the title, and the uninstall the addon.
        You could pull your firefox history and merge it with the log of all your other windows. Wouldn't miss as much.
Re: here is a script to log what you do during the day...
by sundialsvc4 (Monsignor) on Feb 10, 2011 at 14:50 UTC

    Do you really need a script to calculate this?   ;-) ...

    Time spent goofing around on perlmonks.org:   90.0%
    Time spent drinking coffee and thinking about getting around to real work:   9.0%
    ;-)   ;-)   ;-)

    In all seriousness, it is extremely useful to actually measure how you spend your day, how much time it actually takes to solve a problem, how accurate your initial rosy estimates were vs. what actually happened (read:   “why you are working so hard and still losing money”), how much time you spend talking to people (who aren’t paying you), and so on.   It’s strange how you think you know what you’re doing all day every day ... because, well, you do it all day every day ... but when you measure, you find out how very different your perceptions actually are from what takes place.

      I was just thinking how grateful I am that my boss doesn't know Perl. If he realized just how easy it is to do complex things, he'd... well... um... yeah... let us hope he never finds this script. ;)

      --Ray

      You need a script to find your remaining 1 %.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://886532]
Approved by moritz
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-07-30 03:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls