Heuristic ranking analysis
[contractdashboard.git] / heuristics / viewHeuristicsColormap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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>";
}
 
?>