#!/usr/bonsaitools/bin/perl -w # -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public License # Version 1.0 (the "License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the # License for the specific language governing rights and limitations # under the License. # # The Original Code is the Bugzilla Bug Tracking System. # # The Initial Developer of the Original Code is Netscape Communications # Corporation. Portions created by Netscape are Copyright (C) 1998 # Netscape Communications Corporation. All Rights Reserved. # # Contributor(s): Harrison Page , # Terry Weissman use diagnostics; use strict; use Chart::Lines; require "CGI.pl"; require "globals.pl"; use vars @::legal_product; my $dir = "data/mining"; my $week = 60 * 60 * 24 * 7; my @status = qw (NEW ASSIGNED REOPENED); # while this looks odd/redundant, it allows us to name # functions differently than the value passed in my %reports = ( "most_doomed" => \&most_doomed, "show_chart" => \&show_chart, ); # patch from Sam Ziegler : # # "reports.cgi currently has it's own idea of what # the header should be. This patch sets it to the # system wide header." print "Content-type: text/html\n\n"; if (defined $::FORM{'nobanner'}) { print < Bug Reports FIN } else { PutHeader ("Bug Reports") unless (defined $::FORM{'nobanner'}); } ConnectToDatabase(); GetVersionTable(); $::FORM{'output'} = $::FORM{'output'} || "most_doomed"; # a reasonable default if (! defined $::FORM{'product'}) { &choose_product; } else { # we want to be careful about what subroutines # can be called from outside. modify %reports # accordingly when a new report type is added if (! exists $reports{$::FORM{'output'}}) { $::FORM{'output'} = "most_doomed"; # a reasonable default } my $f = $reports{$::FORM{'output'}}; if (! defined $f) { print "start over, your form data was all messed up.

\n"; foreach (keys %::FORM) { print "$_ : " . ($::FORM{$_} ? $::FORM{$_} : "undef") . "
\n"; } exit; } &{$f}; } print < FIN ################################## # user came in with no form data # ################################## sub choose_product { my $product_popup = make_options (\@::legal_product, $::legal_product[0]); my $charts = (-d $dir) ? "

Welcome to the Bugzilla Query Kitchen

Product:
Output:
Switches:  Links to Bugs
 No Banner
 Include Quip

FIN } sub most_doomed { my $when = localtime (time); my $product = url_decode($::FORM{'product'}); print <

Bug Report for $product

$when

FIN my $query = <$query

\n" unless (! exists $::FORM{'showsql'}); SendSQL ($query); my $c = 0; my $quip = "Summary"; my $bugs_count = 0; my $bugs_new_this_week = 0; my $bugs_reopened = 0; my %bugs_owners; my %bugs_summary; my %bugs_status; my %bugs_totals; my %bugs_lookup; ############################# # suck contents of database # ############################# while (my ($bid, $a, $sev, $st, $prod, $who, $rep, $ts) = FetchSQLData()) { next if (exists $bugs_lookup{$bid}); $bugs_lookup{$bid} ++; $bugs_owners{$who} ++; $bugs_new_this_week ++ if (time - $ts <= $week); $bugs_status{$st} ++; $bugs_count ++; push @{$bugs_summary{$who}{$st}}, $bid; $bugs_totals{$who}{$st} ++; } if ($::FORM{'quip'}) { if (open (COMMENTS, ") { push @cdata, $_; } close COMMENTS; $quip = "" . $cdata[int(rand($#cdata + 1))] . ""; } } ######################### # start painting report # ######################### print <$quip
New Bugs This Week $bugs_new_this_week
Bugs Marked New $bugs_status{'NEW'}
Bugs Marked Assigned $bugs_status{'ASSIGNED'}
Bugs Marked Reopened $bugs_status{'REOPENED'}
Total Bugs $bugs_count

FIN if ($bugs_count == 0) { print "No bugs found!\n"; exit; } print <Bug Count by Engineer FIN foreach my $who (sort keys %bugs_summary) { my $bugz = 0; print < FIN foreach my $st (@status) { $bugs_totals{$who}{$st} += 0; print <$bugs_totals{$who}{$st} FIN $bugz += $#{$bugs_summary{$who}{$st}} + 1; } print <$bugz FIN } print <

FIN ############################### # individual bugs by engineer # ############################### print <Individual Bugs by Engineer

Owner New Assigned Reopened Total
$who
FIN foreach my $who (sort keys %bugs_summary) { print < FIN foreach my $st (@status) { my @l; foreach (sort { $a <=> $b } @{$bugs_summary{$who}{$st}}) { if ($::FORM{'links'}) { push @l, "$_\n"; } else { push @l, $_; } } my $bugz = join ' ', @l; $bugz = " " unless ($bugz); print <$bugz FIN } print < FIN } print <

FIN } sub is_legal_product { my $product = shift; return grep { $_ eq $product} @::legal_product; } sub header { print <

Owner New Assigned Reopened
$who
FIN } sub show_chart { my $when = localtime (time); my $product = url_decode($::FORM{'product'}); if (! is_legal_product($product)) { &die_politely ("Unknown product: $product"); } print < FIN my @dates; my @open; my @assigned; my @reopened; my $prodname = $::FORM{'product'}; $prodname =~ s/\//-/gs; my $file = join '/', $dir, $prodname; my $image = "$file.gif"; if (! open FILE, $file) { &die_politely ("The tool which gathers bug counts has not been run yet."); } while () { chomp; next if ($_ =~ /^#/ or ! $_); my ($date, $open, $assigned, $reopened) = split /\|/, $_; my ($yy, $mm, $dd) = $date =~ /^\d{2}(\d{2})(\d{2})(\d{2})$/; push @dates, "$mm/$dd/$yy"; push @open, $open; push @assigned, $assigned; push @reopened, $reopened; } close FILE; if ($#dates < 1) { &die_politely ("We don't have enough data points to make a graph (yet)"); } my $img = Chart::Lines->new (800, 600); my @labels = qw (New Assigned Reopened); my @when; my $i = 0; my @data; push @data, \@dates; push @data, \@open; push @data, \@assigned; push @data, \@reopened; my %settings = ( "title" => "Bug Charts for $product", "x_label" => "Dates", "y_label" => "Bug Count", "legend_labels" => \@labels, ); $img->set (%settings); open IMAGE, ">$image" or die "$image: $!"; $img->gif (*IMAGE, \@data); close IMAGE; print <

FIN } sub die_politely { my $msg = shift; my $product = url_decode($::FORM{'product'}); print <
Sorry, but ...

There is no graph available for $product

$msg

FIN exit; }