michael@0: #!/usr/bin/perl michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: use CGI::Carp qw(fatalsToBrowser); michael@0: use CGI::Request; michael@0: use URLTimingDataSet; michael@0: use URLTimingGraph; michael@0: michael@0: my $request = new CGI::Request; michael@0: michael@0: my $id = $request->param('id'); #XXX need to check for valid parameter id michael@0: my $id2 = $request->param('id2') || undef; # possible comparison test michael@0: michael@0: # set up the data for the first graph michael@0: my $rs = URLTimingDataSet->new($id); michael@0: my @data = (); michael@0: push @data, [ map($_->[1], @{$rs->{sorted}}) ]; # URL michael@0: push @data, [ map($_->[4], @{$rs->{sorted}}) ]; # median michael@0: # '7' is the first slot for individual test run data michael@0: for (my $idx = 7; $idx < (7+$rs->{count}); $idx++) { michael@0: push @data, [ map($_->[$idx], @{$rs->{sorted}}) ]; michael@0: } michael@0: michael@0: michael@0: # set up the data for the second graph, if requested a second id michael@0: # need to sort according to the first chart's ordering michael@0: my $rs2; michael@0: if ($id2) { michael@0: $rs2 = URLTimingDataSet->new($id2); michael@0: my @order = map($_->[0], @{$rs->{sorted}}); # get the first chart's order michael@0: my @resort = (); michael@0: for my $i (@order) { michael@0: for (@{$rs2->{sorted}}) { michael@0: if ($i == $_->[0]) { michael@0: push @resort, $_; michael@0: last; michael@0: } michael@0: } michael@0: } michael@0: push @data, [ map($_->[4], @resort) ]; # median michael@0: for (my $idx = 7; $idx < (7+$rs2->{count}); $idx++) { michael@0: push @data, [ map($_->[$idx], @resort) ]; michael@0: } michael@0: } michael@0: michael@0: # and now convert 'NaN' to undef, if they exist in the data. michael@0: for (@data) { for (@$_) { $_ = undef if $_ eq "NaN"; } } michael@0: michael@0: # set up the chart parameters michael@0: my $args = {}; michael@0: $args->{cgimode} = 1; michael@0: $args->{title} = "id=$id"; michael@0: michael@0: # need to draw first visit as dotted with points michael@0: my $types = ['lines','lines']; for (1..$rs->{count}-1) { push @$types, undef; } michael@0: my $dclrs = []; for (0..$rs->{count}) { push @$dclrs, 'lred'; } michael@0: my $legend = [$id]; for (1..$rs->{count}) { push @$legend, undef; } michael@0: if ($id2) { michael@0: push @$types, 'lines'; for (1..$rs2->{count}) { push @$types, undef; } michael@0: for (0..$rs2->{count}) { push @$dclrs, 'lblue'; } michael@0: push @$legend, $id2; for (1..$rs2->{count}) { push @$legend, undef; } michael@0: } michael@0: $args->{types} = $types; michael@0: $args->{dclrs} = $dclrs; michael@0: $args->{legend} = $legend; michael@0: michael@0: #XXX set min to zero, and round max to 1000 michael@0: $args->{y_max_value} = maxDataOrCap(); michael@0: ## nope $args->{y_min_value} = 1000; michael@0: $args->{width} = 800; michael@0: $args->{height} = 720; michael@0: michael@0: my $g = URLTimingGraph->new(\@data, $args); michael@0: $g->plot(); michael@0: michael@0: exit; michael@0: michael@0: michael@0: sub maxDataOrCap { michael@0: my $max; michael@0: warn $rs->{maximum}; michael@0: if ($rs2 && ($rs->{maximum} < $rs2->{maximum})) { michael@0: $max = $rs2->{maximum}; michael@0: } else { michael@0: $max = $rs->{maximum}; michael@0: } michael@0: warn $max; michael@0: #return $max > 10000 ? 10000 : 1000*int($max/1000)+1000; michael@0: # just return whatever, rounded to 1000 michael@0: return 1000*int($max/1000)+1000; michael@0: }