Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

[idea] Plugin or Mod: Reset_Hit_Count

Quote Reply
[idea] Plugin or Mod: Reset_Hit_Count
Not a Perl-ist, so don't feel confident about doing this myself, though it is probably very simple ... maybe somebody else could pick it up?

Background
The 'Cool' page is meaningless as a measure of link popularity, or user activity. In practice, it is a list of links that have been in the database a long time, or which begin with the first few letters of the alphabet. A meaningful Hit Count should be based on a sensible time scale set by admin, eg: daily, weekly, monthly.

Idea
1. Create a new column in the link table named OldHits.
2. Then in a plugin or code mod, do something like this ...
Code:
For each link {
$diff = 'Hits' - 'OldHits';
'Hits' = $diff;
'OldHits' = $diff;
}
Result: 'Hits' holds the count since the last reset, so newly built Cool pages reflect recent activity rather than cumulative activity since day zero.

Ideally, the plugin/mod could be run both from the admin control panel and as a monthly or weekly cron job.
Quote Reply
Re: [YoYoYoYo] [idea] Plugin or Mod: Reset_Hit_Count In reply to
I'll have a look at this today...sounds like a nice idea...

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [YoYoYoYo] [idea] Plugin or Mod: Reset_Hit_Count In reply to
Take a look at Ians' Remote Count plugin.Smile
Quote Reply
Re: [Teambldr] [idea] Plugin or Mod: Reset_Hit_Count In reply to
In Reply To:
Take a look at Ians' Remote Count plugin.Smile
$45 to do that!
Quote Reply
Re: [YoYoYoYo] [idea] Plugin or Mod: Reset_Hit_Count In reply to
Were you hoping for lots of free code?

I would perhaps suggest you write your own plugin at some point in time and you'll realise what kind of effort goes into making them.

Last edited by:

Paul: Aug 30, 2002, 2:20 AM
Quote Reply
Re: [Paul] [idea] Plugin or Mod: Reset_Hit_Count In reply to
In Reply To:
Were you hoping for lots of free code?
No. But $45 is a lot to pay just to look at, like Teambldr suggested. It is excellent value, but it doesn't do anything we want to do, so we would never actually use it. Nor would we consider plundering any code we found there.

Last edited by:

YoYoYoYo: Aug 30, 2002, 4:10 AM
Quote Reply
Meaningful Hits Mod In reply to
OK, here is my first attempt. It's a code hack, not a plugin. Please be critical -- I do not claim to be a programmer, so I have no professional feelings that might be injured.

After backing up your database:

Add a new INT column to your Links table named 'OldHits'.

In .../admin/nph-build.cgi, insert the line in red below ...
Code:
sub main {
# -------------------------------------------------------------------
# Determine what we should build.
#
$USE_HTML = defined $ENV{REQUEST_METHOD} ? 1 : 0;
if ($USE_HTML) {
my $do = $IN->param('do') || '';
CASE: {
($do eq 'changed') and build_changed(), last CASE;
($do eq 'staggered') and build_staggered(), last CASE;
($do eq 'repair') and build_repair(), last CASE;
build_all(); # default
}
}
else {
my $arg = $ARGV[0] || '';
CASE: {
($arg eq '--all') and build_all(), last CASE;
($arg eq '--changed') and build_changed(), last CASE;
($arg eq '--repair') and build_repair(), last CASE;
($arg eq '--flags') and build_flags(), last CASE;

($arg eq '--mhits') and build_meaningful_hits(), last CASE;

usage(); # default
}
}
}


In .../admin/nph-build.cgi, add these two functions ...
Code:
sub build_meaningful_hits {
# ------------------------------------------------------------------
# Reset meaningful hits
#
_header("Resetting meaningful hits.", "Links SQL will now make your Hits meaningful.");
_build_meaningful_hits();
_build_cool_flags();
_footer();
}

sub _build_meaningful_hits {
# ------------------------------------------------------------------
# Resets meaningful hits
#
_time_start();
print "Resetting meaningful hits ... \n";
my $ret = Links::Build::build ('reset_meaningful_hits', shift || {});
print "Done (", _time_display(), " s)\n\n";
return $ret;
}


In .../admin/Links/Build.pm, add these two functions ...
Code:
$SUBS{build_reset_meaningful_hits} = <<'END_OF_SUB';
sub build_reset_meaningful_hits {
# ------------------------------------------------------------------
# Reset meaningful hits
#
my ($link_db, $sth, $id, $hits, $oldhits, $diff);

$link_db = $DB->table('Links');
$sth = $link_db->select ( ['ID', 'Hits', 'OldHits'] );
while ( ( $id, $hits, $oldhits) = $sth->fetchrow_array) {
$diff = $hits - $oldhits;
## Play safe ...
if ($diff < 0) {
$diff = 0;
}
$link_db->update (
{OldHits => $diff, Hits => $diff}, {ID => $id}, {GT_SQL_SKIP_CHECK => 1}
);
}
}
END_OF_SUB


Now you can run it as a cron job at intervals which make sense to your project ...
Code:
.../admin/nph-build.cgi --mhits

It works for us.

Last edited by:

YoYoYoYo: Aug 30, 2002, 8:34 AM