Cleaned up code, sorted by pctg

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2120 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2003-07-30 13:46:48 +00:00
parent 58e0b2df9c
commit 87c36672ce
2 changed files with 65 additions and 51 deletions

View File

@ -9,6 +9,7 @@ push @EXPORT, '&getUnixName';
push @EXPORT, '&getModuleDir';
push @EXPORT, '&getSrcDir';
push @EXPORT, '&getString';
push @EXPORT, '&getPctg';
push @EXPORT, '&getJobsFile';
push @EXPORT, '&getRptFile';
push @EXPORT, '&getRptURL';
@ -16,54 +17,71 @@ push @EXPORT, '&getLines';
push @EXPORT, '&getLocation';
sub new {
my $self = {};
bless($self);
if ((scalar(@_)-1) == 1) {
($self->{LOCATION},$self->{TITLE},$self->{UNIXNAME}, $self->{MODULEDIR}, $self->{SRCDIR}) = split(":", @_[1]);
} else {
$self->{LOCATION} = @_[1];
$self->{TITLE} = @_[2];
$self->{UNIXNAME} = @_[3];
$self->{MODULEDIR} = @_[4];
$self->{SRCDIR} = @_[5];
}
return $self;
my $self = {};
bless($self);
if ((scalar(@_)-1) == 1) {
($self->{LOCATION},$self->{TITLE},$self->{UNIXNAME}, $self->{MODULEDIR}, $self->{SRCDIR}) = split(":", @_[1]);
} else {
$self->{LOCATION} = @_[1];
$self->{TITLE} = @_[2];
$self->{UNIXNAME} = @_[3];
$self->{MODULEDIR} = @_[4];
$self->{SRCDIR} = @_[5];
}
# count lines in the report
open(FILE,getRptFile($self));
my @x = <FILE>;
close(FILE);
my $lines;
foreach (@x) {
$lines = $lines + 1 if $_ =~ "<td ";
}
$self->{LINES} = sprintf("%0.f", $lines/4);
# get NCSS lines
if (! -e getNCSSFile($self)) {
$self->{NCSS} = "TBD";
} else {
open(FILE,getNCSSFile($self));
my @x = <FILE>;
close(FILE);
@splits = split(/:/,$x[0]);
$self->{NCSS} = $splits[1];
}
return $self;
}
sub getLines() {
my $self = shift;
open(FILE,getRptFile($self));
my @x = <FILE>;
close(FILE);
my $lines;
foreach (@x) {
$lines = $lines + 1 if $_ =~ "<td ";
}
return sprintf("%0.f", $lines/4);
my $self = shift;
return $self->{LINES}
}
sub getPctg() {
my $self = shift;
my $mungencss = $self->{NCSS};
if ($mungencss == 0) {
$mungencss = 1;
}
return (int(($self->{LINES}/$mungencss)*10000))/100;
}
sub getCPDLines() {
my $self = shift;
open(FILE,getCPDRptFile($self));
my @x = <FILE>;
close(FILE);
my $lines;
foreach (@x) {
$lines = $lines + 1 if $_ =~ "=================================";
}
return sprintf("%0.f", $lines);
my $self = shift;
open(FILE,getCPDRptFile($self));
my @x = <FILE>;
close(FILE);
my $lines;
foreach (@x) {
$lines = $lines + 1 if $_ =~ "=================================";
}
return sprintf("%0.f", $lines);
}
sub getNCSS() {
my $self=shift;
if (! -e getNCSSFile($self)) {
return "TBD";
}
open(FILE,getNCSSFile($self));
my @x = <FILE>;
close(FILE);
@splits = split(/:/,$x[0]);
return $splits[1];
my $self = shift;
return $self->{NCSS};
}
sub getLocation() {
@ -115,7 +133,7 @@ sub getCPDRptURL() {
sub getRptFile() {
my $self = shift;
my $name = $self->getReportName();
my $name = getReportName($self);
return "../htdocs/reports/${name}";
}

View File

@ -66,7 +66,7 @@ sub loadProjectList() {
}
}
@newprojects = sort { $b->getLocation() cmp $a->getLocation() || $a->getTitle() cmp $b->getTitle() } @projects;
@newprojects = sort { $a->getPctg() cmp $b->getPctg() } @projects;
my $result="<table align=center><tr><th>Project</th><th></th><th>Home page</th><th>NCSS</th><th>Problems</th><th>Percentage<br>Unused Code</th><th>Duplicate<br>Code</th></tr>";
foreach $project (@newprojects) {
@ -76,23 +76,19 @@ sub loadProjectList() {
}
$result="${result}<tr><td>${jobLink}</td><td></td><td>@{[$project->getHomePage()]}</td>";
$result="${result}<td>@{[$project->getNCSS()]}</td>";
my $ncss = $project->getNCSS();
if ($ncss == 0) {
$ncss = 1;
}
my $rounded = (int(($project->getLines()/$ncss)*10000))/100;
my $pctg = $project->getPctg();
my $color="red";
if ($rounded < .2) {
if ($pctg < .2) {
$color="#00ff00";
} elsif ($rounded < .8 ) {
} elsif ($pctg < .8 ) {
$color="yellow";
}
$rounded = sprintf("%0.2f", $rounded);
$pctg = sprintf("%0.2f", $pctg);
if ($project->getNCSS() == "TBD") {
$rounded = "N/A";
$pctg = "N/A";
$color = "white";
}
$result="${result}<td align=center>@{[$project->getLines()]}</td><td bgcolor=$color align=center>$rounded</td>";
$result="${result}<td align=center>@{[$project->getLines()]}</td><td bgcolor=$color align=center>$pctg</td>";
my $cpdLink="0";
if (-e $project->getCPDRptFile() && $project->getCPDLines() > 0) {
$cpdLink="<a href=\"@{[$project->getCPDRptURL]}\">@{[$project->getCPDLines()]}</a>";