stas 2002/11/07 21:26:05
Modified: src/outstanding/stats graph.pl
Log:
reformat the code to read nicely, no logic change
Revision Changes Path
1.5 +104 -109 modperl-docs/src/outstanding/stats/graph.pl
Index: graph.pl
===================================================================
RCS file: /home/cvs/modperl-docs/src/outstanding/stats/graph.pl,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- graph.pl 8 Nov 2002 05:11:41 -0000 1.4
+++ graph.pl 8 Nov 2002 05:26:05 -0000 1.5
@@ -35,13 +35,14 @@
print STDERR "Processing data\n";
-my @data = read_data_from_csv("input.data")
- or die "Cannot read data from input.data";
+my $input_file = "input.data";
+my @data = read_data_from_csv($input_file)
+ or die "Cannot read data from $input_file";
# make the Y axis to be optimally used
my $max_y = 0;
-foreach (@{$data[1]},@{$data[2]}) {
- $max_y = $_ if $_ > $max_y ;
+foreach (@{$data[1]}, @{$data[2]}) {
+ $max_y = $_ if $_ > $max_y ;
}
# normalize it
$max_y = ( int $max_y / 1000 + 1 ) * 1000;
@@ -51,123 +52,117 @@
pseudo_graph();
# plot a normal graph of points with all the info as possible
-sub normal_graph{
- my $my_graph = new GD::Graph::linespoints(600,400);
+sub normal_graph {
+ my $my_graph = new GD::Graph::linespoints(600, 400);
- $my_graph->set(
- x_label => 'Months',
- y_label => 'Counts',
- title => "mod_perl usage survey (numbers are by courtesy of
netcraft.com).",
- y_max_value => $max_y,
- y_label_skip => 1,
- x_label_skip => 3,
- x_labels_vertical => 1,
- x_label_position => 1/2,
- markers => [ 1, 7 ],
- marker_size => 2,
- transparent => 1,
- t_margin => 10,
- b_margin => 10,
- l_margin => 10,
- r_margin => 10,
-
- two_axes => 1,
- logo => 'logo.png',
- logo_position => 'LL',
- );
-
- #$my_graph->set( dclrs => [ qw(green pink blue cyan) ] );
-
- $my_graph->set_x_label_font(GD::gdMediumBoldFont);
- $my_graph->set_y_label_font(GD::gdMediumBoldFont);
- $my_graph->set_x_axis_font(GD::gdMediumBoldFont);
- $my_graph->set_y_axis_font(GD::gdMediumBoldFont);
- $my_graph->set_title_font(GD::gdGiantFont);
-
- $my_graph->set_legend('Hostnames','Unique IP numbers' );
- $my_graph->set_legend_font(GD::gdMediumBoldFont);
-
-
- open IMG, '>graph.jpg' or die $!;
- print IMG $my_graph->plot([EMAIL PROTECTED])->jpeg(70);
- close IMG;
-# $my_graph->plot_to_gif( "graph.gif", [EMAIL PROTECTED] );
+ $my_graph->set(
+ x_label => 'Months',
+ y_label => 'Counts',
+ title => "mod_perl usage survey (numbers are by courtesy of
netcraft.com).",
+ y_max_value => $max_y,
+ y_label_skip => 1,
+ x_label_skip => 3,
+ x_labels_vertical => 1,
+ x_label_position => 1/2,
+ markers => [ 1, 7 ],
+ marker_size => 2,
+ transparent => 1,
+ t_margin => 10,
+ b_margin => 10,
+ l_margin => 10,
+ r_margin => 10,
+
+ two_axes => 1,
+ logo => 'logo.png',
+ logo_position => 'LL',
+ );
+
+ #$my_graph->set( dclrs => [ qw(green pink blue cyan) ] );
+
+ $my_graph->set_x_label_font(GD::gdMediumBoldFont);
+ $my_graph->set_y_label_font(GD::gdMediumBoldFont);
+ $my_graph->set_x_axis_font(GD::gdMediumBoldFont);
+ $my_graph->set_y_axis_font(GD::gdMediumBoldFont);
+ $my_graph->set_title_font(GD::gdGiantFont);
+
+ $my_graph->set_legend('Hostnames','Unique IP numbers' );
+ $my_graph->set_legend_font(GD::gdMediumBoldFont);
+
+ open IMG, '>graph.jpg' or die "Can't create graph.jpg: $!";
+ print IMG $my_graph->plot([EMAIL PROTECTED])->jpeg(70);
+ close IMG;
+ # $my_graph->plot_to_gif( "graph.gif", [EMAIL PROTECTED] );
}
# plot a small graph of points with as least info as possible
-sub pseudo_graph{
- my $my_graph = new GD::Graph::linespoints(350,200);
+sub pseudo_graph {
+ my $my_graph = new GD::Graph::linespoints(350,200);
# in this graph we don't want X labels to be printed
- for (0..$#{$data[0]}) {
- $data[0]->[$_] = "";
- }
-
- $my_graph->set(
- y_max_value => $max_y,
- y_label_skip => 0,
- x_label_skip => 1,
- x_labels_vertical => 1,
- x_label_position => 1/2,
- markers => [ 1, 7 ],
- marker_size => 2,
- transparent => 1,
- t_margin => 10,
- b_margin => 10,
- l_margin => 10,
- r_margin => 10,
- two_axes => 0,
-
- logo => 'logo-middle.png',
- logo_position => 'UL',
- );
-
- #$my_graph->set( dclrs => [ qw(green pink blue cyan) ] );
-
- $my_graph->set_x_label_font(GD::gdMediumBoldFont);
- $my_graph->set_y_label_font(GD::gdSmallFont);
- $my_graph->set_x_axis_font(GD::gdMediumBoldFont);
- $my_graph->set_y_axis_font(GD::gdSmallFont);
- $my_graph->set_title_font(GD::gdGiantFont);
-
- $my_graph->set_legend('Hostnames','Unique IP numbers' );
- $my_graph->set_legend_font(GD::gdSmallFont);
-
-
- open IMG, '>pseudo-graph.jpg' or die $!;
- print IMG $my_graph->plot([EMAIL PROTECTED])->jpeg(70);
- close IMG;
- #$my_graph->plot_to_gif( "pseudo-graph.gif", [EMAIL PROTECTED] );
-
+ for (0..$#{$data[0]}) {
+ $data[0]->[$_] = "";
+ }
+
+ $my_graph->set(
+ y_max_value => $max_y,
+ y_label_skip => 0,
+ x_label_skip => 1,
+ x_labels_vertical => 1,
+ x_label_position => 1/2,
+ markers => [ 1, 7 ],
+ marker_size => 2,
+ transparent => 1,
+ t_margin => 10,
+ b_margin => 10,
+ l_margin => 10,
+ r_margin => 10,
+ two_axes => 0,
+
+ logo => 'logo-middle.png',
+ logo_position => 'UL',
+ );
+
+ #$my_graph->set( dclrs => [ qw(green pink blue cyan) ] );
+
+ $my_graph->set_x_label_font(GD::gdMediumBoldFont);
+ $my_graph->set_y_label_font(GD::gdSmallFont);
+ $my_graph->set_x_axis_font(GD::gdMediumBoldFont);
+ $my_graph->set_y_axis_font(GD::gdSmallFont);
+ $my_graph->set_title_font(GD::gdGiantFont);
+
+ $my_graph->set_legend('Hostnames','Unique IP numbers' );
+ $my_graph->set_legend_font(GD::gdSmallFont);
+
+ open IMG, '>pseudo-graph.jpg' or die "Can't create pseudo-graph.jpg: $!";
+ print IMG $my_graph->plot([EMAIL PROTECTED])->jpeg(70);
+ close IMG;
+ #$my_graph->plot_to_gif( "pseudo-graph.gif", [EMAIL PROTECTED] );
}
-sub read_data_from_csv
-{
- my $fn = shift;
- my @d = ();
-
- open(ZZZ, $fn) || return ();
-
- while (<ZZZ>)
- {
- chomp;
-
- next if /^#/;
-
- # you might want Text::CSV here
- my @row = split /\t/;
-
- for (my $i = 0; $i <= $#row; $i++)
- {
- undef $row[$i] if ($row[$i] eq 'undef');
- unshift @{$d[$i]}, $row[$i];
- }
+sub read_data_from_csv {
+ my $fn = shift;
+ my @d = ();
+
+ open ZZZ, $fn or return ();
+
+ while (<ZZZ>) {
+ chomp;
+
+ next if /^#/;
+
+ # you might want Text::CSV here
+ my @row = split /\t/;
+
+ for (my $i = 0; $i <= $#row; $i++) {
+ undef $row[$i] if $row[$i] eq 'undef';
+ unshift @{$d[$i]}, $row[$i];
}
+ }
- close (ZZZ);
+ close ZZZ;
- return @d;
+ return @d;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]