Audio-DB
view release on metacpan or search on metacpan
DB/Reports.pm view on Meta::CPAN
push(@$background,255,255,0) unless @$background;
my ($bred,$bgreen,$bblue) = @{$background};
my $bg = $im->colorAllocate($bred,$bgreen,$bblue);
push(@$foreground,0,255,255) unless @$foreground;
my ($fred,$fgreen,$fblue) = @$foreground;
my $fg = $im->colorAllocate($fred,$fgreen,$fblue);
my $black = $im->colorAllocate(0,0,0);
my $blue = $im->colorAllocate(0,0,255);
$im->transparent($bg);
$im->rectangle(0 + $PADLEFT,0 + $PADTOP,
$width - $PADRIGHT,$height - $PADBOTTOM,$black);
# Set up the axis, grid, and labels
# Create a suitable scale of y-axis tick marks
# if drawing 10 up the axis
my $division = int($biggest_year/10);
my $total = $division * 10;
for (my $i = 0;$i<=9;$i++) {
my $y1 = ($division * $i) * $yscale + $PADBOTTOM;
print STDERR $division . '-' . $y1,"\n" if DEBUG;
$im->line(0+$PADLEFT-5,$y1,0 + $PADLEFT,$y1,$black);
$im->line(0+$PADLEFT,$y1,$width - $PADRIGHT,$y1,$blue);
$im->string(gdTinyFont,$PADLEFT-20,$y1-(gdTinyFont->height/2),($total - ($division*$i)),$black);
}
$im->stringUp(gdSmallFont,0+5,((($height - $PADTOP - $PADBOTTOM)/2) + (gdSmallFont->height * 1)/2),
'TOTAL ' . uc($class),$black);
$im->string(gdSmallFont,
(($width - $PADLEFT - $PADRIGHT)/2) + ((gdSmallFont->width * 5)/2),$height-20,'YEARS',$black);
# Now I need to iterate through the range drawing boxes
# Dynamically set the box width based on the number of years seen
my $boxwidth = ($width - ($PADLEFT + $PADRIGHT)) / scalar (@$range);
my $xoffset;
foreach my $year (@$range) {
my $total = $years_seen{$year} || 0;
# normalize the yoffset to the biggest column
my $y1 = int(($height - $PADBOTTOM) - ($total * $yscale));
my $x1 = int($PADLEFT + $xoffset);
my $x2 = int($x1 + $boxwidth);
my $y2 = int($height - $PADBOTTOM);
$im->filledRectangle($x1,$y1,$x2,$y2,$fg);
$im->rectangle($x1,$y1,$x2,$y2,$black);
# $im->stringUp(gdTinyFont,$x1-2,$y2+25,$year,$black);
# Add the year and totals
$im->stringUp(gdTinyFont,$x1 + ((gdTinyFont->width * 1)/2),$y2+25,$year,$black);
unless ($omit_totals) {
$im->stringUp(gdTinyFont,$x1 + ((gdTinyFont->width * 1)/2),$y1-5,$total,$black);
}
$xoffset += $boxwidth;
print STDERR join("\t",$year,$total,$x1,$y1,$x2,$y2),"\n" if DEBUG
}
my $string = $im->png;
return $string;
}
=pod
=item $report->library_size()
Calculate the full size of your library. Returns a hash reference
containing the size in kilobytes (Kb), megabytes (MB), and the size in
gigabytes (GB).
=cut
sub library_size {
my $self = shift;
my $adaptor = $self->adaptor;
my $size = $adaptor->query_for_total('filesize');
my %stats;
$stats{MB} = sprintf ('%.3f',($size / (1024 * 1024)));
$stats{GB} = sprintf ('%.3f',($size / (1024 * 1024 * 1024)));
$stats{Kb} = $size;
return \%stats;
}
=pod
=item $report->library_duration()
Calculate the full duration of your library. Returns a hash reference
containing the breakdown of the total duration using the hash keys
days, minutes, hours, and seconds. For convenience, the total time is
also returned as a formatted string of DD::HH::MM::SS under the hash
key "total_time".
=cut
sub library_duration {
my $self = shift;
my $adaptor = $self->adaptor;
my $milliseconds = $adaptor->query_for_total('seconds');
my $seconds = int($milliseconds / 1000);
my $days = _save_remainder($seconds,60 * 60 * 24);
my $hours = _save_remainder($seconds,60 * 60);
my $min = _save_remainder($seconds,60);
my %stats;
$stats{days} = $days;
$stats{minutes} = $min;
$stats{hours} = $hours;
$stats{seconds} = int $seconds;
$stats{total_time} = join(':',$days,$hours,$min,$seconds);
return \%stats;
}
sub _save_remainder {
my ($val) = int($_[0] / $_[1]);
$_[0] -= $val * $_[1];
return $val;
}
( run in 1.161 second using v1.01-cache-2.11-cpan-df04353d9ac )