<?php | <?php |
//long contract period (number of weeks/days?) | //long contract period (number of weeks/days?) |
$heuristics["DATE_LONG_CONTRACT_PERIOD"] = Array( | $heuristics["DATE_LONG_CONTRACT_PERIOD"] = Array( |
"description" => "long contract period (number of weeks/days?)" | "description" => "long contract period (number of weeks/days?)" |
); | ); |
function DATE_LONG_CONTRACT_PERIOD($cn) | function DATE_LONG_CONTRACT_PERIOD($cn) |
{ | { |
$averageContractPeriod = getAverageContractPeriod(); | $averageContractPeriod = getAverageContractPeriod(); |
$stddevContractPeriod = getstddevContractPeriod(); | $stddevContractPeriod = getstddevContractPeriod(); |
$diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); | $diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); |
$days = intval($diff / (60 * 60 * 24)); | $days = intval($diff / (60 * 60 * 24)); |
$value = abs($days - $averageContractPeriod) / $stddevContractPeriod; | $value = abs($days - $averageContractPeriod) / $stddevContractPeriod; |
return Array( | return Array( |
"heuristic_value" => $value, | "heuristic_value" => $value, |
"raw_value" => $days, | "raw_value" => $days, |
"mean" => $averageContractPeriod, | "mean" => $averageContractPeriod, |
"stddev" => $stddevContractPeriod | "stddev" => $stddevContractPeriod |
); | ); |
} | } |
$averageContractPeriod; | $averageContractPeriod; |
function getAverageContractPeriod() | function getAverageContractPeriod() |
{ | { |
global $averageContractPeriod; | global $averageContractPeriod, $stddevContractPeriod; |
if (!$averageContractPeriod) { | if (!$averageContractPeriod) { |
$query = "select AVG(dateDiff(contractEnd,contractStart)) from contractnotice"; | getStddevAverageContractPeriod(); |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageContractPeriod = $r[0]; | |
} | } |
return $averageContractPeriod; | return $averageContractPeriod; |
} | } |
$stddevContractPeriod; | $stddevContractPeriod; |
function getstddevContractPeriod() | function getstddevContractPeriod() |
{ | { |
global $stddevContractPeriod; | global $averageContractPeriod, $stddevContractPeriod; |
if (!$stddevContractPeriod) { | if (!$stddevContractPeriod) { |
$query = "select STDDEV(dateDiff(contractEnd,contractStart)) from contractnotice"; | getStddevAverageContractPeriod(); |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$stddevContractPeriod = $r[0]; | |
} | } |
return $stddevContractPeriod; | return $stddevContractPeriod; |
} | } |
function getStddevAverageContractPeriod() | |
{ | |
global $averageContractPeriod, $stddevContractPeriod; | |
$query = "select AVG(dateDiff(contractEnd,contractStart)),stddev(dateDiff(contractEnd,contractStart)) from contractnotice"; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageContractPeriod = $r[0]; | |
$stddevContractPeriod = $r[1]; | |
} | |
//Reported late, 45 days? A late contract is a dodgy contract except maybe for variations? | //Reported late, 45 days? A late contract is a dodgy contract except maybe for variations? |
$heuristics["DATE_REPORTED_LATE"] = Array( | $heuristics["DATE_REPORTED_LATE"] = Array( |
"description" => "Reported late, 45 days?" | "description" => "Reported late, 45 days?" |
); | ); |
function DATE_REPORTED_LATE($cn) | function DATE_REPORTED_LATE($cn) |
{ | { |
$averageDaysLate = getAverageDaysLate(); | $averageDaysLate = getAverageDaysLate(); |
$stddevDaysLate = getStddevDaysLate(); | $stddevDaysLate = getStddevDaysLate(); |
$diff = strtotime($cn['publishDate']) - strtotime($cn['contractStart']); | $diff = strtotime($cn['publishDate']) - strtotime($cn['contractStart']); |
$days = intval($diff / (60 * 60 * 24)); | $days = intval($diff / (60 * 60 * 24)); |
if ($days <= 0) { | if ($days <= 0) { |
$value = 0; | $value = 0; |
} | } |
else { | else { |
// +1 demerit for exceeding 45 day requirement | // +1 demerit for exceeding 45 day requirement |
$value = (abs($days - $averageDaysLate) / $stddevDaysLate) + ($days < 45 ? 0 : 1); | $value = (abs($days - $averageDaysLate) / $stddevDaysLate) + ($days < 45 ? 0 : 1); |
} | } |
return Array( | return Array( |
"heuristic_value" => $value, | "heuristic_value" => $value, |
"raw_value" => $days, | "raw_value" => $days, |
"mean" => $averageDaysLate, | "mean" => $averageDaysLate, |
"stddev" => $stddevDaysLate | "stddev" => $stddevDaysLate |
); | ); |
} | } |
$averageDaysLate; | $averageDaysLate; |
function getAverageDaysLate() | function getAverageDaysLate() |
{ | { |
global $averageDaysLate; | global $averageDaysLate; |
if (!$averageDaysLate) { | if (!$averageDaysLate) { |
$query = "select AVG(dateDiff(publishDate,contractStart)) from contractnotice"; | getDaysLate(); |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageDaysLate = $r[0]; | |
} | } |
return $averageDaysLate; | return $averageDaysLate; |
} | } |
$stddevDaysLate; | $stddevDaysLate; |
function getStddevDaysLate() | function getStddevDaysLate() |
{ | { |
global $stddevDaysLate; | global $stddevDaysLate; |
if (!$stddevDaysLate) { | if (!$stddevDaysLate) { |
$query = "select STDDEV(dateDiff(publishDate,contractStart)) from contractnotice"; | getDaysLate(); |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$stddevDaysLate = $r[0]; | |
} | } |
return $stddevDaysLate; | return $stddevDaysLate; |
} | } |
function getDaysLate() { | |
global $averageDaysLate,$stddevDaysLate; | |
$query = "select AVG(dateDiff(publishDate,contractStart)), STDDEV(dateDiff(publishDate,contractStart)) from contractnotice"; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageDaysLate = $r[0]; | |
$stddevDaysLate = $r[1]; | |
} | |
?> | ?> |
<?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"); |
// method signature heuristic($contractNoticeAsArray); | |
function runHeuristic($heuristicName, $cn) | function runHeuristic($heuristicName, $cn) |
{ | { |
$hresults = call_user_func($heuristicName, $cn); | // check if already ran |
if (!isset($hresults["heuristic_value"]) || !isset($hresults["raw_value"]) || !isset($hresults["mean"]) || !isset($hresults["stddev"])) { | $query = "select count(*) from heuristic_results where heuristic_name = '$heuristicName' and CNID = '{$CN['CNID']}"; |
print_r($hresults); | $result = mysql_query($query); |
die("Missing field in heurtistic $heuristicName result"); | $r = mysql_fetch_array($result); |
} | if ($r[0] == 0) { |
$query = "insert into heuristic_results values('$heuristicName', | // 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["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"]}' | '{$cn["supplierID"]}' |
)"; | )"; |
// save value and cn data via sql | // save value and cn data via sql |
$result = mysql_query($query); | $result = mysql_query($query); |
if ($result) echo "Saved $heuristicName for {$cn["CNID"]} <br>\n"; | 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"; | elseif (strpos(mysql_error() , "Duplicate entry") === false) echo $hresults . " failed insert.<br>" . mysql_error() . " <br> $query <br><br>\n"; |
} | |
} | } |
?> | ?> |
<?php | <?php |
// "unusual for agency/supplier due to previous low number of transactions " | $heuristics["HISTORY_LOW_TRANSACTIONS_AGENCY"] = Array( |
$heuristics["HISTORY_LOW_TRANSACTIONS"] = Array( | "description" => "unusual for agency due to previous low number of transactions " |
"description" => "unusual for agency/supplier due to previous low number of transactions " | |
); | ); |
function HISTORY_LOW_TRANSACTIONS($cn) | function HISTORY_LOW_TRANSACTIONS_AGENCY($cn) |
{ | { |
$averageContractPeriod = getAverageContractPeriod(); | $thisAgencyTransactions = getAgencyTransactions($cn['agencyName']); |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $averageAgencyTransactions = getAverageAgencyTransactions(); |
$days = intval($diff / 24); | $stddevAgencyTransactions = getstddevAgencyTransactions(); |
return ($days > 45 ? 1 : 0); | $diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); |
$days = intval($diff / (60 * 60 * 24)); | |
$value = abs($days - $averageAgencyTransactions) / $stddevAgencyTransactions; | |
return Array( | |
"heuristic_value" => $value, | |
"raw_value" => $days, | |
"mean" => $averageAgencyTransactions, | |
"stddev" => $stddevAgencyTransactions | |
); | |
} | } |
/* - unusual value for time of year | $agencyTransactions = Array(); |
- compare to all other records in last 2 weeks | function getAgencyTransactions($agencyName) |
- ie. many large contracts in june so takes more to standout*/ | |
$heuristics["HISTORY_HIGH_VALUE_FOR_MONTH"] = Array( | |
"description" => "unusual value for time of year"); | |
function HISTORY_HIGH_VALUE_FOR_MONTH($cn) | |
{ | { |
$averageContractPeriod = getAverageContractPeriod(); | global $agencyTransactions; |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | if (!$agencyTransactions[$agencyName]) { |
$days = intval($diff / 24); | $query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; |
return ($days > 45 ? 1 : 0); | $result = mysql_query($query); |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$agencyTransactions[$agencyName] = $r[0]; | |
} | |
return $agencyTransactions[$agencyName]; | |
} | } |
$averageAgencyTransactions; | |
function getAverageAgencyTransactions() | |
{ | |
global $averageAgencyTransactions; | |
if (!$averageAgencyTransactions) { | |
getStatsAgencyTransactions(); | |
} | |
return $averageAgencyTransactions; | |
} | |
$stddevAgencyTransactions; | |
function getstddevAgencyTransactions() | |
{ | |
global $stddevAgencyTransactions; | |
if (!$stddevAgencyTransactions) { | |
getStatsAgencyTransactions(); | |
} | |
return $stddevAgencyTransactions; | |
} | |
function getStatsAgencyTransactions() | |
{ | |
global $averageAgencyTransactions, $stddevAgencyTransactions; | |
$query = "select avg(count), STDDEV(count) from (select count(*) as count | |
from contractnotice group by agencyName) as a;"; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageAgencyTransactions = $r[0]; | |
$stddevAgencyTransactions = $r[1]; | |
} | |
$heuristics["HISTORY_LOW_TRANSACTIONS_SUPPLIER"] = Array( | |
"description" => "unusual for supplier due to previous low number of transactions " | |
); | |
function HISTORY_LOW_TRANSACTIONS_SUPPLIER($cn) | |
{ | |
$thisSupplierTransactions = getSupplierTransactions($cn['supplierName'], $cn['supplierABN']); | |
$averageSupplierTransactions = getAverageSupplierTransactions(); | |
$stddevSupplierTransactions = getstddevSupplierTransactions(); | |
$diff = strtotime($cn['contractEnd']) - strtotime($cn['contractStart']); | |
$days = intval($diff / (60 * 60 * 24)); | |
$value = abs($days - $averageSupplierTransactions) / $stddevSupplierTransactions; | |
return Array( | |
"heuristic_value" => $value, | |
"raw_value" => $days, | |
"mean" => $averageSupplierTransactions, | |
"stddev" => $stddevSupplierTransactions | |
); | |
} | |
$supplierTransactions = Array(); | |
function getSupplierTransactions($supplierName, $supplierABN) | |
{ | |
global $supplierTransactions; | |
if ($supplierABN != 0 && $supplierABN != "") { | |
if (!$supplierTransactions[$supplierABN]) { | |
$query = 'select count(*) from contractnotice where supplierABN = "' . $supplierABN . '"'; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$supplierTransactions[$supplierABN] = $r[0]; | |
} | |
return $supplierTransactions[$supplierABN]; | |
} | |
if (!$supplierTransactions[$supplierName]) { | |
$query = 'select count(*) from contractnotice where supplierName = "' . $supplierName . '"'; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$supplierTransactions[$supplierName] = $r[0]; | |
} | |
return $supplierTransactions[$supplierName]; | |
} | |
$averageSupplierTransactions; | |
function getAverageSupplierTransactions() | |
{ | |
global $averageSupplierTransactions; | |
if (!$averageSupplierTransactions) { | |
getStatsSupplierTransactions(); | |
} | |
return $averageSupplierTransactions; | |
} | |
$stddevSupplierTransactions; | |
function getstddevSupplierTransactions() | |
{ | |
global $stddevSupplierTransactions; | |
if (!$stddevSupplierTransactions) { | |
getStatsSupplierTransactions(); | |
} | |
return $stddevSupplierTransactions; | |
} | |
function getStatsSupplierTransactions() | |
{ | |
global $averageSupplierTransactions, $stddevSupplierTransactions; | |
$query = 'select avg(count), stddev(count) from (select IF(supplierABN != "",supplierABN,supplierName) as supplierID, count(*) as count from contractnotice group by supplierID) as a;'; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageSupplierTransactions = $r[0]; | |
$stddevSupplierTransactions = $r[1]; | |
} | |
<?php | <?php |
/*- duplicated description | /* all |
- most duplicated overall, most duplicated per agency/category/supplier etc. */ | SELECT description, count(*) as count |
$heuristics["METADATA_DUPLICATED_DESCRIPTION"] = Array( | FROM `contractnotice` |
"description" => "unusual value for time of year"); | group by description having count > 1 order by count |
*/ | |
/*- duplicated description | |
- most duplicated overall, most duplicated per agency/category/supplier etc. */ | |
$heuristics["METADATA_DUPLICATED_DESCRIPTION"] = Array( | |
"description" => "" | |
); | |
function METADATA_DUPLICATED_DESCRIPTION($cn) | function METADATA_DUPLICATED_DESCRIPTION($cn) |
{ | { |
$averageContractPeriod = getAverageContractPeriod(); | $averageDuplicatedDescriptions = getAverageDuplicatedDescriptions(); |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $stddevDuplicatedDescriptions = getstddevDuplicatedDescriptions(); |
$days = intval($diff / 24); | $query = 'select count(*) from contractnotice where description = "' . $agencyName . '"'; |
return ($days > 45 ? 1 : 0); | $result = mysql_query($query); |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$dupeDesc = $r[0]; | |
if ($dupeDesc == 1) $value = 0; | |
else $value = abs($dupeDesc - $averageDuplicatedDescriptions) / $stddevDuplicatedDescriptions; | |
return Array( | |
"heuristic_value" => $value, | |
"raw_value" => $dupeDesc, | |
"mean" => $averageDuplicatedDescriptions, | |
"stddev" => $stddevDuplicatedDescriptions | |
); | |
} | } |
$averageDuplicatedDescriptions; | |
function getAverageDuplicatedDescriptions() | |
{ | |
global $averageDuplicatedDescriptions; | |
if (!$averageDuplicatedDescriptions) { | |
getStatsDuplicatedDescriptions(); | |
} | |
return $averageDuplicatedDescriptions; | |
} | |
$stddevDuplicatedDescriptions; | |
function getstddevDuplicatedDescriptions() | |
{ | |
global $stddevDuplicatedDescriptions; | |
if (!$stddevDuplicatedDescriptions) { | |
getStatsDuplicatedDescriptions(); | |
} | |
return $stddevDuplicatedDescriptions; | |
} | |
function getStatsDuplicatedDescriptions() | |
{ | |
$query = "select avg(count),STDDEV(count) from ( | |
SELECT description, count(*) as count | |
FROM `contractnotice` | |
group by description having count > 1 | |
) as a;"; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$averageDuplicatedDescriptions = $r[0]; | |
$stddevDuplicatedDescriptions = $r[1]; | |
} | |
<?php | <?php |
include_once("heuristics.inc.php"); | include_once("heuristics.inc.php"); |
$query = "SELECT *, agency.abn as agencyABN, IF(supplierABN != '',supplierABN,supplierName) as supplierID | $query = "SELECT *, agency.abn as agencyABN, IF(supplierABN != '',supplierABN,supplierName) as supplierID |
FROM contractnotice JOIN agency ON contractnotice.agencyName=agency.agencyName"; | FROM contractnotice JOIN agency ON contractnotice.agencyName=agency.agencyName"; |
$query = "SELECT *, agency.abn as agencyABN, IF(supplierABN != '',supplierABN,supplierName) as supplierID | $query = "SELECT *, agency.abn as agencyABN, IF(supplierABN != '',supplierABN,supplierName) as supplierID |
FROM contractnotice JOIN agency ON contractnotice.agencyName=agency.agencyName | FROM contractnotice JOIN agency ON contractnotice.agencyName=agency.agencyName |
WHERE DATE(importDate) = (select * from (SELECT DATE(importDate) | WHERE DATE(importDate) = (select * from (SELECT DATE(importDate) |
FROM contractnotice ORDER BY importDate DESC limit 1) alias)"; | FROM contractnotice ORDER BY importDate DESC limit 1) alias)"; |
$result = mysql_query($lastimportquery); | $result = mysql_query($query); |
if (!$result) echo mysql_error().$query; | if (!$result) echo mysql_error().$query; |
while ($cn = mysql_fetch_array($result, MYSQL_BOTH)) { | while ($cn = mysql_fetch_array($result, MYSQL_BOTH)) { |
//get each new CN from latest update | //get each new CN from latest update |
foreach ($heuristics as $heuristic => $description) { | foreach ($heuristics as $heuristic => $description) { |
// run all heuristics | // run all heuristics |
runHeuristic($heuristic, $cn); | runHeuristic($heuristic, $cn); |
} | } |
flush(); | flush(); |
} | } |
/*foreach agency | /*foreach agency |
aggregate agency metrics | aggregate agency metrics |
foreach supplier | foreach supplier |
aggreate supplier metrics | aggreate supplier metrics |
foreach CN | foreach CN |
aggregate CN metrics */ | aggregate CN metrics */ |
?> | ?> |
<?php | |
- large contract value | /* - large contract value |
- chi-square test for outliers / standard dev from mean/median | - standard dev from mean/median |
- percent of total contracts for supplier/agency | - percent of total contracts for supplier/agency*/ |
$heuristics["METADATA_DUPLICATED_DESCRIPTION"] = Array( | $heuristics["VALUE_LARGE_CONTRACT_OVERALL"] = Array( |
"description" => "unusual value for time of year"); | "description" => "unusual value for time of year"); |
function METADATA_DUPLICATED_DESCRIPTION($cn) | function METADATA_DUPLICATED_DESCRIPTION($cn) |
{ | { |
$averageContractPeriod = getAverageContractPeriod(); | $averageContractPeriod = getAverageContractPeriod(); |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); |
$days = intval($diff / 24); | $days = intval($diff / 24); |
return ($days > 45 ? 1 : 0); | return ($days > 45 ? 1 : 0); |
} | } |
- peculiar value | /* - peculiar value |
- Just under 80k, amplified if other contracts with same supplier are just under | - Just under 80k, amplified if other contracts with same supplier are just under |
- unusual variation amount | */ |
- absolute value; large reductions as well as large increases | $heuristics["VALUE_NEAR_THRESHOLD"] = Array( |
"description" => "unusual value for time of year"); | |
$heuristics["METADATA_DUPLICATED_DESCRIPTION"] = Array( | /* |
- unusual variation amount - absolute value; large reductions as well as large increases | |
*/ | |
$heuristics["VALUE_LARGE_VARIATION"] = Array( | |
"description" => "unusual value for time of year"); | "description" => "unusual value for time of year"); |
function METADATA_DUPLICATED_DESCRIPTION($cn) | function METADATA_DUPLICATED_DESCRIPTION($cn) |
{ | { |
$averageContractPeriod = getAverageContractPeriod(); | $averageContractPeriod = getAverageContractPeriod(); |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); |
$days = intval($diff / 24); | $days = intval($diff / 24); |
return ($days > 45 ? 1 : 0); | return ($days > 45 ? 1 : 0); |
} | } |
/* - unusual value for time of year | |
- compare to all other records in last 2 weeks | |
- ie. many large contracts in june so takes more to standout*/ | |
$heuristics["VALUE_HIGH_FOR_MONTH"] = Array( | |
"description" => "unusual value for time of year" | |
); | |
function VALUE_HIGH_FOR_MONTH($cn, $monthAsInt) | |
{ | |
$averageContractPeriod = getAverageContractPeriod(); | |
$diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); | |
$days = intval($diff / 24); | |
return ($days > 45 ? 1 : 0); | |
} | |
$monthlyValueAverage = Array(); | |
function getAgencyTransactions($agencyName) | |
{ | |
global $agencyTransactions; | |
if (!$agencyTransactions[$agencyName]) { | |
$query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; | |
$result = mysql_query($query); | |
$r = mysql_fetch_array($result, MYSQL_BOTH); | |
$agencyTransactions[$agencyName] = $r[0]; | |
} | |
return $agencyTransactions[$agencyName]; | |
} | |
?> |
<?php | <?php |
include_once("../lib/common.inc.php"); | include_once("../lib/common.inc.php"); |
echo '<style> | |
div { | |
padding: 5px; | |
display: inline-block; | |
} | |
</style>'; | |
// http://www.herethere.net/~samson/php/color_gradient/color_gradient_generator.php.txt | // http://www.herethere.net/~samson/php/color_gradient/color_gradient_generator.php.txt |
// return the interpolated value between pBegin and pEnd | // return the interpolated value between pBegin and pEnd |
function interpolate($pBegin, $pEnd, $pStep, $pMax) | function interpolate($pBegin, $pEnd, $pStep, $pMax) |
{ | { |
if ($pBegin < $pEnd) { | if ($pBegin < $pEnd) { |
return (($pEnd - $pBegin) * ($pStep / $pMax)) + $pBegin; | return (($pEnd - $pBegin) * ($pStep / $pMax)) + $pBegin; |
} | } |
else { | else { |
return (($pBegin - $pEnd) * (1 - ($pStep / $pMax))) + $pEnd; | return (($pBegin - $pEnd) * (1 - ($pStep / $pMax))) + $pEnd; |
} | } |
} | } |
function Gradient($HexFrom, $HexTo, $ColorSteps) | function Gradient($HexFrom, $HexTo, $ColorSteps) |
{ | { |
$theColorBegin = hexdec($HexFrom); | $theColorBegin = hexdec($HexFrom); |
$theColorEnd = hexdec($HexTo); | $theColorEnd = hexdec($HexTo); |
$theNumSteps = intval($ColorSteps); | $theNumSteps = intval($ColorSteps); |
$theR0 = ($theColorBegin & 0xff0000) >> 16; | $theR0 = ($theColorBegin & 0xff0000) >> 16; |
$theG0 = ($theColorBegin & 0x00ff00) >> 8; | $theG0 = ($theColorBegin & 0x00ff00) >> 8; |
$theB0 = ($theColorBegin & 0x0000ff) >> 0; | $theB0 = ($theColorBegin & 0x0000ff) >> 0; |
$theR1 = ($theColorEnd & 0xff0000) >> 16; | $theR1 = ($theColorEnd & 0xff0000) >> 16; |
$theG1 = ($theColorEnd & 0x00ff00) >> 8; | $theG1 = ($theColorEnd & 0x00ff00) >> 8; |
$theB1 = ($theColorEnd & 0x0000ff) >> 0; | $theB1 = ($theColorEnd & 0x0000ff) >> 0; |
$GradientColors = array(); | $GradientColors = array(); |
// generate gradient swathe now | // generate gradient swathe now |
for ($i = 0; $i <= $theNumSteps; $i++) { | for ($i = 0; $i <= $theNumSteps; $i++) { |
$theR = interpolate($theR0, $theR1, $i, $theNumSteps); | $theR = interpolate($theR0, $theR1, $i, $theNumSteps); |
$theG = interpolate($theG0, $theG1, $i, $theNumSteps); | $theG = interpolate($theG0, $theG1, $i, $theNumSteps); |
$theB = interpolate($theB0, $theB1, $i, $theNumSteps); | $theB = interpolate($theB0, $theB1, $i, $theNumSteps); |
$theVal = ((($theR << 8) | $theG) << 8) | $theB; | $theVal = ((($theR << 8) | $theG) << 8) | $theB; |
$GradientColors[] = sprintf("%06X", $theVal); | $GradientColors[] = sprintf("%06X", $theVal); |
} | } |
return $GradientColors; | return $GradientColors; |
} | } |
$Gradients = Gradient("66FF00" , "FF0000" , 10); | $Gradients = Gradient("66FF00" , "FF0000" , 10); |
$query = "select max(sum) from (SELECT sum(heuristic_value) | $query = "select max(sum) from (SELECT sum(heuristic_value) |
as sum FROM heuristic_results group by CNID) as a"; | as sum FROM heuristic_results group by CNID) as a"; |
$result = mysql_query($query); | $result = mysql_query($query); |
$r = mysql_fetch_array($result, MYSQL_BOTH); | $r = mysql_fetch_array($result, MYSQL_BOTH); |
$maxVal = $r[0]; | $maxVal = $r[0]; |
$query = "SELECT sum(heuristic_value) as sum, CNID | $query = "SELECT sum(heuristic_value) as sum, CNID |
FROM `heuristic_results` group by CNID order by sum DESC LIMIT 30"; | FROM `heuristic_results` group by CNID order by sum DESC LIMIT 300"; |
$result = mysql_query($query); | $result = mysql_query($query); |
if (!$result) echo mysql_error().$query; | if (!$result) echo mysql_error().$query; |
while ($r = mysql_fetch_array($result, MYSQL_BOTH)) { | while ($r = mysql_fetch_array($result, MYSQL_BOTH)) { |
echo '<span style="background: #'.$Gradients[floor(($r['sum']/$maxVal) * 10)].'; padding: 5px;">'; | echo '<div style="background: #'.$Gradients[floor(($r['sum']/$maxVal) * 10)].';">'; |
echo '<a title="'.$r['sum'].'" href="../displayContract.php?CNID='.$r['CNID'].'">X</a>'; | echo '<a title="'.$r['sum'].'" href="../displayContract.php?CNID='.$r['CNID'].'">X</a>'; |
echo "</span>"; | echo "</div>"; |
} | } |
?> | ?> |
<?php | <?php |
/*// most interesting | /*// most interesting |
SELECT sum(heuristic_value) as sum, CNID | SELECT sum(heuristic_value) as sum, CNID |
FROM `heuristic_results` group by CNID order by sum DESC limit 30 | FROM `heuristic_results` group by CNID order by sum DESC limit 30 |
// spread of values | // spread of values |
select floor(sum) as val,count(*) from (SELECT sum(heuristic_value) | select floor(sum) as val,count(*) from (SELECT sum(heuristic_value) |
as sum FROM heuristic_results group by CNID) as a group by val*/ | as sum FROM heuristic_results group by CNID) as a group by val*/ |
/* CAT:Spline chart */ | /* CAT:Spline chart */ |
/* pChart library inclusions */ | /* pChart library inclusions */ |
include("../lib/pChart2.1.0/class/pData.class.php"); | include("../lib/pChart2.1.0/class/pData.class.php"); |
include("../lib/pChart2.1.0/class/pDraw.class.php"); | include("../lib/pChart2.1.0/class/pDraw.class.php"); |
include("../lib/pChart2.1.0/class/pImage.class.php"); | include("../lib/pChart2.1.0/class/pImage.class.php"); |
$labels = Array(); | |
$values = Array(); | $series = Array(); |
include_once("../lib/common.inc.php"); | include_once("../lib/common.inc.php"); |
$query = "select floor(sum) as val,count(*) from (SELECT sum(heuristic_value) | $query = "select heuristic_name, floor(heuristic_value) as val,count(*) from heuristic_results group by heuristic_name, val"; |
as sum FROM heuristic_results group by CNID) as a group by val"; | |
$result = mysql_query($query); | $result = mysql_query($query); |
if (!$result) echo mysql_error().$query; | if (!$result) echo mysql_error().$query; |
while ($r = mysql_fetch_array($result, MYSQL_BOTH)) { | while ($r = mysql_fetch_array($result, MYSQL_BOTH)) { |
$labels[] = $r[0]; | $series[$r["heuristic_name"]][$r["val"]] = $r[2]; |
$values[] = $r[1]; | |
} | } |
/* Create and populate the pData object */ | /* Create and populate the pData object */ |
$MyData = new pData(); | $MyData = new pData(); |
$MyData->addPoints($values,"Records"); | $labels = Array(); |
foreach ($series as $value) { | |
$labels = $labels+array_keys($value); | |
} | |
$labels = Array(0,1,2,3,4,5); | |
foreach ($series as $seriesName => $seriesEntry) { | |
$data; | |
foreach ($labels as $label) { | |
$data[$label] = ($seriesEntry[$label] ? $seriesEntry[$label] : 0); | |
} | |
$MyData->addPoints($data,$seriesName); | |
} | |
$MyData->setAxisName(0,"# of records"); | $MyData->setAxisName(0,"# of records"); |
$MyData->addPoints($labels,"Labels"); | $MyData->addPoints($labels,"Labels"); |
$MyData->setSerieDescription("Labels","Bins"); | $MyData->setSerieDescription("Labels","Bins"); |
$MyData->setAbscissa("Labels"); | $MyData->setAbscissa("Labels"); |
/* Create the pChart object */ | /* Create the pChart object */ |
$myPicture = new pImage(700,230,$MyData); | $myPicture = new pImage(700,230,$MyData); |
/* Turn of Antialiasing */ | /* Turn of Antialiasing */ |
$myPicture->Antialias = FALSE; | $myPicture->Antialias = FALSE; |
/* Add a border to the picture */ | /* Add a border to the picture */ |
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0)); | $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0)); |
/* Write the chart title */ | /* Write the chart title */ |
$myPicture->setFontProperties(array("FontName"=>"../lib/pChart2.1.0/fonts/Forgotte.ttf","FontSize"=>11)); | $myPicture->setFontProperties(array("FontName"=>"../lib/pChart2.1.0/fonts/Forgotte.ttf","FontSize"=>11)); |
$myPicture->drawText(150,35,"Record distribution",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); | $myPicture->drawText(150,35,"Record distribution",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); |
/* Set the default font */ | /* Set the default font */ |
$myPicture->setFontProperties(array("FontName"=>"../lib/pChart2.1.0/fonts/pf_arma_five.ttf","FontSize"=>6)); | $myPicture->setFontProperties(array("FontName"=>"../lib/pChart2.1.0/fonts/pf_arma_five.ttf","FontSize"=>6)); |
/* Define the chart area */ | /* Define the chart area */ |
$myPicture->setGraphArea(60,40,650,200); | $myPicture->setGraphArea(60,40,650,200); |
/* Draw the scale */ | /* Draw the scale */ |
$scaleSettings = array("XMargin"=>10,"YMargin"=>0,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE); | $scaleSettings = array("XMargin"=>10,"YMargin"=>0,"Floating"=>TRUE,"GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE); |
$myPicture->drawScale($scaleSettings); | $myPicture->drawScale($scaleSettings); |
/* Turn on Antialiasing */ | /* Turn on Antialiasing */ |
$myPicture->Antialias = TRUE; | $myPicture->Antialias = TRUE; |
/* Draw the line chart */ | /* Draw the line chart */ |
$myPicture->drawSplineChart(); | $myPicture->drawSplineChart(); |
/* Write the chart legend */ | /* Write the chart legend */ |
$myPicture->drawLegend(540,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); | $myPicture->drawLegend(540,20,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL)); |
/* Render the picture (choose the best way) */ | /* Render the picture (choose the best way) */ |
$myPicture->autoOutput("pictures/example.drawSplineChart.simple.png"); | $myPicture->autoOutput("pictures/example.drawSplineChart.simple.png"); |
?> | ?> |