- 0 Talk
-
RT3StatisticsPackageTimeWorked
This version works well for me, but hasn't been tested very thoroughly. You'll need to adjust the value of $Queue and the id of the custom field.
% # {{{ comment
% #
% # Created: 12/05/2004 13:55:01 EST by Andy Harrison
% # {
% # TLD => 'com',
% # Username => 'aharrison',
% # Domain => 'gmail'
% # }
% #
% # ------------------
% # Time Worked Report
% # ------------------
% #
% # Plugin for the RT Statistics Package
% #
% # $Id: RT3StatisticsPackageTimeWorked,v 1.7 2006/10/26 12:21:19 www-data Exp $
% #
% # }}}
<& /Elements/Header, Title => loc('RT Statistics: sysops-tasks queue, Time Worked Report') &>
<& /Statistics/Elements/Tabs, Title => loc('RT Statistics: Time Worked Report, sysops-tasks') &>
<form method="POST">
<p>
<&|/l&>Days to see</&>:
<INPUT TYPE=text MAXLENGTH=2 SIZE=3 VALUE="<% 1+$max %>" NAME="max">
<&|/l&>See weekends</&>:
<INPUT TYPE="checkbox" <% $weekends && 'CHECKED' %> name="weekends">
<INPUT TYPE="submit" VALUE="<&|/l&>Go!</&>"</INPUT>
</p>
% # --------
% # Re-add this if you want to be able to pick queues again
% #
% # <&|/l&>See Queue</&>:<BR>
% # <& /Elements/SelectQueue, Name=>"queue", ShowNullOption=>0 &>
% # --------
%
% #
% # Now start iterating through our dates and
% # building our our results and summary hashes.
% #
%
% for my $d (0..$#dates) {
%
% my $x = 1;
% for my $CurrentTicketType ( @CustomTicketTypes ) {
% #
% # Create a fresh Tickets object
% #
% my $TicketsObj = new RT::Tickets( $RT::SystemUser );
% #
% # (just wanted a CurrentDayStart for my own readability )
% #
% my $CurrentDayStart = new RT::Date( $RT::SystemUser );
% $CurrentDayStart->Set(
% Format => 'unix',
% Value => $dates[ $d ]->Unix
% );
% $CurrentDayStart->SubtractDay;
%
% #
% # In the current date range, we want to just
% # make a list of tickets that have been updated
% # in the current time period for this pass.
% #
% $TicketsObj->LimitDate(
% FIELD => 'LastUpdated',
% VALUE => $dates[$d]->ISO,
% OPERATOR => "<="
% );
% if ( $dates[$d+1] ) {
% $TicketsObj->LimitDate(
% FIELD => 'LastUpdated',
% VALUE => $CurrentDayStart->Unix,
% OPERATOR => ">="
% );
% }
%
% #
% # You could do this for other queues if you wanted
% #
% $TicketsObj->LimitQueue( VALUE => $Queue );
%
% #
% # Only show transactions where there was some work done
% #
% $TicketsObj->LimitTimeWorked( VALUE => 1, OPERATOR => ">" );
%
% #
% # Limiting the search to the custom field that we use
% # for the type work being done in the ticket
% #
% $TicketsObj->LimitCustomField(
% CUSTOMFIELD => 129,
% VALUE => "$CurrentTicketType",
% OPERATOR => "="
% );
%
% #
% #
% # $TicketsObj will now contain tickets with
% # a transaction for the current date
% #
% #
% # For every ticket in the list, we want to cycle through its
% # transactions looking for what we want.
% #
% while ( my $CurrentTicketObj = $TicketsObj->Next ) {
% my $CurrentTransactionsObj = $CurrentTicketObj->Transactions;
% my $LastTicket;
%
% while ( my $CurrentTicketTransactionObj =
% $CurrentTransactionsObj->Next ) {
% my $CurTransDateObj = new RT::Date( $RT::SystemUser );
% $CurTransDateObj->Set(
% Format => 'ISO',
% Value => $CurrentTicketTransactionObj->Created
% );
%
% if (
% ( $CurrentTicketTransactionObj->Type
% eq 'Comment'
% || $CurrentTicketTransactionObj->Type
% eq 'Correspond'
% || $CurrentTicketTransactionObj->Type
% eq 'Create'
% )
% &&
% ( $CurTransDateObj->Unix
% <= $dates[ $d ]->Unix
% && $CurTransDateObj->Unix
% >= $CurrentDayStart->Unix
% )
% && $CurrentTicketTransactionObj->TimeTaken
% ) {
%
% $TicketResults{ $CurrentDayStart->ISO }{ $CurrentTicketType } =
% $SubTableObj->render(
% {
% 'TicketID' =>
% $CurrentTicketTransactionObj->TicketObj->id,
% 'TicketSubject' =>
% $CurrentTicketTransactionObj->TicketObj->Subject,
% 'TicketRequestor' =>
% $CurrentTicketTransactionObj->TicketObj->RequestorAddresses,
% 'TransactionID' =>
% $CurrentTicketTransactionObj->id,
% 'Employee' =>
% $CurrentTicketTransactionObj->CreatorObj->Name,
% 'Worked' =>
% $CurrentTicketTransactionObj->TimeTaken,
% 'EntryDate' =>
% $CurrentTicketTransactionObj->Created,
% });
%
% $EmployeeSummary{ $CurrentTicketType }{ $CurrentTicketTransactionObj->CreatorObj->Name } +=
% $CurrentTicketTransactionObj->TimeTaken;
%
% $EmployeeSummary{ 'total/person' }{ $CurrentTicketTransactionObj->CreatorObj->Name } +=
% $CurrentTicketTransactionObj->TimeTaken;
%
% $EmployeeSummary{ $CurrentTicketType }{ 'total/type' } +=
% $CurrentTicketTransactionObj->TimeTaken;
% $EmployeeSummary{ 'total/person' }{ 'total/type' } +=
% $CurrentTicketTransactionObj->TimeTaken;
%
%
%# $EmployeeSummary{ $CurrentTicketType }{ $CurrentTicketTransactionObj->CreatorObj->Name } +=
%# $TicketResults{ $CurrentDayStart->ISO }{ $CurrentTicketType }{ Worked };
%#
%# $EmployeeSummary{ 'total/person' }{ $CurrentTicketTransactionObj->CreatorObj->Name } +=
%# $TicketResults{ $CurrentDayStart->ISO }{ $CurrentTicketType }{ Worked };
%#
%# $EmployeeSummary{ $CurrentTicketType }{ 'total/type' } +=
%# $TicketResults{ $CurrentDayStart->ISO }{ $CurrentTicketType }{ Worked };
%# $EmployeeSummary{ 'total/person' }{ 'total/type' } +=
%# $TicketResults{ $CurrentDayStart->ISO }{ $CurrentTicketType }{ Worked };
% }
% }
% }
%
% # $data[$x++][$d] = $TicketsObj->Count;
% }
% }
<p>
<hr>
</p>
% #
% # Dump the summary of gathered TimeWorked
% #
%
% #
% # Make the totals appear in bold
% #
% foreach my $TotalToStyle ( keys %{ $EmployeeSummary{ 'total/person' } } ) {
% $EmployeeSummary{ 'total/person' }{ $TotalToStyle } =
% "<b>"
% . $EmployeeSummary{ 'total/person' }{ $TotalToStyle }
% . "</b>";
% }
% foreach my $TotalToStyle ( keys %EmployeeSummary ) {
% $EmployeeSummary{ $TotalToStyle }{ 'total/type' } =
% "<b>"
% . $EmployeeSummary{ $TotalToStyle }{ 'total/type' }
% . "</b>";
% }
%
% print $TableObj->render( \%TicketResults );
% print $TableObj->render( \%EmployeeSummary );
<p>
<hr>
</p>
</form>
<BR>
%#
%# No graphing at the moment
%#
%## <%perl>
%## my $url= 'Elements/Chart?x_labels=';
%## for (0..$max) {
%## $url .= $data[0][$_] . ",";
%## }
%## chop $url;
%## $url .= "&";
%## shift @data;
%## for (0..$#data) {
%## $url .= "data".(1+$_)."=".(join ",", @{$data[$_]})."&";
%## }
%## chop $url;
%## </%perl>
%## <IMG SRC="<% $url %>" type="image/png">
%## <BR>
%## <font color="red"> <&|/l&>Resolved</&></FONT> <font color="green"><&|/l&>Created</&></font>
%## <font color="blue"> <&|/l&>Deleted</&> </font> <BR>
<%ARGS>
$max => undef
$Queue => 45
$weekends => 1
</%ARGS>
<%INIT>
unless ( eval { require HTML::QuickTable } ) {
die "Unable to load HTML::QuickTable module: $@\n"
}
my $TableObj = HTML::QuickTable->new(
labels => 1,
th => { class => 'ticketheader' },
table => { border => 0 },
td => { style => 'border: solid black 1px' },
null => ' ',
);
my $SubTableObj = HTML::QuickTable->new(
labels => 0,
table => { border => 0 },
null => ' ',
);
my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
my $n = 0;
my @data = ([]);
my @dates;
my @msgs;
my @CustomTicketTypes;
my %EmployeeSummary;
my %TicketResults;
$max--;
#
# Load up the specified queue
#
# my $QueueObj = new RT::Queue($session{'CurrentUser'});
my $QueueObj = new RT::Queue( $RT::SystemUser );
$QueueObj->Load( $Queue ) || Abort(loc("Queue could not be loaded."));
#
# We use a custom field to designate the particular
# type of work being done, Maintenance, Security,
# Documentation, etc.
#
# All you need is push strings to the @CustomTicketTypes
# list and it will split up the report into those
# categories
#
my $CustomFieldsObj = $QueueObj->CustomFields;
while ( my $CustomFieldObj = $CustomFieldsObj->Next ) {
next unless $CustomFieldObj->Name eq "Type";
my $CustomFieldValuesObj = $CustomFieldObj->Values();
while ( my $CustomFieldValueObj = $CustomFieldValuesObj->Next ) {
push @CustomTicketTypes, $CustomFieldValueObj->Name;
}
}
#
# Create the list of dates.
#
until ($#dates == $max) {
# my $date = new RT::Date($session{CurrentUser});
my $date = new RT::Date( $RT::SystemUser );
$date->Set(Value=>time - $n, Format => 'unix');
$date->SetToMidnight;
my $when = $days[(localtime($date->SetToMidnight))[6]];
$n+= 60*60*24;
next if !$weekends and ( $when eq "Sat" or $when eq "Sun" );
unshift @dates, $date;
unshift @{ $data[0] },
$days[(localtime($date->Unix))[6]]."%20". (localtime($date->Unix))[3];
}
</%INIT>
* This seems great but where are you supposed to put this file?
- MichaelErana, August 5, 2005
* No idea, I'm trying to figure that out too.
- RoyMiller, October 26, 2005
* File goes into /<rt3dir>/share/html/RTx/Statistics/TimeWorked/index.html * Will need to add a link to the base index.html
- Spiker, June 10, 2009