[Debtags-commits] [svn] r1450 -
central-database/branches/alioth/webfrontend
Enrico Zini
enrico at costa.debian.org
Mon Oct 31 09:44:48 UTC 2005
Author: enrico
Date: Mon Oct 31 09:44:46 2005
New Revision: 1450
Modified:
central-database/branches/alioth/webfrontend/Engine.pm
central-database/branches/alioth/webfrontend/index.cgi
Log:
Some cleanup
Modified: central-database/branches/alioth/webfrontend/Engine.pm
==============================================================================
--- central-database/branches/alioth/webfrontend/Engine.pm (original)
+++ central-database/branches/alioth/webfrontend/Engine.pm Mon Oct 31 09:44:46 2005
@@ -41,7 +41,7 @@
{
my ($class, $pkg) = @_;
return $cache{$pkg} if exists $cache{$pkg};
- return bless {
+ return $cache{$pkg} = bless {
name => $pkg
}, $class;
}
@@ -83,6 +83,28 @@
return map { Engine::Tag->new($_->{name}) } @{$db->{pkgs}{$_[0]->name}{tags}};
}
+sub hasTag ($@)
+{
+ my $self = shift;
+ my %tags = map { $_ => 1 } @{$db->{pkgs}{$self->name}{tags}};
+ for my $t (@_)
+ {
+ return undef if not exists $tags{$t->name()};
+ }
+ return 1;
+}
+
+sub hasSomeTag ($@)
+{
+ my $self = shift;
+ my %tags = map { $_ => 1 } @{$db->{pkgs}{$self->name}{tags}};
+ for my $t (@_)
+ {
+ return 1 if exists $tags{$t->name()};
+ }
+ return undef;
+}
+
package Engine::Facet;
use strict;
@@ -94,7 +116,7 @@
{
my ($class, $facet) = @_;
return $cache{$facet} if exists $cache{$facet};
- return bless {
+ return $cache{$facet} = bless {
name => $facet
}, $class;
}
@@ -153,7 +175,7 @@
{
my ($class, $tag) = @_;
return $cache{$tag} if exists $cache{$tag};
- return bless {
+ return $cache{$tag} = bless {
name => $tag
}, $class;
}
@@ -256,6 +278,16 @@
%p = %packages;
%f = %facets;
%t = %tags;
+
+ # Sort the arrays in db
+ for my $p (values %{$db->{pkgs}})
+ {
+ $p->{tags} = [ sort { $a->{name} cmp $b->{name} } @{$p->{tags}} ];
+ }
+ for my $t (values %{$db->{tags}})
+ {
+ $t->{pkgs} = [ sort { $a->{name} cmp $b->{name} } @{$t->{pkgs}} ];
+ }
store $db, 'debtags.store';
}
@@ -305,11 +337,7 @@
if (@{$parms->{tags}})
{
- my %tags = map { $_->name() => 1 } $p->tags();
- for my $i (@{$parms->{tags}})
- {
- return undef if not exists $tags{$i->name()};
- }
+ return undef if not $p->hasTag(@{$parms->{tags}});
}
for my $w (@{$parms->{words}})
{
Modified: central-database/branches/alioth/webfrontend/index.cgi
==============================================================================
--- central-database/branches/alioth/webfrontend/index.cgi (original)
+++ central-database/branches/alioth/webfrontend/index.cgi Mon Oct 31 09:44:46 2005
@@ -42,30 +42,6 @@
# Returns the facet name for a tag
sub facet ($) { return (split('::', $_[0]))[0] or 'legacy'; }
-# Returns true if the has contains all the values in the vector
-sub contains ($\@)
-{
- my ($pkg, $vec) = @_;
- my %hash = map { $_ => 1 } @{$pkg->{tags}};
- for my $i (@$vec)
- {
- return undef if not exists $hash{$i};
- }
- return 1;
-}
-
-# Returns true if the has contains at least one of the values in the vector
-sub intersects ($\@)
-{
- my ($p, $vec) = @_;
- my %hash = map { $_ => 1 } $p->tags();
- for my $i (@$vec)
- {
- return 1 if exists $hash{$i};
- }
- return undef;
-}
-
#sub array_index ($$);
#sub array_index($$) { my($haystack,$needle) = @_;
# for (my $i=0; $i <= $#$haystack; $i++) {
@@ -189,27 +165,35 @@
@subpkgs = Engine::package(keys %sub);
} else {
- @subpkgs = grep { $_->tags() } Engine::packages();
+ @subpkgs = grep { scalar($_->tags()) } Engine::packages();
}
##
## Building statistics for packages in subgroups
##
+msg "SP %d\n", scalar(@subpkgs);
+
# Compute tag statistics
my %tag_counts;
for my $p (@subpkgs)
{
- foreach my $t ($p->tags())
+ foreach my $t (map { $_->name() } $p->tags())
{
- $tag_counts{$t->name()} += 1;
+ $tag_counts{$t} += 1;
}
}
+msg "KTC %d\n", scalar(keys %tag_counts);
+
# Select the child tags
my %seen = map { $_->name => 1 } @sel_tags;
-my @tag_newtags = Engine::tag(grep { !$seen{$_} } keys %tag_counts);
+msg "SEEN %d\n", scalar(keys %seen);
+
+my @tag_newtags = Engine::tag(grep { not exists $seen{$_} } keys %tag_counts);
+
+msg "TNT %d\n", scalar(@tag_newtags);
##
## Output results
@@ -259,7 +243,7 @@
};
$cur_fac = $f->name();
}
- next if $seen{$t->name()};
+ next if $seen{$t};
$ht_newfacets[$#ht_newfacets]{COUNT} += $tag_counts{$t->name()};
push @{$ht_newfacets[$#ht_newfacets]{TAGS}}, {
TAG => $t->name(),
@@ -306,7 +290,7 @@
my $lastsection = '';
foreach my $pkg (sort bytagset @pkgs)
{
- my @tags = sort { $a->name() cmp $b->name() } grep { !$seen{$_->name} } $pkg->tags();
+ my @tags = sort { $a->name() cmp $b->name() } grep { !$seen{$_->name()} } $pkg->tags();
my $tags = join(',', @tags);
my %data;
More information about the Debtags-commits
mailing list