3 # This library is used by Support Stats.
5 # In particular, it's used by the following pages:
6 # - htdocs/admin/support/dept.bml
7 # - htdocs/admin/support/individual.bml
9 # This library doesn't have any DB access routines.
10 # All DB access routines are in supportlib.pl
14 package LJ
::Support
::Stats
;
15 use vars
qw($ALL_CATEGORIES_ID);
22 $ALL_CATEGORIES_ID = -1;
25 # name: LJ::Support::Stats::filter_support_by_category
26 # des: Filter Support by Category ID.
28 # des-support: HashRef of Support Rows indexed by Support ID.
29 # info: Used by dept.bml and individual.bml under
30 # htdocs/admin/support/.
31 # All DB access routines are in supportlib.pl.
32 # Return: Filtered HashRef of Support Rows.
34 sub filter_support_by_category
{
35 my($support_hashref, $category_id_parm) = @_;
37 return $support_hashref if $category_id_parm == $ALL_CATEGORIES_ID;
39 my %filtered_support = ();
40 while (my($support_id, $support) = each %{$support_hashref}) {
41 $filtered_support{$support_id} = $support
42 if $support->{spcatid
} == $category_id_parm;
45 return \
%filtered_support;
49 # name: LJ::Support::Stats::date_formatter
51 # args: year, month, day
52 # des-year: Four digit year (e.g. 2001)
53 # des-month: One-based numeric month: 1-12
54 # des-day: One-based numeric day: 1-31
55 # info: Used by dept.bml and individual.bml under
56 # htdocs/admin/support/.
57 # All DB access routines are in supportlib.pl.
58 # Return: Date formatted as follows: YYYY-MM-DD
61 croak
('Not enough parameters') if @_ < 3;
62 my($year, $month, $day) = @_;
63 my $date = sprintf("%04d-%02d-%02d", $year, $month, $day);
68 # name: LJ::Support::Stats::comma_formatter
69 # des: Format a number with commas
71 # des-number: number to commafy.
72 # info: Used by dept.bml and individual.bml under
73 # htdocs/admin/support/.
74 # All DB access routines are in supportlib.pl.
75 # Return: Number with commas inserted.
78 my $number = shift or croak
('No parameter for comma_formatter');
79 1 while ($number =~ s/([-+]?\d+)(\d\d\d\.?)(?!\d)/$1,$2/);
85 # name: LJ::Support::Stats::percent_formatter
86 # des: Format a percentage: Take integer portion and append percent sign.
88 # des-percent: Number to format as a percentage.
89 # info: Used by dept.bml and individual.bml under
90 # htdocs/admin/support/.
91 # All DB access routines are in supportlib.pl.
92 # Return: Formatted percentage.
94 sub percent_formatter
{
96 $percent = int($percent) . '%';
101 # name: LJ::Support::Stats::get_grains_from_seconds
102 # des: Determine the grains (day/week/month/year) of given a date
104 # des-seconds: Seconds since Unix epoch.
105 # info: Used by dept.bml and individual.bml under
106 # htdocs/admin/support/.
107 # All DB access routines are in supportlib.pl.
108 # Return: HashRef of Grains.
110 sub get_grains_from_seconds
{
111 my $seconds_since_epoch = shift or croak
('No parameter specified');
113 my $date = LJ
::TimeUtil
->mysql_time($seconds_since_epoch);
116 $grain{grand
} = 'Grand';
117 $grain{day
} = substr($date, 0, 10);
118 $grain{month
} = substr($date, 0, 7);
119 $grain{year
} = substr($date, 0, 4);
121 # Get week of Support Ticket
122 my $dt = DateTime
->from_epoch( epoch
=> $seconds_since_epoch );
123 my($week_year, $week_number) = $dt->week;
124 $grain{week
} = $week_year . ' - Week #' . sprintf('%02d', $week_number);