From: Maxious Date: Wed, 03 Oct 2012 05:31:48 +0000 Subject: add sitemap X-Git-Url: http://maxious.lambdacomplex.org/git/?p=contractdashboard.git&a=commitdiff&h=c724329bdcab178544fc7f228060959a5f445531 --- add sitemap --- --- a/displayCalendar.php +++ b/displayCalendar.php @@ -5,9 +5,9 @@ if ($_REQUEST['month']) { - $monthParts = explode("-", $_REQUEST['month']); + $monthParts = explode("-", str_replace(Array("'","/","\\",'-'), "",$_REQUEST['month'])); $year = $monthParts[1]; - $month = str_replace("'", "", $monthParts[0]); + $month = $monthParts[0]; $monthName = date("F Y", mktime(0,0,0,$month,1,$year)); include_header($monthName); --- a/heuristics/heuristics.inc.php +++ b/heuristics/heuristics.inc.php @@ -1,43 +1,47 @@ query($query); - databaseError($conn->errorInfo()); + // 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', + 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"]}' + '{$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"]}
\n"; - elseif (strpos($errors[2] , "Duplicate entry") === false) echo $hresults . " failed insert.
" . print_r($errors,true) . "
$query

\n"; - } + // save value and cn data via sql + $result = $conn->query($query); + $errors = $conn->errorInfo(); + if ($errors[2] == "") + echo "Saved $heuristicName for {$cn["CNID"]}
\n"; + elseif (strpos($errors[2], "Duplicate entry") === false) + echo $hresults . " failed insert.
" . print_r($errors, true) . "
$query

\n"; + } } + ?> --- a/heuristics/historyHeuristics.php +++ b/heuristics/historyHeuristics.php @@ -20,9 +20,9 @@ $agencyTransactions = Array(); function getAgencyTransactions($agencyName) { - global $agencyTransactions; + global $agencyTransactions,$conn; if (!$agencyTransactions[$agencyName]) { - $query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; + $query = 'select count(*) from contractnotice where "agencyName" = \'' . $agencyName . '"\''; $result = $conn->query($query); $r = $result->fetch(PDO::FETCH_BOTH); $agencyTransactions[$agencyName] = $r[0]; @@ -49,9 +49,9 @@ } function getStatsAgencyTransactions() { - global $averageAgencyTransactions, $stddevAgencyTransactions; - $query = "select avg(count), STDDEV(count) from (select count(*) as count - from contractnotice group by agencyName) as a;"; + global $averageAgencyTransactions, $stddevAgencyTransactions,$conn; + $query = 'select avg(count), STDDEV(count) from (select count(*) as count + from contractnotice group by "agencyName") as a;'; $result = $conn->query($query); $r = $result->fetch(PDO::FETCH_BOTH); $averageAgencyTransactions = $r[0]; @@ -78,10 +78,10 @@ $supplierTransactions = Array(); function getSupplierTransactions($supplierName, $supplierABN) { - global $supplierTransactions; + global $supplierTransactions,$conn; if ($supplierABN != 0 && $supplierABN != "") { if (!$supplierTransactions[$supplierABN]) { - $query = 'select count(*) from contractnotice where supplierABN = "' . $supplierABN . '"'; + $query = "select count(*) from contractnotice where \"supplierABN\" = '" . $supplierABN . "'"; $result = $conn->query($query); $r = $result->fetch(PDO::FETCH_BOTH); $supplierTransactions[$supplierABN] = $r[0]; @@ -89,7 +89,8 @@ return $supplierTransactions[$supplierABN]; } if (!$supplierTransactions[$supplierName]) { - $query = 'select count(*) from contractnotice where supplierName = "' . $supplierName . '"'; + $query = "select count(*) from contractnotice where \"supplierName\" = '" . $supplierName . "'"; + $result = $conn->query($query); $r = $result->fetch(PDO::FETCH_BOTH); $supplierTransactions[$supplierName] = $r[0]; @@ -116,8 +117,10 @@ } 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;'; + global $averageSupplierTransactions, $stddevSupplierTransactions,$conn; + $query = 'select avg(count), stddev(count) from ( + select (case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as "supplierID", + count(*) as count from contractnotice group by "supplierID") as a;'; $result = $conn->query($query); $r = $result->fetch(PDO::FETCH_BOTH); $averageSupplierTransactions = $r[0]; --- a/heuristics/runHeuristics.php +++ b/heuristics/runHeuristics.php @@ -5,10 +5,11 @@ auth(); include_once("heuristics.inc.php"); -$query = 'SELECT *, agency.abn as "agencyABN", case when "supplierABN" != 0 then "supplierABN"::text else "supplierName" end as "supplierID" -FROM contractnotice JOIN agency ON contractnotice."agencyName"=agency."agencyName" +// agency table missing JOIN agency ON contractnotice."agencyName" +$query = 'SELECT *, case when "supplierABN" != 0 then "supplierABN"::text else "supplierName" end as "supplierID" +FROM contractnotice WHERE DATE("importDate") = (select * from (SELECT DATE("importDate") -FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) limit 10'; +FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) limit 100'; $query = $conn->prepare($query); $query->execute(); databaseError($conn->errorInfo()); --- a/heuristics/valueHeuristics.php +++ b/heuristics/valueHeuristics.php @@ -1,58 +1,61 @@ - "unusual value for time of year"); -function METADATA_DUPLICATED_DESCRIPTION($cn) -{ - $averageContractPeriod = getAverageContractPeriod(); - $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); - $days = intval($diff / 24); - return ($days > 45 ? 1 : 0); + "unusual value for time of year"); + +function VALUE_LARGE_CONTRACT_OVERALL($cn) { + $averageContractPeriod = getAverageContractPeriod(); + $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); + $days = intval($diff / 24); + return ($days > 45 ? 1 : 0); } - /* - peculiar value - - Just under 80k, amplified if other contracts with same supplier are just under - */ - $heuristics["VALUE_NEAR_THRESHOLD"] = Array( - "description" => "unusual value for time of year"); - /* - - unusual variation amount - absolute value; large reductions as well as large increases - */ - $heuristics["VALUE_LARGE_VARIATION"] = Array( - "description" => "unusual value for time of year"); -function METADATA_DUPLICATED_DESCRIPTION($cn) -{ - $averageContractPeriod = getAverageContractPeriod(); - $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); - $days = intval($diff / 24); - return ($days > 45 ? 1 : 0); +/* - peculiar value + - Just under 80k, amplified if other contracts with same supplier are just under + */ +$heuristics["VALUE_NEAR_THRESHOLD"] = Array( + "description" => "unusual value for time of year"); +/* + - unusual variation amount - absolute value; large reductions as well as large increases + */ +$heuristics["VALUE_LARGE_VARIATION"] = Array( + "description" => "unusual value for time of year"); + +function VALUE_LARGE_VARIATION($cn) { + $averageContractPeriod = getAverageContractPeriod(); + $diff = strtotime($cn['contractStart']) - strtotime($cn['publishDate']); + $days = intval($diff / 24); + 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*/ + - 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" + "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); + +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 = $conn->query($query); - $r = $result->fetch(PDO::FETCH_BOTH); - $agencyTransactions[$agencyName] = $r[0]; - } - return $agencyTransactions[$agencyName]; + +function getAgencyTransactions($agencyName) { + global $agencyTransactions; + if (!$agencyTransactions[$agencyName]) { + $query = 'select count(*) from contractnotice where agencyName = "' . $agencyName . '"'; + $result = $conn->query($query); + $r = $result->fetch(PDO::FETCH_BOTH); + $agencyTransactions[$agencyName] = $r[0]; + } + return $agencyTransactions[$agencyName]; } + ?> --- a/heuristics/viewHeuristicsDistribution.php +++ b/heuristics/viewHeuristicsDistribution.php @@ -6,7 +6,7 @@ // spread of values 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*/ $series = Array(); @@ -17,4 +17,17 @@ $series[$r["heuristic_name"]][$r["val"]] = $r[2]; } + $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); + } +} +print_r($labels); +print_r($data); ?> --- a/lib/common.inc.php +++ b/lib/common.inc.php @@ -11,7 +11,7 @@ } define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); -if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/")) { +if (strstr($_SERVER['PHP_SELF'], "labs/") || strstr($_SERVER['PHP_SELF'], "admin/") || strstr($_SERVER['PHP_SELF'], "heuristics/")) { $basePath = "../"; } require $basePath."lib/amon-php/amon.php"; --- a/sitemap.xml.php +++ b/sitemap.xml.php @@ -1,14 +1,67 @@ "; - echo '' . "\n"; +$result = $conn->query('SELECT title, to_char("lastUpdated",\'YYYY-MM-DD\') as "lastUpdated" from datasets'); +foreach ($result->fetchAll() as $row) { + if ($row['title'] == "Contract Notices") { + $last_updated['agency'] = $row['lastUpdated']; + $last_updated['supplier'] = $row['lastUpdated']; + $last_updated['category'] = $row['lastUpdated']; + } +} +if (isset($_REQUEST['section']) == false) { + echo ''; + foreach ($sections as $section) { + echo " + " . local_url() . "sitemap.xml.php?section=$section + " . $last_updated[$section] . ''; + } + echo ''; +} else { + echo '' . "\n"; + if ($_REQUEST['section'] == "page") { echo " ".local_url()."index.php1.0\n"; foreach (scandir("./") as $file) { if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " ".local_url()."$file0.3\n"; } + } + if ($_REQUEST['section'] == "agency") { + $result = $conn->query('SELECT DISTINCT "agencyName" from contractnotice'); + foreach ($result->fetchAll() as $row) { + echo " " . local_url() . "displayAgency.php?agency=" . urlencode($row['agencyName']) . " + " . $last_updated['agency'] . "\n"; + } + } + if ($_REQUEST['section'] == "supplier") { + $result = $conn->query('SELECT DISTINCT "supplierABN", "supplierName" from contractnotice'); + + foreach ($result->fetchAll() as $row) { + + $supplier = urlencode(stripslashes($row['supplierABN'] . '-' . $row['supplierName'])); + echo " " . local_url() . "displaySupplier.php?supplier=$supplier + " . $last_updated['supplier'] . "\n"; + } + } + if ($_REQUEST['section'] == "category") { + $result = $conn->query('SELECT distinct category FROM contractnotice;'); + foreach ($result->fetchAll() as $row) { + + echo " " . local_url() . "displayCategory.php?category=".urlencode($row['category'])." + " . $last_updated['category'] . "\n"; + + } + } echo ''; - +} ?>