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