--- a/heuristics/viewHeuristicsColormap.php +++ b/heuristics/viewHeuristicsColormap.php @@ -1,1 +1,54 @@ +<?php + include_once("../lib/common.inc.php"); +// http://www.herethere.net/~samson/php/color_gradient/color_gradient_generator.php.txt +// return the interpolated value between pBegin and pEnd +function interpolate($pBegin, $pEnd, $pStep, $pMax) +{ + if ($pBegin < $pEnd) { + return (($pEnd - $pBegin) * ($pStep / $pMax)) + $pBegin; + } + else { + return (($pBegin - $pEnd) * (1 - ($pStep / $pMax))) + $pEnd; + } +} +function Gradient($HexFrom, $HexTo, $ColorSteps) +{ + $theColorBegin = hexdec($HexFrom); + $theColorEnd = hexdec($HexTo); + $theNumSteps = intval($ColorSteps); + $theR0 = ($theColorBegin & 0xff0000) >> 16; + $theG0 = ($theColorBegin & 0x00ff00) >> 8; + $theB0 = ($theColorBegin & 0x0000ff) >> 0; + $theR1 = ($theColorEnd & 0xff0000) >> 16; + $theG1 = ($theColorEnd & 0x00ff00) >> 8; + $theB1 = ($theColorEnd & 0x0000ff) >> 0; + $GradientColors = array(); + // generate gradient swathe now + for ($i = 0; $i <= $theNumSteps; $i++) { + $theR = interpolate($theR0, $theR1, $i, $theNumSteps); + $theG = interpolate($theG0, $theG1, $i, $theNumSteps); + $theB = interpolate($theB0, $theB1, $i, $theNumSteps); + $theVal = ((($theR << 8) | $theG) << 8) | $theB; + $GradientColors[] = sprintf("%06X", $theVal); + } + return $GradientColors; +} +$Gradients = Gradient("66FF00" , "FF0000" , 10); + +$query = "select max(sum) from (SELECT sum(heuristic_value) +as sum FROM heuristic_results group by CNID) as a"; +$result = mysql_query($query); +$r = mysql_fetch_array($result, MYSQL_BOTH); +$maxVal = $r[0]; + +$query = "SELECT sum(heuristic_value) as sum, CNID +FROM `heuristic_results` group by CNID order by sum DESC LIMIT 30"; +$result = mysql_query($query); +if (!$result) echo mysql_error().$query; +while ($r = mysql_fetch_array($result, MYSQL_BOTH)) { + echo '<span style="background: #'.$Gradients[floor(($r['sum']/$maxVal) * 10)].'; padding: 5px;">'; + echo '<a title="'.$r['sum'].'" href="../displayContract.php?CNID='.$r['CNID'].'">X</a>'; + echo "</span>"; +} +?>