1998-10-26 23:15:38 +03:00
|
|
|
#!/usr/bonsaitools/bin/perl -w
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-02 02:33:56 +03:00
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (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.
|
|
|
|
#
|
1998-10-26 23:15:38 +03:00
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
1999-11-02 02:33:56 +03:00
|
|
|
#
|
1998-10-26 23:15:38 +03:00
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-02 02:33:56 +03:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
1998-10-26 23:15:38 +03:00
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>,
|
|
|
|
# Harrison Page <harrison@netscape.com>
|
2001-03-10 04:47:30 +03:00
|
|
|
# Gervase Markham <gerv@gerv.net>
|
1998-10-26 23:15:38 +03:00
|
|
|
|
|
|
|
# Run me out of cron at midnight to collect Bugzilla statistics.
|
|
|
|
|
2001-04-19 21:35:23 +04:00
|
|
|
|
2001-04-06 22:19:47 +04:00
|
|
|
use AnyDBM_File;
|
1998-10-26 23:15:38 +03:00
|
|
|
use strict;
|
2000-10-31 02:02:41 +03:00
|
|
|
use vars @::legal_product;
|
1998-10-26 23:15:38 +03:00
|
|
|
|
|
|
|
require "globals.pl";
|
|
|
|
|
2000-10-31 02:02:41 +03:00
|
|
|
# tidy up after graphing module
|
2000-12-14 20:52:18 +03:00
|
|
|
if (chdir("graphs")) {
|
2001-03-10 04:47:30 +03:00
|
|
|
unlink <./*.gif>;
|
2000-12-14 20:52:18 +03:00
|
|
|
unlink <./*.png>;
|
|
|
|
chdir("..");
|
|
|
|
}
|
2001-03-10 04:47:30 +03:00
|
|
|
|
2000-10-31 02:23:42 +03:00
|
|
|
ConnectToDatabase(1);
|
1998-10-27 13:43:24 +03:00
|
|
|
GetVersionTable();
|
1998-10-26 23:15:38 +03:00
|
|
|
|
1999-05-04 04:01:57 +04:00
|
|
|
my @myproducts;
|
|
|
|
push( @myproducts, "-All-", @::legal_product );
|
|
|
|
|
|
|
|
foreach (@myproducts) {
|
1999-03-05 22:48:26 +03:00
|
|
|
my $dir = "data/mining";
|
1998-11-10 02:19:37 +03:00
|
|
|
|
1999-03-05 22:48:26 +03:00
|
|
|
&check_data_dir ($dir);
|
|
|
|
&collect_stats ($dir, $_);
|
|
|
|
}
|
1998-10-26 23:15:38 +03:00
|
|
|
|
2000-10-24 02:01:31 +04:00
|
|
|
&calculate_dupes();
|
|
|
|
|
1999-03-05 22:48:26 +03:00
|
|
|
sub check_data_dir {
|
|
|
|
my $dir = shift;
|
1998-10-26 23:15:38 +03:00
|
|
|
|
1999-03-05 22:48:26 +03:00
|
|
|
if (! -d) {
|
|
|
|
mkdir $dir, 0777;
|
|
|
|
chmod 0777, $dir;
|
|
|
|
}
|
|
|
|
}
|
1998-10-26 23:15:38 +03:00
|
|
|
|
1999-03-05 22:48:26 +03:00
|
|
|
sub collect_stats {
|
|
|
|
my $dir = shift;
|
|
|
|
my $product = shift;
|
|
|
|
my $when = localtime (time);
|
2002-08-12 09:43:05 +04:00
|
|
|
my $product_id = get_product_id($product) unless $product eq '-All-';
|
|
|
|
|
|
|
|
die "Unknown product $product" unless ($product_id or $product eq '-All-');
|
1998-10-26 23:15:38 +03:00
|
|
|
|
2000-09-13 01:35:46 +04:00
|
|
|
# NB: Need to mangle the product for the filename, but use the real
|
|
|
|
# product name in the query
|
|
|
|
my $file_product = $product;
|
|
|
|
$file_product =~ s/\//-/gs;
|
|
|
|
my $file = join '/', $dir, $file_product;
|
1999-03-05 22:48:26 +03:00
|
|
|
my $exists = -f $file;
|
|
|
|
|
|
|
|
if (open DATA, ">>$file") {
|
|
|
|
push my @row, &today;
|
|
|
|
|
2001-03-10 04:47:30 +03:00
|
|
|
foreach my $status ('NEW', 'ASSIGNED', 'REOPENED', 'UNCONFIRMED', 'RESOLVED', 'VERIFIED', 'CLOSED') {
|
|
|
|
if( $product eq "-All-" ) {
|
|
|
|
SendSQL("select count(bug_status) from bugs where bug_status='$status'");
|
|
|
|
} else {
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("select count(bug_status) from bugs where bug_status='$status' and product_id=$product_id");
|
2001-03-10 04:47:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
push @row, FetchOneColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $resolution ('FIXED', 'INVALID', 'WONTFIX', 'LATER', 'REMIND', 'DUPLICATE', 'WORKSFORME', 'MOVED') {
|
|
|
|
if( $product eq "-All-" ) {
|
|
|
|
SendSQL("select count(resolution) from bugs where resolution='$resolution'");
|
|
|
|
} else {
|
2002-08-12 09:43:05 +04:00
|
|
|
SendSQL("select count(resolution) from bugs where resolution='$resolution' and product_id=$product_id");
|
2001-03-10 04:47:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
push @row, FetchOneColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $exists) {
|
|
|
|
print DATA <<FIN;
|
2000-10-31 02:02:41 +03:00
|
|
|
# Bugzilla Daily Bug Stats
|
1998-10-26 23:15:38 +03:00
|
|
|
#
|
2000-10-31 02:02:41 +03:00
|
|
|
# Do not edit me! This file is generated.
|
2001-03-10 04:47:30 +03:00
|
|
|
#
|
2001-01-19 02:08:22 +03:00
|
|
|
# fields: DATE|NEW|ASSIGNED|REOPENED|UNCONFIRMED|RESOLVED|VERIFIED|CLOSED|FIXED|INVALID|WONTFIX|LATER|REMIND|DUPLICATE|WORKSFORME|MOVED
|
2000-10-31 02:02:41 +03:00
|
|
|
# Product: $product
|
|
|
|
# Created: $when
|
1998-10-26 23:15:38 +03:00
|
|
|
FIN
|
2001-03-10 04:47:30 +03:00
|
|
|
}
|
|
|
|
|
1999-03-05 22:48:26 +03:00
|
|
|
print DATA (join '|', @row) . "\n";
|
|
|
|
close DATA;
|
|
|
|
} else {
|
|
|
|
print "$0: $file, $!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-24 02:01:31 +04:00
|
|
|
sub calculate_dupes {
|
|
|
|
SendSQL("SELECT * FROM duplicates");
|
|
|
|
|
|
|
|
my %dupes;
|
|
|
|
my %count;
|
|
|
|
my @row;
|
|
|
|
my $key;
|
|
|
|
my $changed = 1;
|
|
|
|
|
2001-04-06 22:19:47 +04:00
|
|
|
my $today = &today_dash;
|
2000-10-24 02:01:31 +04:00
|
|
|
|
|
|
|
# Save % count here in a date-named file
|
|
|
|
# so we can read it back in to do changed counters
|
|
|
|
# First, delete it if it exists, so we don't add to the contents of an old file
|
2001-06-07 01:17:42 +04:00
|
|
|
if (my @files = <data/duplicates/dupes$today*>) {
|
|
|
|
unlink @files;
|
2000-10-24 02:01:31 +04:00
|
|
|
}
|
|
|
|
|
2001-04-19 21:19:07 +04:00
|
|
|
dbmopen(%count, "data/duplicates/dupes$today", 0644) || die "Can't open DBM dupes file: $!";
|
2000-10-24 02:01:31 +04:00
|
|
|
|
|
|
|
# Create a hash with key "a bug number", value "bug which that bug is a
|
|
|
|
# direct dupe of" - straight from the duplicates table.
|
2001-03-10 04:47:30 +03:00
|
|
|
while (@row = FetchSQLData()) {
|
|
|
|
my $dupe_of = shift @row;
|
|
|
|
my $dupe = shift @row;
|
|
|
|
$dupes{$dupe} = $dupe_of;
|
2000-10-24 02:01:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Total up the number of bugs which are dupes of a given bug
|
|
|
|
# count will then have key = "bug number",
|
|
|
|
# value = "number of immediate dupes of that bug".
|
|
|
|
foreach $key (keys(%dupes))
|
|
|
|
{
|
2001-03-10 04:47:30 +03:00
|
|
|
my $dupe_of = $dupes{$key};
|
2000-10-24 02:01:31 +04:00
|
|
|
|
2001-03-10 04:47:30 +03:00
|
|
|
if (!defined($count{$dupe_of})) {
|
|
|
|
$count{$dupe_of} = 0;
|
|
|
|
}
|
2000-10-24 02:01:31 +04:00
|
|
|
|
2001-03-10 04:47:30 +03:00
|
|
|
$count{$dupe_of}++;
|
2000-10-24 02:01:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Now we collapse the dupe tree by iterating over %count until
|
|
|
|
# there is no further change.
|
|
|
|
while ($changed == 1)
|
|
|
|
{
|
2001-03-10 04:47:30 +03:00
|
|
|
$changed = 0;
|
|
|
|
foreach $key (keys(%count)) {
|
|
|
|
# if this bug is actually itself a dupe, and has a count...
|
|
|
|
if (defined($dupes{$key}) && $count{$key} > 0) {
|
|
|
|
# add that count onto the bug it is a dupe of,
|
|
|
|
# and zero the count; the check is to avoid
|
|
|
|
# loops
|
|
|
|
if ($count{$dupes{$key}} != 0) {
|
|
|
|
$count{$dupes{$key}} += $count{$key};
|
|
|
|
$count{$key} = 0;
|
|
|
|
$changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-10-24 02:01:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Remove the values for which the count is zero
|
|
|
|
foreach $key (keys(%count))
|
|
|
|
{
|
2001-03-10 04:47:30 +03:00
|
|
|
if ($count{$key} == 0) {
|
|
|
|
delete $count{$key};
|
|
|
|
}
|
2000-10-24 02:01:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dbmclose(%count);
|
|
|
|
}
|
|
|
|
|
1999-03-05 22:48:26 +03:00
|
|
|
sub today {
|
|
|
|
my ($dom, $mon, $year) = (localtime(time))[3, 4, 5];
|
|
|
|
return sprintf "%04d%02d%02d", 1900 + $year, ++$mon, $dom;
|
|
|
|
}
|
1998-10-26 23:15:38 +03:00
|
|
|
|
2001-04-06 22:19:47 +04:00
|
|
|
sub today_dash {
|
|
|
|
my ($dom, $mon, $year) = (localtime(time))[3, 4, 5];
|
|
|
|
return sprintf "%04d-%02d-%02d", 1900 + $year, ++$mon, $dom;
|
|
|
|
}
|
|
|
|
|