duplicates.cgi 6.77 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
#!/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.

25

26 27 28
use diagnostics;
use strict;
use CGI "param";
29
use AnyDBM_File;
30 31 32
require "globals.pl";
require "CGI.pl";

33
ConnectToDatabase(1);
34 35
GetVersionTable();

36
my %dbmcount;
37 38 39 40 41
my %count;
my $dobefore = 0;
my $before = "";
my %before;

42
# Get params from URL
43

44 45 46
my $changedsince = 7;     # default one week
my $maxrows = 100;        # arbitrary limit on max number of rows
my $sortby = "dup_count"; # default to sorting by dup count
47

48
if (defined(param("sortby")))
49
{
50
  $sortby = param("sortby");
51 52 53
}

# Check for changedsince param, and see if it's a positive integer
54
if (defined(param("changedsince")) && param("changedsince") =~ /^\d{1,4}$/) 
55
{
56
  $changedsince = param("changedsince");
57
}
58 59 60

# check for max rows param, and see if it's a positive integer
if (defined(param("maxrows")) && param("maxrows") =~ /^\d{1,4}$/)
61
{
62
  $maxrows = param("maxrows");
63 64
}

65 66 67 68
# Start the page
print "Content-type: text/html\n";
print "\n";
PutHeader("Most Frequently Reported Bugs");
69

70 71 72
# Open today's record of dupes
my $today = &days_ago(0);

73
if (<data/duplicates/dupes$today*>)
74
{
75
  dbmopen(%dbmcount, "data/duplicates/dupes$today", 0644) || 
76
                            &die_politely("Can't open today's dupes file: $!");
77
}
78 79 80 81
else
{
  # Try yesterday's, then (in case today's hasn't been created yet)
  $today = &days_ago(1);
82
  if (<data/duplicates/dupes$today*>)
83
  {
84
    dbmopen(%dbmcount, "data/duplicates/dupes$today", 0644) || 
85 86 87 88
                        &die_politely("Can't open yesterday's dupes file: $!");
  }
  else
  {
89
    &die_politely("There are no duplicate statistics for today ($today) or yesterday.");
90 91 92 93 94 95 96 97
  }
}

# Copy hash (so we don't mess up the on-disk file when we remove entries)
%count = %dbmcount;
my $key;
my $value;
my $threshold = Param("mostfreqthreshold");
98

99 100
# Remove all those dupes under the threshold (for performance reasons)
while (($key, $value) = each %count)
101
{
102 103 104 105
  if ($value < $threshold)
  {
    delete $count{$key};
  } 
106 107
}

108 109 110
# Try and open the database from "changedsince" days ago
$before = &days_ago($changedsince);    

111
if (<data/duplicates/dupes$before*>) 
112
{
113
  dbmopen(%before, "data/duplicates/dupes$before", 0644) && ($dobefore = 1);
114
}
115 116 117

print Param("mostfreqhtml");

118
my %delta;
119 120 121

if ($dobefore) 
{
122 123 124 125 126
  # Calculate the deltas if we are doing a "before"
  foreach (keys(%count))
  {
    $delta{$_} = $count{$_} - $before{$_};
  }
127 128
}

129 130
# Sort, if required
my @sortedcount;
131

132
if    ($sortby eq "delta")
133
{
134
  @sortedcount = sort by_delta keys(%count);
135
}
136
elsif ($sortby eq "bug_no")
137
{
138
  @sortedcount = reverse sort by_bug_no keys(%count);
139
}
140
elsif ($sortby eq "dup_count")
141
{
142
  @sortedcount = sort by_dup_count keys(%count);
143 144 145 146
}

my $i = 0;

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 187 188 189 190 191 192 193 194
# Produce a string of bug numbers for a Bugzilla buglist.
my $commabugs = "";
foreach (@sortedcount) 
{
  last if ($i == $maxrows);

  $commabugs .= ($_ . ",");
  $i++;  
}

# Avoid having a comma at the end - Bad Things happen.
chop $commabugs; 

print qq|

<form method="POST" action="buglist.cgi">
<input type="hidden" name="bug_id" value="$commabugs">
<input type="hidden" name="order" value="Reuse same sort as last time">
Give this to me as a <input type="submit" value="Bug List">. (Note: the order may not be the same.)
</form>

<table BORDER>
<tr BGCOLOR="#CCCCCC">

<td><center><b>
<a href="duplicates.cgi?sortby=bug_no&maxrows=$maxrows&changedsince=$changedsince">Bug #</a>
</b></center></td>
<td><center><b>
<a href="duplicates.cgi?sortby=dup_count&maxrows=$maxrows&changedsince=$changedsince">Dupe<br>Count</a>
</b></center></td>\n|;

if ($dobefore) 
{
  print "<td><center><b>
  <a href=\"duplicates.cgi?sortby=delta&maxrows=$maxrows&changedsince=$changedsince\">Change in
  last<br>$changedsince day(s)</a></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";

$i = 0;

195 196
foreach (@sortedcount)
{
197
  my $id = $_;
198
  SendSQL("SELECT component, bug_severity, op_sys, target_milestone, short_desc, groupset, bug_status, resolution" .
199
                 " FROM bugs WHERE bug_id = $id");
200 201 202
  my ($component, $severity, $op_sys, $milestone, $summary, $groupset, $bug_status, $resolution) = FetchSQLData();
  next unless $groupset == 0;
  $summary = html_quote($summary);
203

204 205 206 207 208
  # Show all bugs except those CLOSED _OR_ VERIFIED but not INVALID or WONTFIX.
  # We want to see VERIFIED INVALID and WONTFIX because common "bugs" which aren't
  # bugs end up in this state.
  unless ( ($bug_status eq "CLOSED") || ( ($bug_status eq "VERIFIED") &&
          ! ( ($resolution eq "INVALID") || ($resolution eq "WONTFIX") ) ) ) {
209 210
    print "<tr>";
    print '<td><center>';
211
    if  ( ($bug_status eq "RESOLVED") || ($bug_status eq "VERIFIED") ) {
212 213 214 215
      print "<strike>";
    }
    print "<A HREF=\"show_bug.cgi?id=" . $id . "\">";
    print $id . "</A>";
216
    if  ( ($bug_status eq "RESOLVED") || ($bug_status eq "VERIFIED") ) {
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
      print "</strike>";
    }
    print "</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++;
233
  }
234

235 236 237 238
  if ($i == $maxrows)
  {
    last;
  }
239 240 241 242 243 244
}

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


245 246 247 248 249
sub by_bug_no 
{
  return ($a <=> $b);
}

250 251
sub by_dup_count 
{
252
  return -($count{$a} <=> $count{$b});
253 254 255 256
}

sub by_delta 
{
257
  return -($delta{$a} <=> $delta{$b});
258 259 260 261
}

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

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
sub die_politely {
  my $msg = shift;

  print <<FIN;
<p>
<table border=1 cellpadding=10>
<tr>
<td align=center>
<font color=blue>$msg</font>
</td>
</tr>
</table>
<p>
FIN
    
  PutFooter();
  exit;
}