Nuclear Physics comes to our web site
Archive - Originally posted on "The Horse's Mouth" - 2008-12-17 08:22:45 - Graham EllisOne of the major projects that we'll be undertaking in the near future is aimed at improving the findability of information on our site - you shouldn't need to know that you need a blog article dated 2nd Feb 2007 to find about the difference between a comparator and comparable in Java, nor to look up on page /resources/Q907.html to find out about object oriented design - there should be an easier way.
And what better way than to actually use an Object Oriented approach where each of the "Pieces of Content" on the web site can be accessed through the same API (Application Programmer Interface)? Then - whether it's on The Horse's Mouth Blog, in the longer articles of the solution centre, part of a course description or somewhere in the Forum you should be able to find it by keyword or description, and further more have a ranked list of other pieces of content ("poc"s) that may also be relevant offered to you, irrespective of the particular subclass that they belong to.
On yesterday's Perl for larger Projects course, which covers Object Orientation in Perl as one of its key subjects, I took my "poc" project as an example and came up with something of a concept test / spike solution for the first algorithms that we may use. Starting with a series of function calls, we moved on to an object oriented example, showing off most of the features of Perl's OO model - all the "usual OO stuff", plus autoloaders, exporters and the rest. I've added the full series of examples written on to our web site ... so you can look at the source of each stage if you wish; it made an excellent teaching tool:
1. Use of a package
2. Encapsulate code, and add strict checking
3. Adding OO notations
4. AUTOLOAD
5. A list of objects
6. Setters and Getters
7. Inherited classes, and an Exporter
8. and 9. The final demo - the test program to go with ... the Perl module and the two classes
So where does the nuclear physics come in? Well - I've chosen to define an initial ranking for each piece of content, and a "halflife" - the number of days in which it decays to having just a half of its initial significance, as per the decay of a radioactive isotope. Here's the algorithm if you're interesed:
sub getrank {
my ($current) = @_;
my $now = time();
my $age_in_days = ($now - $current->{otime}) / 3600 / 24;
my $decaysteps = $age_in_days / $current->{halflife};
$decaysteps < 0 and $decaysteps = 0; # future content!
my $decayfactor = 0.5 ** $decaysteps;
my $rank = sprintf("%.2f",$current->{orank} * $decayfactor);
return $rank; }
but of course that's going to be encapsulated within the class and "Joe Public" visiting our site - our even our content providers - will be gloriously unaware of the mathematics!
No - the general visitor will be much more interested in the titles and ranking of the pages, as illustrated by running our test program:
Dorothy:plpw grahamellis$ perl poctest
The Vet who liked horse meat
rank is 15.00 down from 15
Copyright, Well House Consultants
MySQL left join - howto
rank is 73.82 down from 95
Copyright, Well House Consultants
Contacts at Well House Consultants
rank is 95.00 down from 95
Copyright, Well House Consultants
Perl for Deep Sea Divers
rank is 50.00 down from 50
Copyright, Well House Consultants
95.00 - Contacts at Well House Consultants
73.82 - MySQL left join - howto
50.00 - Perl for Deep Sea Divers
15.00 - The Vet who liked horse meat
Attributes supported - comment halflife orank otime author title
Dorothy:plpw grahamellis$