Rob Dixon wrote:
> It's very unclear what you're trying to do, and what your RT package
> does. Let
> me make some observations and guesses and you can tell me where I'm
> right or
> wrong.
> 
> $tix is an iterator that will return a sequence of tickets through the Next
> method.
> 
> $ticket is a data handle that will return an id, an Environment, and a
> Transactions iterator. The environment appears to be a customer number.
> 
> $transaction is a RT handle that will return a TimeTaken and a Creator. The
> creator appears to be a user identity.
> 
> What you want to generate is a hash of total time worked by each user
> across
> all customers and tickets.
> 
> The code below may help. Clearly it is untested as I have no RT package or
> database, but it is something we can discuss. Please let us know how close
> this is to what you are aiming for.
> 
> HTH,
> 
> Rob
> 
> 
> use warnings;
> use strict;
> 
> use lib '/usr/local/rt-3.6.3/lib';
> use lib '/usr/local/rt-3.6.3/local/lib';
> use RT;
> use RT::Tickets;
> use RT::Users;
> 
> RT::LoadConfig();
> RT::Init();
> 
> my $tix = new RT::Tickets($RT::SystemUser);
> $tix->FromSQL('Queue = "CustomerCare" OR Status = "resolved" OR Status =
> "open"');
> 
> my %timeworked;
> 
> while (my $ticket = $tix->Next) {
> 
>  my $id = $ticket->id;
>  my $customer = $ticket->FirstCustomFieldValue('Environment');
> 
>  unless ($customer) {
>    warn "warning $id no environment";
>    next
>  }
> 
>  my $transactions = $ticket->Transactions;
> 
>  while (my $transaction = $transactions->Next) {
>  
>    my $user = $transaction->Creator;
>    my $time = $transaction->TimeTaken;
>       $timeworked{$user} += $time;
>  }
> }
> 
> foreach my $user (keys %timeworked) {
>  printf "%s -> %s\n", $user, $timeworked{$user};
> }
> 

Rob,

You are correct in all of your assumptions above.  Your code example spurred me
to get a bit further with my script.  I now have this:

#!/usr/bin/perl

use warnings;
use strict;
use lib '/usr/local/rt-3.6.3/lib';
use lib '/usr/local/rt-3.6.3/local/lib';
use RT;
use RT::Tickets;
use RT::Users;

RT::LoadConfig();
RT::Init();

my $tix = new RT::Tickets(RT::SystemUser);
$tix->FromSQL('Queue = "CustomerCare" AND Status = "open" AND Created <
"2007-03-03"');

my %environment;
my %timeworked;
my $users = new RT::Users(RT::SystemUser);
$users->LimitToPrivileged;

while (my $ticket = $tix->Next) {
        my $environment = $ticket->FirstCustomFieldValue('Environment');

        unless ($environment) {
                warn "warning" . $ticket->id. "no environment";
                next
        }

        my $transactions = $ticket->Transactions;

        while (my $transaction = $transactions->Next) {
                next unless ($transaction->TimeTaken);

                foreach my $user ($users->Next) {
                        if ($user = $transaction->Creator) {
                                $timeworked{$user} += $transaction->TimeTaken;
                                $environment{$environment} = $timeworked{$user};
                        }
                }
        }
}

foreach my $env (sort keys %environment) {
        print "\n" . $env . "\n";
        print "--------------------\n";
        foreach my $user (sort keys %timeworked) {
                print $user . " -> " . $timeworked{$user} . "\n";
        }
}

This is getting closer to what I want.  However, the %timeworked hash still
doesn't do what I'm looking for.  Rather than only totalling up the time worked
on each customer for each user and then adding that to the customer environment
hash as $environment{$env}{$user} it is still iterating through every ticket and
transaction and adding that time to $timeworked{$user} which is then output for
each customer at the end.  To clarify, each $environment{$env} has an identical
%timeworked hash printed with it.  That %timeworked hash is a total for all time
for each user and not just the time for the customer.

I've tried so many different alterations but can't figure out how to get the
%timeworked hash populated the way I need and paired with the %environment hash
properly.

Your further assistance will be greatly appreciated.

Mathew

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to