add sitemap
[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
41
42
43
44
45
46
47
<?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) {
    global $conn;
    // check  if already ran
    $query = "select count(*) from heuristic_results where heuristic_name = '$heuristicName' and \"CNID\" = '{$cn['CNID']}'";
    $result = $conn->query($query);
    databaseError($conn->errorInfo());
    $r = $result->fetch(PDO::FETCH_BOTH);
    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"]}',
           ."0,'{$cn["supplierID"]}'
    )";
        // save value and cn data via sql
        $result = $conn->query($query);
        $errors = $conn->errorInfo();
        if ($errors[2] == "")
            echo "Saved $heuristicName for {$cn["CNID"]} <br>\n";
        elseif (strpos($errors[2], "Duplicate entry") === false)
            echo $hresults . " failed insert.<br>" . print_r($errors, true) . " <br>  $query <br><br>\n";
    }
}
 
?>