Permalink
Browse files

Move activity reports code into elements.

Allow saving reports to SavedSearch with type of ActivityReport.
Thunk the portlet display api to show saved reports.
  • Loading branch information...
Chia-liang Kao
Chia-liang Kao committed Nov 22, 2006
1 parent 0d83e3d commit 858c48c3ecbcaedd241085110cdece0f96831873
@@ -2,59 +2,6 @@
path => "Reports/Activity/ActivitySummary.html",
&>
-<& Elements/MiniPlot, data => \%queues &>
+<& Elements/ActivitySummary, %ARGS &>
-<table style="width: 100%">
-<tr class="titlerow">
-<th>Queue</th>
-% for my $status (sort keys %status) {
-<th><% $status %></th>
-% }
-<th>Total</th>
-</tr>
-% for my $queue (sort keys %queues) {
-<th class="label"><% $queue %></th>
-% for my $status (sort keys %status) {
-<td><% $queues{$queue}{$status} || 0 %>
-% }
-<td><% $total{$queue} %></td>
-</tr>
-% }
-<tr class="grandtotal">
-<th class="label" >Grand Total</th>
-% for my $status (sort keys %status) {
-<td><% $status{$status} %></td>
-% }
-<td><% $total %></td>
-</table>
</&>
-<%args>
-$query => ''
-$start => "2005/01/01"
-$end => "2006/01/01"
-</%args>
-<%init>
-my $tickets = RT::Tickets->new($session{'CurrentUser'});
-$tickets->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
-
-my %queues;
-my %status;
-my %total;
-my $total;
-while (my $ticket = $tickets->Next) {
- my $txns = $ticket->Transactions;
- $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
- $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
- $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
- $txns->Limit(FIELD => 'Type', VALUE => 'Create');
-
- while (my $txn = $txns->Next) {
- $queues{$txn->TicketObj->QueueObj->Name}{$txn->NewValue || 'new'}++;
- $status{$txn->NewValue || 'new'}++;
- $total{$txn->TicketObj->QueueObj->Name}++;
- $total++;
- }
-}
-
-
-</%init>
@@ -0,0 +1,57 @@
+
+<& MiniPlot, data => \%queues &>
+
+<table style="width: 100%">
+<tr class="titlerow">
+<th>Queue</th>
+% for my $status (sort keys %status) {
+<th><% $status %></th>
+% }
+<th>Total</th>
+</tr>
+% for my $queue (sort keys %queues) {
+<th class="label"><% $queue %></th>
+% for my $status (sort keys %status) {
+<td><% $queues{$queue}{$status} || 0 %>
+% }
+<td><% $total{$queue} %></td>
+</tr>
+% }
+<tr class="grandtotal">
+<th class="label" >Grand Total</th>
+% for my $status (sort keys %status) {
+<td><% $status{$status} %></td>
+% }
+<td><% $total %></td>
+</table>
+
+<%args>
+$query => ''
+$start => "2005/01/01"
+$end => "2006/01/01"
+</%args>
+<%init>
+my $tickets = RT::Tickets->new($session{'CurrentUser'});
+$tickets->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, "Updated >= '$start' AND Updated <= '$end'"));
+
+my %queues;
+my %status;
+my %total;
+my $total;
+while (my $ticket = $tickets->Next) {
+ my $txns = $ticket->Transactions;
+ $txns->Limit(FIELD => 'Created', OPERATOR => '>=', VALUE => $start);
+ $txns->Limit(FIELD => 'Created', OPERATOR => '<=', VALUE => $end);
+ $txns->Limit(FIELD => 'Type', VALUE => 'Status', ENTRYAGGREGATOR => 'OR');
+ $txns->Limit(FIELD => 'Type', VALUE => 'Create');
+
+ while (my $txn = $txns->Next) {
+ $queues{$txn->TicketObj->QueueObj->Name}{$txn->NewValue || 'new'}++;
+ $status{$txn->NewValue || 'new'}++;
+ $total{$txn->TicketObj->QueueObj->Name}++;
+ $total++;
+ }
+}
+
+
+</%init>
@@ -1,4 +1,4 @@
-<form action="index.html" method="POST" enctype="multipart/form-data">
+<form action="index.html" method="GET">
Query:
<textarea name="query" rows="5" cols="80"><% $query %></textarea><br />
@@ -0,0 +1,60 @@
+
+<table style="width: 100%">
+<tr>
+<th>Queue</th><th>Ticket #</th><th>Created</th><th>Resolved</th><th>Time to resolve</th>
+</tr>
+<tr>
+<th colspan="5">Resolution comments</th>
+</tr>
+% for my $item (@items) {
+<tr class="titlerow">
+<td><% $item->{queue} %></td>
+<td><% $item->{id} %></td>
+<td><% $item->{created} %></td>
+<td><% $item->{resolved} %></td>
+<td><% $item->{duration} %></td>
+</tr>
+<tr>
+<td colspan="5"><% $item->{whiteboard} %></td>
+</tr>
+% }
+</table>
+
+<%args>
+$query => ''
+$start => "2005/01/01"
+$end => "2006/01/01"
+</%args>
+<%init>
+
+use Time::Duration;
+
+my $summary_tickets = RT::Tickets->new( $session{'CurrentUser'} );
+$summary_tickets->FromSQL(
+ join " AND ", map {"($_)"} grep {/\S/} ($query, "(Status = 'resolved') AND ( Updated >= '$start' AND Updated <= '$end')"));
+
+my @items;
+while ( my $ticket = $summary_tickets->Next ) {
+ my $whiteboard = $ticket->CustomFieldValues('Whiteboard') ?
+ $ticket->FirstCustomFieldValue('Whiteboard') : undef;
+ push @items, {
+ queue => $ticket->QueueObj->Name,
+ id => $ticket->id,
+ created => $ticket->CreatedObj->AsString,
+ resolved => $ticket->ResolvedObj->AsString,
+ duration => Time::Duration::concise(
+ Time::Duration::duration(
+ $ticket->ResolvedObj->Unix - $ticket->CreatedObj->Unix
+ )
+ ),
+ whiteboard => $whiteboard,
+ };
+}
+
+@items = sort { $a->{queue} cmp $b->{queue} || $a->{id} <=> $b->{id} } @items;
+
+
+
+
+
+</%init>
@@ -0,0 +1,91 @@
+
+<& MiniPlot,
+ data => \%plot,
+ major => ['Date range','Last 30 days','Last 60 days','Last 90 days','Ever'],
+ minor => [(sort keys %queues), "Average"]
+ &>
+
+<table style="width: 100%">
+<tr>
+<td></td><th colspan="4">Number of tickets closed / Average resolution time per ticket</th>
+</tr>
+<tr class="titlerow">
+<th>Queue</th>
+<th>Date range</th>
+<th>Last 30 days</th>
+<th>Last 60 days</th>
+<th>Last 90 days</th>
+<th>Ever</th>
+</tr>
+% for my $queue (sort keys %queues) {
+<tr>
+<th><% $queue %></th>
+% for my $period ('Date range','Last 30 days','Last 60 days','Last 90 days','Ever') {
+<td><% scalar @{$closed{$period}{$queue} || []} %> / <% $average_resolve_times{$period}{$queue} %></td>
+% }
+</tr>
+% }
+<tr class="grandtotal">
+<th>Ticket average</th>
+% for my $period ('Date range','Last 30 days','Last 60 days','Last 90 days','Ever') {
+<td><% $average_resolve_times{$period}{_all_count} %> / <% $average_resolve_times{$period}{_all} %></td>
+% }
+</tr>
+</table>
+
+<%args>
+$query => ''
+$start => "2005/01/01"
+$end => "2006/01/01"
+</%args>
+<%init>
+
+my $in_30_days = RT::Date->new($session{'CurrentUser'});
+$in_30_days->Set(Format => 'Unix', Value => ( time - (86400*30)));
+my $in_60_days = RT::Date->new($session{'CurrentUser'});
+$in_60_days->Set(Format => 'Unix', Value => ( time - (86400*60)));
+my $in_90_days = RT::Date->new($session{'CurrentUser'});
+$in_90_days->Set(Format => 'Unix', Value => ( time - (86400*90)));
+
+my %queries;
+$queries{'Date range'} = "(Resolved >= '$start' AND Resolved <= '$end')";
+$queries{'Last 30 days'} = "(Resolved >= '".$in_30_days->ISO."')";
+$queries{'Last 60 days'} = "(Resolved >= '".$in_60_days->ISO."')";
+$queries{'Last 90 days'} = "(Resolved >= '".$in_90_days->ISO."')";
+$queries{'Ever'} = "(Status = 'resolved' OR Status = 'rejected')";
+
+
+my %closed;
+my %queues;
+foreach my $period (keys %queries) {
+ my $tix = RT::Tickets->new($session{'CurrentUser'});
+ $tix->FromSQL(join " AND ", map {"($_)"} grep {/\S/} ($query, $queries{$period}));
+
+ while (my $ticket = $tix->Next) {
+ push @{ $closed{$period}{$ticket->QueueObj->Name}}, $ticket;
+ $queues{$ticket->QueueObj->Name}++;
+ }
+}
+
+my %restimes;
+my %average_resolve_times;
+my %plot;
+use Time::Duration;
+foreach my $period ( keys %closed ) {
+ foreach my $queue ( keys %{$closed{$period}} ) {
+ foreach my $ticket (@{$closed{$period}{$queue}} ) {
+ push @{$restimes{$period}{$queue}}, ( $ticket->ResolvedObj->Unix - $ticket->CreatedObj->Unix);
+ }
+
+ my $total_time = 0;
+ $total_time+= $_ for @{$restimes{$period}{$queue}};
+ $average_resolve_times{$period}{'_all_time'} += $total_time;
+ $average_resolve_times{$period}{'_all_count'} += @{$restimes{$period}{$queue}};
+ $plot{$period}{$queue} = $total_time / @{$restimes{$period}{$queue}};
+ $average_resolve_times{$period}{$queue} = Time::Duration::concise(Time::Duration::duration($plot{$period}{$queue}));
+ }
+ $plot{$period}{Average} = $average_resolve_times{$period}{'_all_time'} / $average_resolve_times{$period}{'_all_count'};
+ $average_resolve_times{$period}{'_all'} = Time::Duration::concise(Time::Duration::duration($plot{$period}{Average}));
+}
+
+</%init>
Oops, something went wrong.

0 comments on commit 858c48c

Please sign in to comment.