Time difference between certain transaction types

Hi list,

for reporting I am trying to get time differences between certain transaction types, e.g. I would like to know the time between “Take” and “stalled” or “resolved”. Right now, I do the following, but it produces negative results, when a ticket is stalled first and taken later. Maybe someone knows a solution that respects the order :slight_smile:

define minutes

my $seconds = 0;
my $minutes = 0;
my $start;
my $end;

Get all transactions of this ticket

my $Transactions = $self->Transactions;

order by created timestamp

$Transactions->OrderBy(FIELD => ‘Created’, ORDER => ‘ASC’);

loop through all of them

while (my $Transaction = $Transactions->Next) {

if ($Transaction->Type eq “Take”) {
$start = $Transaction->CreatedObj;
}
if ($Transaction->NewValue eq “stalled” || $Transaction->NewValue eq “resolved”) {
$end = $Transaction->CreatedObj;
}
if ($start && $end) {
$seconds += $end->Diff($start);
$start = undef;
$end = undef;
}
}

Get minutes and round

$minutes = int($seconds / 60);

Thanks,
Julian

Julian Hein NETWAYS GmbH
Managing Director Deutschherrnstr. 47a
Fon.0911/92885-0 D-90429 Nürnberg
Fax.0911/92885-31
jhein@netways.de www.netways.de

rt-devel wrote:

for reporting I am trying to get time differences between certain
transaction types, e.g. I would like to know the time between "Take"
and “stalled” or “resolved”. Right now, I do the following, but it
produces negative results, when a ticket is stalled first and taken
later. Maybe someone knows a solution that respects the order :slight_smile:

You could keep a simple flag and not look for the $start time until
after you’ve seen a Take

rt-devel wrote:

for reporting I am trying to get time differences between certain
transaction types, e.g. I would like to know the time between "Take"
and “stalled” or “resolved”. Right now, I do the following, but it
produces negative results, when a ticket is stalled first and taken
later. Maybe someone knows a solution that respects the order :slight_smile:

You could keep a simple flag and not look for the $start time until
after you’ve seen a Take

Or, simply use perl’s abs() function to show the difference sans negative.

Of course, this may not be what you want, as a ticket could easily be
Created -> Stalled -> Taken -> Resolved -> Opened -> Taken -> Stalled ->
Opened -> Resolved, just to give an example.

                         Bruce Campbell                            RIPE
               Systems/Network Engineer                             NCC
             www.ripe.net - PGP562C8B1B             Operations/Security