summaryrefslogtreecommitdiff
path: root/rt/html/RTx/Statistics/DayOfWeek/index.html
blob: 2e82b9c240ef80de0032037870648269a66d821c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<& /Elements/Header, Title =>loc('Tickets by Day Of Week in Queue:' . $QueueObj->Name()) &>
<& /RTx/Statistics/Elements/Tabs, Title =>loc('Trends in ticket status by Day Of Week in Queue:' . $QueueObj->Name()) &>

<h3>Description</h3>
<p>The purpose of this page is to show historical trends for each day of the week. 
It displays details of number of tickets created in your
selected queue for each day. It also hows how many of those created tickets were Resolved or Deleted</p>

<form method="POST" action="index.html">


%my $title = "Ticket counts by day of week in " . $QueueObj->Name();
<&|/Elements/TitleBox, 
	title => $title,
	title_href => "/RTx/Statistics/DayOfWeek/index.html?$QueryString" &>
<TABLE BORDER=0 cellspacing=0 cellpadding=1 WIDTH=100%>
% if ($ShowHeader) {
<& /RTx/Statistics/Elements/CollectionAsTable/Header, 
    Format => \@Format, 
    FormatString => $Format,
    AllowSorting => $AllowSorting, 
    Order => $Order, 
    Query => undef,
    Rows => $Rows,
    Page => $Page,
    OrderBy => $OrderBy , 
    BaseURL => $BaseURL,
    maxitems => $maxitems &> 
% }
% my $line = 1;
% for my $d (0..$#days) {
%     my $x = 1;
%     $values{Statistics_Date} = $days[$d];
%# NOTE Show all status values???
%     $values{Statistics_Created_Count} = $counts[$d]{new};
%     $values{Statistics_Resolved_Count} = $counts[$d]{resolved};
%     $values{Statistics_Deleted_Count} = $counts[$d]{deleted};
<&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@Format, i => $line, record => $record, maxitems => $maxitems &>
%    $line++;
% }
% $values {Statistics_Date} = "Totals";
% $values {Statistics_Created_Count} = $Totals{new};
% $values {Statistics_Resolved_Count} = $Totals{resolved};
% $values {Statistics_Deleted_Count} = $Totals{deleted};
<&   /RTx/Statistics/Elements/CollectionAsTable/Row, Format => \@BoldFormat, i => $line, record => $record, maxitems => $maxitems &>
</table>
</&>

<hr>

<BR />
<BR />

<%perl>
my $url = 'Elements/Chart?&x_labels=';
for (0..$#days) {
  $url .= $days[$_] . "," ;
}
chop $url;
$url .= "&";

my @things = qw(new resolved deleted);
for my $th (0..$#things) {
  $url .= "data".(1+$th)."=".(join ",", map { $counts[$_]{$things[$th]} } (0..6))."&";
}
chop $url;
$url .= '&set_legend=Created,Resolved,Deleted';
</%perl>

<& /RTx/Statistics/Elements/GraphBox, GraphURL => $url &>

% Statistics::DebugLog("queue name=" . $QueueObj->Id() . "\n");

<& /RTx/Statistics/Elements/ControlsAsTable/ControlBox, 
         Title => "Change Queue", 
         ShowSingleQueue => 1, Queue => $QueueObj->Id()
 &>

</form>

% Statistics::DebugInit( $m );

<%ARGS>
$Queue => $Statistics::DayOfWeekQueue

$AllowSorting => undef
$Order => undef
$OrderBy => undef
$ShowNavigation => 1
$ShowHeader => 1
$Rows => 50
$Page => 1
$BaseURL => undef
</%ARGS>

<%INIT>
use GD::Graph;
use RTx::Statistics;
my @days = qw(Sun Mon Tue Wed Thu Fri Sat);
my $n = 0;
my @data = ([]);
my @msgs;
my @counts;
my %Totals = (
  resolved => 0,
  deleted => 0,
  new => 0
);
my $QueryString = "Queue=$Queue";
my $maxitems = 4;
my %record;
my %values;
my $record = \%record;

$record{values} = \%values;

my $Format = qq{ Statistics_Date, 
                 '__Statistics_Created_Count__/STYLE:text-align:right;', 
                 '__Statistics_Resolved_Count__/STYLE:text-align:right;', 
		 '__Statistics_Deleted_Count__/STYLE:text-align:right;' };
my $BoldFormat = qq{ '<B>__Statistics_Date__</B>', 
                     '<B>__Statistics_Created_Count__</B>/STYLE:text-align:right;',
                     '<B>__Statistics_Resolved_Count__</B>/STYLE:text-align:right;',
		     '<B>__Statistics_Deleted_Count__</B>/STYLE:text-align:right;' };
my (@Format) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $Format);
my (@BoldFormat) = $m->comp('/RTx/Statistics/Elements/CollectionAsTable/ParseFormat', Format => $BoldFormat);

my $QueueObj = new RT::Queue($session{'CurrentUser'});
$QueueObj->Load($Queue);
$RT::Logger->warning("Loaded queue $Queue, name=". $QueueObj->Name());

my $tix = new RT::Tickets($session{'CurrentUser'});
$tix->LimitQueue (VALUE => $Queue);
$tix->UnLimit;
if ($tix->Count) {
    # Initialize the counters to zero, so that all the cells show up
    foreach my $day (0..@days) {
        $counts[$day]{resolved} = 0;
        $counts[$day]{deleted} = 0;
        $counts[$day]{new} = 0;
    }
    while (my $t = $tix->RT::SearchBuilder::Next) {  # BLOODY HACK
        if($t->Status eq "resolved") {
          $counts[(localtime($t->ResolvedObj->Unix))[6]]{resolved}++;
	  $Totals{resolved}++;
	}
	if($t->Status eq "deleted") {
	  $counts[(localtime($t->LastUpdatedObj->Unix))[6]]{deleted}++;
	  $Totals{deleted}++;
        }
        $counts[(localtime($t->CreatedObj->Unix))[6]]{new}++;
	$Totals{new}++;
    }
}
</%INIT>