duplicates.cgi 4.27 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/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.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.
#
# 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): Gervase Markham <gerv@gerv.net>
#
# Generates mostfreq list from data collected by collectstats.pl.

use diagnostics;
use strict;
use CGI "param";
use DB_File;
require "globals.pl";
require "CGI.pl";

ConnectToDatabase();
GetVersionTable();

my %count;
my $dobefore = 0;
my $before = "";
my %before;

my $changedsince;
my $maxrows = 500;       # arbitrary limit on max number of rows

my $today = &days_ago(0);

# Open today's record of dupes
if (-e "data/mining/dupes$today.db")
{
	dbmopen(%count, "data/mining/dupes${today}.db", 0644) || die "Can't open today's dupes file: $!";
}
else
{
	# Try yesterday's, then (in case today's hasn't been created yet) :-)
	$today = &days_ago(1);
	if (-e "data/mining/dupes$today.db")
	{
		dbmopen(%count, "data/mining/dupes${today}.db", 0644) || die "Can't open yesterday's dupes file: $!";
	}
	else
	{
		die "There are no duplicate statistics for today or yesterday.";
	}
}

# Check for changedsince param, and see if it's a positive integer
65
if (defined(param("changedsince")) && param("changedsince") =~ /^\d{1-4}$/) 
66 67 68 69 70 71 72 73 74 75 76 77
{
	$changedsince = param("changedsince");
}
else
{
	# Otherwise, default to one week
	$changedsince = "7";
}

$before = &days_ago($changedsince);		

# check for max rows parameter
78
if (defined(param("maxrows")) && param("maxrows") =~ /^\d{1-4}$/)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
{
	$maxrows = param("maxrows");
}

if (-e "data/mining/dupes${before}.db") 
{
	dbmopen(%before, "data/mining/dupes${before}.db", 0644) && ($dobefore = 1);
}

print "Content-type: text/html\n";
print "\n";
PutHeader("Most Frequently Reported Bugs");

print Param("mostfreqhtml");

print "
<table BORDER>

<tr BGCOLOR=\"#CCCCCC\">
<td><center><b>Bug #</b></center></td>
<td><center><b>Dupe<br>Count</b></center></td>\n";

if ($dobefore) 
{
	print "<td><center><b>Change in last<br>$changedsince day(s)</b></center></td> ";
}

print "
<td><center><b>Component</b></center></td>
<td><center><b>Severity</b></center></td>
<td><center><b>Op Sys</b></center></td>
<td><center><b>Target<br>Milestone</b></center></td>
<td><center><b>Summary</b></center></td>
</tr>\n\n";

my %delta;

# Calculate the deltas if we are doing a "before"
if ($dobefore)
{
	foreach (keys(%count))
	{
		$delta{$_} = $count{$_} - $before{$_};
	}
}

# Offer the option of sorting on total count, or on the delta
my @sortedcount;

if (defined(param("sortby")) && param("sortby") == "delta")
{
	@sortedcount = sort by_delta keys(%count);
}
else
{
	@sortedcount = sort by_dup_count keys(%count);
}

my $i = 0;

foreach (@sortedcount)
{
	my $id = $_;
	SendSQL("SELECT component, bug_severity, op_sys, target_milestone, short_desc FROM " . 
												   "bugs WHERE bug_id = $id");
	my ($component, $severity, $op_sys, $milestone, $summary) = FetchSQLData();
	print "<tr>";
	print '<td><center><A HREF="show_bug.cgi?id=' . $id . '">';
	print $id . "</A></center></td>";
	print "<td><center>$count{$id}</center></td>";
	if ($dobefore) 
	{
		print "<td><center>$delta{$id}</center></td>";
	}
	print "<td>$component</td>\n    ";
	print "<td><center>$severity</center></td>";
	print "<td><center>$op_sys</center></td>";
	print "<td><center>$milestone</center></td>";
	print "<td>$summary</td>";
	print "</tr>\n";
	
	$i++;
	if ($i == $maxrows)
	{
		last;
	}
}

print "</table><br><br>";
PutFooter();


sub by_dup_count 
{
	return -($count{$a} <=> $count{$b});
}

sub by_delta 
{
	return -($delta{$a} <=> $delta{$b});
}

sub days_ago 
{
    my ($dom, $mon, $year) = (localtime(time - ($_[0]*24*60*60)))[3, 4, 5];
    return sprintf "%04d%02d%02d", 1900 + $year, ++$mon, $dom;
}