summaryrefslogtreecommitdiff
path: root/rt/lib/RTx/Statistics.pm
blob: 8b9d6e4f0169b3c389e23899f63f76d5ed91fa4a (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package Statistics;

use vars qw(
$MultiQueueStatus $MultiQueueDateFormat @MultiQueueQueueList $MultiQueueMaxRows $MultiQueueWeekends $MultiQueueLabelDateFormat
$PerDayStatus $PerDayDateFormat $PerDayQueue $PerDayMaxRows $PerDayWeekends $PerDayLabelDateFormat $PerDayPeriod
$DayOfWeekQueue
@OpenStalledQueueList $OpenStalledWeekends
$TimeToResolveDateFormat $TimeToResolveQueue $TimeToResolveMaxRows $TimeToResolveWeekends $TimeToResolveLabelDateFormat
$TimeToResolveGraphQueue
@years @months %monthsMaxDay
$secsPerDay
$RestrictAccess
$GraphWidth $GraphHeight
);

use Time::Local;

# I couldn't figure out a way to override these in RT_SiteConfig, which would be
# preferable.

# Width and Height of all graphics
$GraphWidth=500;
$GraphHeight=400;

# Initial settings for the CallsMultiQueue stat page
$MultiQueueStatus = "resolved";
$MultiQueueDateFormat = "%a %b %d %Y";  # format for dates on Multi Queue report, see "man strftime" for options
@MultiQueueQueueList = ("General"); # list of queues to start Multi Queue per day reports
$MultiQueueMaxRows = 10;
$MultiQueueWeekends = 1;
$MultiQueueLabelDateFormat = "%a";

# Initial settings for the CallsQueueDay stat page
$PerDayStatus = "resolved";
$PerDayDateFormat = "%a %b %d %Y";
$PerDayQueue = "General";
$PerDayMaxRows = 10;
$PerDayWeekends = 1;
$PerDayLabelDateFormat = "%a";
$PerDayPeriod = 10;

# Initial settings for the DayOfWeek stat page
$DayOfWeekQueue = "General";

# Initial settings for the OpenStalled stat page
@OpenStalledQueueList = ("General");
$OpenStalledWeekends = 1;

# Initial settings for the TimeToResolve stat page
$TimeToResolveDateFormat = "%a %b %d"; 
$TimeToResolveQueue = "General";
$TimeToResolveMaxRows = 10;
$TimeToResolveWeekends = 1;
$TimeToResolveLabelDateFormat = "%a";

# Initial settings for the TimeToResolve Graph page
$TimeToResolveGraphQueue = "General";

$secsPerDay = 86400;

# List of years and months to populate drop down lists
@years =('2010', '2009', '2008', '2007', '2006', '2005', '2004', '2003' ,'2003' ,'2002');
@months=qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;	  
%monthsMaxDay = (
		 0 => 31,  # January
		 1 => 29,  # February, allow for leap year
		 2 => 31,  # March
		 3 => 30,  # April
		 4 => 31,  # May
		 5 => 30,  # June
		 6 => 31,  # July
		 7 => 31,  # August
		 8 => 30,  # September
		 9 => 31,  # October
		 10=> 30,  # November
		 11=> 31   # December
		 );

# Set to one to prevent users without the ShowConfigTab right from seeing Statistics
$RestrictAccess = 0;

# Variables to control debugging
my $debugging=0;  # set to 1 to enable debugging
my $debugtext="";

=head2 FormatDate 

Returns a string representing the specified date formatted by the specified string

=cut
sub FormatDate {
    my $fmt = shift;
    my $self = shift;
    return POSIX::strftime($fmt, localtime($self->Unix));
}


=head2 RTDateSetToLocalMidnight

Sets the date to midnight (at the beginning of the day) local time
Returns the unixtime at midnight.

=cut
sub RTDateSetToLocalMidnight {
    my $self = shift;
    
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($self->Unix);
    $self->Unix(timelocal (0,0,0,$mday,$mon,$year,$wday,$yday));
    
    return ($self->Unix);
}

=head2 RTDateIsWeekend

Returns 1 if the date is on saturday or sunday

=cut
sub RTDateIsWeekend {
    my $self = shift;
    
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($self->Unix);
    return 1 if (($wday==6) || ($wday==0));
    0;
}

=head2 RTDateGetDateWeekday

Returns the localized name of the day specified by date

=cut
sub RTDateGetDateWeekday {
    my $self = shift;
    
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime($self->Unix);
    return $self->GetWeekday($wday);
}

=head2 RTDateSubDay

Subtracts 24 hours from the current time

=cut

sub RTDateSubDay {
    my $self = shift;
    $self->AddSeconds(0 - $DAY);
}

=head2 RTDateSubDays $DAYS

Subtracts 24 hours * $DAYS from the current time

=cut

sub RTDateSubDays {
    my $self = shift;
    my $days = shift;
    $self->AddSeconds(0 - ($days * $DAY));
}

=head2 DebugInit

Creates a text area on the page if debugging is on.

=cut

sub DebugInit {
    if($debugging) {
	my $m = shift;
	$m->print("<TEXTAREA NAME=debugarea COLS=120 ROWS=50>$debugtext</TEXTAREA>\n");
    }
}

=head2 DebugLog $logmsg

Adds a message to the debug area

=cut

sub DebugLog {
    if($debugging) {
	my $line = shift;
	$debugtext .= $line;
	$RT::Logger->debug($line);
    }
}

=head2 DebugClear

Clears the current debug string, otherwise it builds from page to page

=cut

sub DebugClear {
    if($debugging) {
	$debugtext = undef;
    }
}

=head2 DurationAsString 

Returns a string representing the specified duration

=cut

sub DurationAsString {
  my $Duration = shift;
  my $MINUTE = 60;
  my $HOUR =  $MINUTE*60;
  my $DAY = $HOUR * 24;
  my $WEEK = $DAY * 7;
  my $days = int($Duration / $DAY);
  $Duration = $Duration % $DAY;
  my $hours = int($Duration / $HOUR);
  $hours = sprintf("%02d", $hours);
  $Duration = $Duration % $HOUR;
  my $minutes = int($Duration/$MINUTE);
  $minutes = sprintf("%02d", $minutes);
  $Duration = $Duration % $MINUTE;
  my $secs = sprintf("%02d", $Duration);

  if(!$days) {
      $days = "00";
  }
  if(!$hours) {
      $hours = "00";
  }
  if(!$minutes) {
      $minutes = "00";
  }
  if(!$secs) {
      $secs = "00";
  }
  return "$days days $hours:$minutes:$secs";
}

1;