[vhffs-dev] svn diff for tags |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Hi,
Here's the proposal for stats about tags (includes function
most_popular_tags).
The files modified are :
../vhffs-panel/admin/stats.pl
../vhffs-panel/templates/admin/misc/stats.tmpl
../vhffs-api/src/Vhffs/Stats.pm
(./vhffs-api/src/Vhffs/Tag.pm is not modified as it's too much object
oriented and inefficient to provide count(groups) per tag).
There's also a diff -Naur available at
safran:/home/devz/baud/Developpement/diff_modifs_tags.diff
As I worked temporarily directly on the files after a make install,
there are some irrelevant
-#!%PERL% -w
+#!/usr/bin/perl -w
or
-use lib '%VHFFS_LIB_DIR%';
+use lib '/usr/share/vhffs/api';
(sorry /o\)
@++
Ben'. aka baud123
Index: vhffs-api/src/Vhffs/Stats.pm
===================================================================
--- vhffs-api/src/Vhffs/Stats.pm (revision 1211)
+++ vhffs-api/src/Vhffs/Stats.pm (working copy)
@@ -447,7 +447,75 @@
return $self->{groups}{total};
}
+sub get_tags_categories_total
+{
+ my $self = shift;
+ unless(defined $self->{tags_categories}{total}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_tag_category';
+ ($self->{tags_categories}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{tags_categories}{total};
+}
+sub get_tags_total
+{
+ my $self = shift;
+ unless(defined $self->{tags}{total}) {
+ my $sql = 'SELECT COUNT(*) FROM vhffs_tag';
+ ($self->{tags}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{tags}{total};
+}
+
+sub get_tags_used_total
+{
+ my $self = shift;
+ unless(defined $self->{tags_used}{total}) {
+ my $sql = 'SELECT COUNT(distinct tag_id) FROM vhffs_object_tag';
+ ($self->{tags_used}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{tags_used}{total};
+}
+
+sub get_tags_groups_total
+{
+ my $self = shift;
+ unless(defined $self->{tags_groups}{total}) {
+ my $sql = 'SELECT COUNT(distinct object_id) FROM vhffs_object_tag';
+ ($self->{tags_groups}{total}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{tags_groups}{total};
+}
+
+sub get_most_popular_tags
+{
+ my $self = shift;
+ # well, I did not succeed to use $self->{tags}{most_popular}
+ my $tags = [];
+ my $sql = 'SELECT vhffs_tag_category.label as category, vhffs_tag.label as tag_label, COUNT(object_id) as nb_groups
+ FROM vhffs_object_tag, vhffs_tag_category, vhffs_tag
+ WHERE vhffs_tag.category_id=vhffs_tag_category.tag_category_id
+ AND vhffs_object_tag.tag_id=vhffs_tag.tag_id
+ GROUP BY category,tag_label ORDER BY nb_groups DESC LIMIT 10';
+ my $sth = $self->{db}->prepare($sql);
+ $sth->execute() or return undef;
+ while( (my $t = $sth->fetchrow_hashref() ) ) {
+ push @$tags, $t;
+ }
+ return $tags;
+}
+
+sub get_tags_groups_max
+{
+ my $self = shift;
+
+ unless(defined $self->{tags_groups}{max}) {
+ my $sql = 'SELECT MAX(count_tag_id) FROM (select COUNT(tag_id) as count_tag_id, object_id FROM vhffs_object_tag GROUP BY object_id) AS count_tags_groups';
+ ($self->{tags_groups}{max}) = @{$self->{db}->selectrow_arrayref( $sql )};
+ }
+ return $self->{tags_groups}{max};
+}
+
1;
Index: vhffs-panel/admin/stats.pl
===================================================================
--- vhffs-panel/admin/stats.pl (revision 1211)
+++ vhffs-panel/admin/stats.pl (working copy)
@@ -1,4 +1,4 @@
-#!%PERL% -w
+#!/usr/bin/perl -w
# Copyright (c) vhffs project and its contributors
# All rights reserved.
#
@@ -40,7 +40,7 @@
use strict;
-use lib '%VHFFS_LIB_DIR%';
+use lib '/usr/share/vhffs/api';
use Vhffs::User;
use Vhffs::Group;
use Vhffs::Main;
@@ -49,6 +49,7 @@
use Vhffs::Stats;
use Vhffs::Constants;
+
my $panel = new Vhffs::Panel::Main();
exit 0 unless $panel;
my $session = $panel->get_session;
@@ -170,6 +171,39 @@
$template->param( VALUE_TOTAL_LISTS_ACTIVATED => $stats->get_lists_activated );
$template->param( TEXT_TOTAL_SUBS => gettext("Total subscribtion for lists") );
$template->param( VALUE_TOTAL_SUBS => $stats->get_lists_totalsubs );
+
+ #tags part
+ $template->param( TEXT_TAGS => gettext("Tags stats") );
+ $template->param( TEXT_TOTAL_TAGS_CATEGORIES => gettext("Total categories") );
+ $template->param( VALUE_TOTAL_TAGS_CATEGORIES => $stats->get_tags_categories_total );
+ $template->param( TEXT_TOTAL_TAGS_USED_EXISTING => gettext("Total tags used") );
+ $template->param( VALUE_TOTAL_TAGS_USED => $stats->get_tags_used_total );
+ #$template->param( TEXT_TOTAL_TAGS_EXISTING => gettext("Total tags existing") );
+ $template->param( VALUE_TOTAL_TAGS_EXISTING => $stats->get_tags_total );
+ $template->param( TEXT_TOTAL_TAGS_GROUPS => gettext("Total tagged groups" ) );
+ $template->param( VALUE_TOTAL_TAGS_GROUPS => $stats->get_tags_groups_total );
+ $template->param( TEXT_MAX_TAGS_GROUPS => gettext("Max tags for a group" ) );
+ $template->param( VALUE_MAX_TAGS_GROUPS => $stats->get_tags_groups_max );
+ $template->param( TEXT_10MOST_USED_TAGS => gettext("Popular tags" ) );
+ #my $tags = Vhffs::Tag::get_10_tagsgroups($panel->{vhffs});
+ #my $sql = q{SELECT vhffs_tag_category.label as category, vhffs_tag.label as tag_label, COUNT(object_id) as nb_groups
+ #FROM vhffs_object_tag, vhffs_tag_category, vhffs_tag
+ #WHERE vhffs_tag.category_id=vhffs_tag_category.tag_category_id
+ #AND vhffs_object_tag.tag_id=vhffs_tag.tag_id
+ #GROUP BY category,tag_label ORDER BY nb_groups DESC LIMIT 10};
+
+ #my $tags = [];
+ #my $main = $panel->{vhffs};
+
+ #my $dbh = $main->get_db_object();
+ #my $sth = $dbh->prepare($sql);
+ #$sth->execute() or return undef;
+ #while( (my $t = $sth->fetchrow_hashref() ) ) {
+ #push @$tags, $t;
+ #}
+
+ $template->param( 'TAGS' => $stats->get_most_popular_tags );
+
}
$panel->build( $template );
Index: vhffs-panel/templates/admin/misc/stats.tmpl
===================================================================
--- vhffs-panel/templates/admin/misc/stats.tmpl (revision 1211)
+++ vhffs-panel/templates/admin/misc/stats.tmpl (working copy)
@@ -98,3 +98,15 @@
<li><TMPL_VAR ESCAPE=1 NAME="TEXT_TOTAL_SUBS">: <TMPL_VAR ESCAPE=1 NAME="VALUE_TOTAL_SUBS"></li>
</ul>
+<h2>
+ <TMPL_VAR ESCAPE=1 NAME="TEXT_TAGS">:
+</h2>
+<ul>
+ <li><TMPL_VAR ESCAPE=1 NAME="TEXT_TOTAL_TAGS_CATEGORIES">: <TMPL_VAR ESCAPE=1 NAME="VALUE_TOTAL_TAGS_CATEGORIES"></li>
+ <li><TMPL_VAR ESCAPE=1 NAME="TEXT_TOTAL_TAGS_USED_EXISTING">: <TMPL_VAR ESCAPE=1 NAME="VALUE_TOTAL_TAGS_USED"> / <TMPL_VAR ESCAPE=1 NAME="VALUE_TOTAL_TAGS_EXISTING"></li>
+ <li><TMPL_VAR ESCAPE=1 NAME="TEXT_TOTAL_TAGS_GROUPS">: <TMPL_VAR ESCAPE=1 NAME="VALUE_TOTAL_TAGS_GROUPS"> / <TMPL_VAR ESCAPE=1 NAME="VALUE_TOTAL_GROUPS_ACTIVATED"></li>
+ <li><TMPL_VAR ESCAPE=1 NAME="TEXT_MAX_TAGS_GROUPS">: <TMPL_VAR ESCAPE=1 NAME="VALUE_MAX_TAGS_GROUPS"> </li>
+ <TMPL_IF NAME="TAGS"><li><TMPL_VAR ESCAPE=1 NAME="TEXT_10MOST_USED_TAGS">: <TMPL_LOOP NAME="TAGS"><TMPL_VAR NAME="category">:<TMPL_VAR NAME="tag_label" ESCAPE="1"> (<TMPL_VAR NAME="nb_groups">) </TMPL_LOOP>
+ </li></TMPL_IF>
+</ul>
+