<& Header, TabText => 'Site Statistics' &>

<&|/l&>Total Projects</&>: <% $TotalProjects || 0 %><br/>
<&|/l&>Total Members</&>:  <% $TotalMembers  || 0 %><br/>

% for(@CFFields) {
%   my $field = $_;
%   $Result = $QueueAcc->result($field);
%   $Label  = freeze(keys %$Result);
%   $Data   = freeze(values %$Result);
<h3><% loc($_) %></h3>
<img src="Graph/Pie?Label=<% $Label |u %>;Data=<% $Data | u %>" />
% }

<h3><% loc('Ticket Status') %></h3>
<span><&|/l&>Total Tickets</&>:  <% $TotalTickets || 0 %></span><br/>

% $Result  = $TicketAcc->result('status');
% $Label   = freeze(keys %$Result);
% $Data    = freeze(values %$Result);
<img src="Graph/Pie?Label=<% $Label |u %>;Data=<% $Data | u %>" />

<& Footer &>

<%INIT>
;;; # Move your ass, girl.
use Algorithm::Accounting;
use List::Util qw(sum);
use FreezeThaw qw(freeze thaw);
use YAML;

my @CFFields = ('Topic', 'Maturity', 'Platform', 'License', 'Programming Language', 'Intended Audience');
my $GetCFValue = sub {
    my $Q = shift;
    my @Values = map {
	my $field = join('',split(/ /,$_));
	my $qobj  = $Q->OriginObj;
	$qobj ?
	[map { $_->Content or 'Unknown' } @{$qobj->CustomFieldValues($field)->ItemsArrayRef}]
	: [];
    } @CFFields;
    return @Values;
};

my $QueueAcc  = Algorithm::Accounting->new(fields => ['QueueId',@CFFields]);
my $Queues = $m->comp('ProjectQueues');
while(my $Q = $Queues->Next) {
    $QueueAcc->append_data([[ $Q->Id, $GetCFValue->($Q)  ]]);
}


my ($ProjectAcc, $TotalProjects,$TotalMembers) = $m->comp('ProjectAcc');
my $TicketAcc     = $m->comp('TicketAcc');

my $QueueTickets  = $TicketAcc->result->[0];
my $TotalTickets  = $TicketAcc->result->[1]->{'tickets'};

my ($Result,$Label,$Data);

</%INIT>

