remove datatable unit tests
[contractdashboard.git] / heuristics / heuristics.inc.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
<?php
include_once ("../lib/common.inc.php");
$heuristics = Array();
//each heuristic adds self to description array
include ("dateHeuristics.php");
include ("historyHeuristics.php");
//include ("metadataHeuristics.php");
//include ("valueHeuristics.php");
function runHeuristic($heuristicName, $cn)
{
        // check  if already ran
        $query = "select count(*) from heuristic_results where heuristic_name = '$heuristicName' and CNID = '{$cn['CNID']}'";
        $result = mysql_query($query);
        $r = mysql_fetch_array($result);
        if ($r[0] == 0) {
                // if not, run now
                $hresults = call_user_func($heuristicName, $cn);
                if (!isset($hresults["heuristic_value"]) || !isset($hresults["raw_value"]) || !isset($hresults["mean"]) || !isset($hresults["stddev"])) {
                        print_r($hresults);
                        die("Missing field in heurtistic $heuristicName result");
                }
                $query = "insert into heuristic_results values('$heuristicName',
    '{$hresults["heuristic_value"]}',
     '{$hresults["raw_value"]}',
      '{$hresults["mean"]}',
       '{$hresults["stddev"]}',
           '{$cn["CNID"]}',
           NOW(),
           '{$cn["publishDate"]}',
           '{$cn["agencyABN"]}',
           '{$cn["supplierID"]}'
    )";
                // save value and cn data via sql
                $result = mysql_query($query);
                if ($result) echo "Saved $heuristicName for {$cn["CNID"]} <br>\n";
                elseif (strpos(mysql_error() , "Duplicate entry") === false) echo $hresults . " failed insert.<br>" . mysql_error() . " <br>  $query <br><br>\n";
        }
}
?>