Algorithm-Accounting
view release on metacpan or search on metacpan
lib/Algorithm/Accounting/Report.pm view on Meta::CPAN
package Algorithm::Accounting::Report;
use Spiffy -Base;
our $VERSION = '0.02';
sub process {
my ($occhash,$field_groups,$group_occ) = @_;
for(keys %{$occhash}) {
$self->report_occurrence_percentage($_,$occhash);
}
for(0..@{$field_groups}-1) {
$self->report_field_group_occurrence_percentage($_,$field_groups,$group_occ);
}
}
__END__
=head1 NAME
Algorithm::Accounting::Report - report generating of Algorithm::Accounting result
=head1 COPYRIGHT
lib/Algorithm/Accounting/Report/GDGraph.pm view on Meta::CPAN
package Algorithm::Accounting::Report::GDGraph;
use Algorithm::Accounting::Report -Base;
use GD::Graph::pie;
use Digest::MD5 qw(md5_hex);
use FreezeThaw qw(thaw);
use List::Util qw(sum);
our $VERSION = '0.01';
sub report_occurrence_percentage {
my ($field,$occhash) = @_;
my $occ = $occhash->{$field};
my (@labels, @values);
for(sort {$occ->{$b} <=> $occ->{$a} } keys %$occ) {
push @labels, $_;
push @values, $occ->{$_};
}
my $graph = GD::Graph::pie->new(640,480);
my $img = $graph->plot([\@labels,\@values]);
my $filename = md5_hex($occ);
$self->save($img,$filename,$graph->export_format);
}
sub report_field_group_occurrence_percentage {
print STDERR "XXX: Fixme. I don't now how to draw group occurrence into graphs\n";
}
sub save {
my ($obj,$file,$format) = @_;
open(IMG, ">${file}.${format}") or die $!;
binmode IMG;
print IMG $obj->$format();
close IMG;
print STDERR "${file}.${format} saved\n";
lib/Algorithm/Accounting/Report/Imager.pm view on Meta::CPAN
package Algorithm::Accounting::Report::Imager;
use Algorithm::Accounting::Report -Base;
use Imager::Graph::Pie;
use Digest::MD5 qw(md5_hex);
use FreezeThaw qw(thaw);
use List::Util qw(sum);
our $VERSION = '0.01';
sub report_occurrence_percentage {
my ($field,$occhash) = @_;
my $occ = $occhash->{$field};
my (@labels, @values);
for(sort {$occ->{$b} <=> $occ->{$a} } keys %$occ) {
push @labels, $_;
push @values, $occ->{$_};
}
my $chart = Imager::Graph::Pie->new;
my $img = $chart->draw(
labels => \@labels,
data => \@values,
size => [640,480],
);
my $filename = md5_hex($occ);
$self->save($img,$filename);
}
sub report_field_group_occurrence_percentage {
my $i = shift; # Only the i-th field group
my $field_groups = shift;
my $group_occurrence = shift;
my @field = @{$field_groups->[$i]};
my $occ = $group_occurrence->[$i];
my $rows = sum(values %$occ);
}
sub save {
my ($obj,$file) = @_;
lib/Algorithm/Accounting/Report/Text.pm view on Meta::CPAN
package Algorithm::Accounting::Report::Text;
use Algorithm::Accounting::Report -Base;
use Perl6::Form;
use FreezeThaw qw(thaw);
use List::Util qw(sum);
our $VERSION = '0.02';
# Do I really have to named it so ?
sub report_occurrence_percentage {
my ($field,$occhash) = @_;
my $occ = $occhash->{$field};
my $rows = sum(values %$occ);
my $sep = "+===========================================+";
print form
$sep,
"| {>>>>>>>>>>>>>>>>>>>>>>>>} | {>>>>>>>>>>} |",
$field, 'Percentage',
$sep;
lib/Algorithm/Accounting/Report/Text.pm view on Meta::CPAN
"| {>>>>>>>>>>>>>>>>>>>>>>>>} | {>>>>>>>>.}% |",
$_, (100 * $occ->{$_} / $rows) ;
}
print form
$sep,
'| {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<} |',
"Total records: $rows",
$sep, "\n";
}
sub report_field_group_occurrence_percentage {
my $i = shift; # Only the i-th field group
my $field_groups = shift;
my $group_occurrence = shift;
my @field = @{$field_groups->[$i]};
my $occ = $group_occurrence->[$i];
my $rows = sum(values %$occ);
local $, = ',';
my $form_format = '|' . join('|',map {'{<<<<<<<<<<<<}'} @field) . '|{>>>>>>>>>>>>}|';
my $sep = '+' . '=' x (15*(1+@field) - 1) . '+';
( run in 0.331 second using v1.01-cache-2.11-cpan-05162d3a2b1 )