Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Can someone explain this in english?

Quote Reply
Can someone explain this in english?
Just want to know what exaclty is going on in these lines:

# Sort the popular list, and set the cutoff mark.
@popular = sort { $b <=> $a } @popular;
($db_popular_cutoff < 1) ?
($cutoff = $popular[int($db_popular_cutoff * $#popular)]) :
($cutoff = $popular[$db_popular_cutoff - 1]);
($cutoff < 2) and ($cutoff = 2);

Basically, how the cutoff is being determined?

Thanks,
Derek


Quote Reply
Re: Can someone explain this in english? In reply to
Hi!
I'll try... Don't kill me, if I'm wrong. I've have changed this long time ago to work with hits per day!

This first part sorts @popular by hits!

# Sort the popular list, and set the cutoff mark.
@popular = sort { $b <=> $a } @popular;


The following lines checks if $db_popular_cutoff is shorter then one.

($db_popular_cutoff < 1) ?


If it is shorter then one, then you have configured Links to show the TOP x percent as pupular. Example: If you set $db_popular_cutoff = 0.1 it now shows the 10% most viewed sites. If you have 100 sites in your db, it will show 10 TOP-sites, if you have 2000 it will show 200 TOP-sites!

($cutoff = $popular[int($db_popular_cutoff * $#popular)]) :


In the case of a $db_popular_cutoff greater 1, it now takes $db_popular_cutoff-sites as TOP-sites! If you set $db_popular_cutoff = 10 it will show always 10 top-sites, no matter how big your db is.

($cutoff = $popular[$db_popular_cutoff - 1]);


Now the $cutoff is set to the hits-count of the last page with enough hits to be popular. (If there are more then one pages with this hits-count, it will show all of this pages. This is why sometimes the top10 has 12 entrys!)

To avoid links from taking links as popular, which has less then 2 to hits, this line sets $cutoff to 2 if it is less then to:

($cutoff < 2) and ($cutoff = 2);


I hope I could be a little help to you. This code is a little bit of perl-magic. But it is less confusing the the parsing of the templates. I needed one hour to get, how links parses templates... ;-)

Bye
Tiggr

Quote Reply
Re: Can someone explain this in english? In reply to
But how does the calculation occur to get what the opoular cutoff is. It is usually different each time. On one of mine it is up over 2200. How does it do the calculation to tell that if the link has over 2200 hits, it is popular?

Thanks,
Derek


Quote Reply
Re: Can someone explain this in english? In reply to
Hi!

>How does it do the calculation to tell that if the link
>has over 2200 hits, it is popular?

It sorts the linkcounts descending. And in the next step it counts $db_popular_cutoff links down the list and takes this value as cutoff!

Example:
This should be your sorted hitlist, $db_popular_cutoff should be 5, this gives:

1: 22000
2: 11010
3: 400
4: 300
5: 250 <---- this is your new cutoff
6: 250
7: 250
8: 140
9: 120
10: 98
11: 72
12: 48
13: 12
14: 1

In this example all pages with 250 or more hits will be popular!

Bye
Tiggr

Quote Reply
Re: Can someone explain this in english? In reply to
Thanks...I didn't realize it was that simple.

Derek