Maths question (log() maybe).
Posted: Sat Feb 24, 2007 3:34 pm
(This is actually related to the table of scores I had a question about in databases.)
I have a table of score data. I'm fetching the top 25 scores and outputting them using a system that makes the highest score biggest:
This works fine, it calculates the 'band' in which the score appears as a percentage of the difference between the biggest and the smallest.
However, it really only works if there is a reasonably even distribution of scores across the range. If they're 1,2,2,3,3,5,6,6,6,6,7,10,12 there's no problem, but if there's a score that's very different, such as 50, it means the table displays with 1 'huge' score and all the rest are 'tiny'.
Is there a solution to this? I thought about making it a logarithmic scale, but I'm not sure how to go about doing that.
I have a table of score data. I'm fetching the top 25 scores and outputting them using a system that makes the highest score biggest:
Code: Select all
function scoreToSize($s,$min,$max) { //Score, minimum score, maximum score
static $scoreSize = array("tiny","small","medium","large","verylarge","huge"); //These are CSS classes
$range = $max-$min; //Find the full range
$s = $s-$min; //Zero base the current score value.
$per = (($s/$range)*100); //Work out the percentile value of the score in the range
$rper = 100/count($scoreSize)+1; //Work out the 'band width' of each size
$level = round($per / $rper); //Calculate which band the score is in
return $scoreSize[$level]; // Return the band class
}
However, it really only works if there is a reasonably even distribution of scores across the range. If they're 1,2,2,3,3,5,6,6,6,6,7,10,12 there's no problem, but if there's a score that's very different, such as 50, it means the table displays with 1 'huge' score and all the rest are 'tiny'.
Is there a solution to this? I thought about making it a logarithmic scale, but I'm not sure how to go about doing that.