X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_port.pm;h=ad92e68f6f4469c901e0e7c1d61698ba1a89c76d;hb=4fc9163c63678a4fd19ed0b31f25f97cc0ac2748;hp=33de08d811385285e14e10f495effd244e171328;hpb=38b2dffeb80f5e943a8f0237deee19ac24edaca9;p=freeside.git diff --git a/FS/FS/svc_port.pm b/FS/FS/svc_port.pm index 33de08d81..ad92e68f6 100644 --- a/FS/FS/svc_port.pm +++ b/FS/FS/svc_port.pm @@ -3,11 +3,13 @@ package FS::svc_port; use strict; use vars qw($conf $system $DEBUG $me ); use base qw( FS::svc_Common ); -use FS::Record qw( qsearch qsearchs dbh - str2time_sql str2time_sql_closing concat_sql ); #dbh +use FS::UID qw( driver_name ); +use FS::Record qw( qsearch qsearchs + str2time_sql str2time_sql_closing concat_sql ); use FS::cust_svc; use GD::Graph; use GD::Graph::mixed; +use GD; use Date::Format qw(time2str); use Data::Dumper; @@ -252,12 +254,15 @@ sub graph_png { $start = $opt{start} if $opt{start}; $end = $opt{end} if $opt{end}; + $end = $now if $end > $now; + return 'Invalid date range' if ($start < 0 || $start >= $end || $end <= $start || $end < 0 || $end > $now || $start > $now || $end-$start > 86400*366 ); - my $_date = str2time_sql. concat_sql([ 'srv_date', "' '", 'srv_time' ]). - str2time_sql_closing; + my $_date = concat_sql([ 'srv_date', "' '", 'srv_time' ]); + $_date = "CAST( $_date AS TIMESTAMP )" if driver_name =~ /^Pg/i; + $_date = str2time_sql. $_date. str2time_sql_closing; my $serviceid_sql = "('${serviceid}_IN','${serviceid}_OUT')"; @@ -271,6 +276,12 @@ sub graph_png { 'order_by' => "order by $_date asc", }); + if ( ! scalar(@records) ) { + warn "$me no records returned for $serviceid\n"; + return ''; #should actually return a blank png (or, even better, the + # error message in the image) + } + warn "$me ". scalar(@records). " records returned for $serviceid\n" if $DEBUG; @@ -283,8 +294,8 @@ sub graph_png { foreach my $rec ( @records ) { push @times, $rec->_date unless grep { $_ eq $rec->_date } @times; - push @in, $rec->value if $rec->serviceid =~ /_IN$/; - push @out, $rec->value if $rec->serviceid =~ /_OUT$/; + push @in, $rec->value*8 if $rec->serviceid =~ /_IN$/; + push @out, $rec->value*8 if $rec->serviceid =~ /_OUT$/; } my $timediff = $times[-1] - $times[0]; # they're sorted ascending @@ -331,12 +342,18 @@ sub graph_png { my @data = ( \@times, \@in, \@out ); + # hardcoded size, colour, etc. - my $graph = new GD::Graph::mixed(600,320); #600,400 + + # don't change width/height other than through here; breaks legend otherwise + my $width = 600; + my $height = 360; + + my $graph = new GD::Graph::mixed($width,$height); $graph->set( types => ['area','lines'], dclrs => ['green','blue'], - x_label => "(In Out) Current: $in_curr $out_curr Average: $in_avg $out_avg Maximum: $in_max $out_max Minimum: $in_min $out_min", + x_label => ' ', x_tick_number => 'auto', x_number_format => sub { my $value = shift; @@ -355,8 +372,10 @@ sub graph_png { my $value = shift; $self->_format_bandwidth($value,1); }, + y_tick_number => 'auto', y_label => 'bps', legend_placement => 'BR', + lg_cols => 1, title => $self->serviceid, ) or return "can't create graph: ".$graph->error; @@ -364,9 +383,26 @@ sub graph_png { or return "can't set text colour: ".$graph->error; $graph->set_legend(('In','Out')) or return "can't set legend: ".$graph->error; + $graph->set_title_font(['verdana', 'arial', gdGiantFont], 16) + or return "can't set title font: ".$graph->error; + $graph->set_legend_font(['verdana', 'arial', gdMediumBoldFont], 12) + or return "can't set legend font: ".$graph->error; + $graph->set_x_axis_font(['verdana', 'arial', gdMediumBoldFont], 12) + or return "can't set font: ".$graph->error; + $graph->set_y_axis_font(['verdana', 'arial', gdMediumBoldFont], 12) + or return "can't set font: ".$graph->error; + $graph->set_y_label_font(['verdana', 'arial', gdMediumBoldFont], 12) + or return "can't set font: ".$graph->error; my $gd = $graph->plot(\@data); return "graph error: ".$graph->error unless($gd); + + my $black = $gd->colorAllocate(0,0,0); + $gd->string(gdMediumBoldFont,50,$height-35, + "Current: $in_curr Average: $in_avg Maximum: $in_max Minimum: $in_min",$black); + $gd->string(gdMediumBoldFont,50,$height-15, + "Current: $out_curr Average: $out_avg Maximum: $out_max Minimum: $out_min",$black); + return $gd->png; }